how to to first check whether the table exist or not before creating it in postgresql?

Viewed 428

How to check whether a table already exists or not before executing a creation script?

for example in MySQL database, we can do

IF NOT EXISTS tableName ..then create table sql script to follow

how about in PostgreSQL? Is there a way to check first if the table exists before creating it? How do we do it?

1 Answers

PostgreSQL uses the following syntax:

CREATE TABLE IF NOT EXISTS mytable (
    -- Column definitions...
)
Related