sasori
sasori

Reputation: 5455

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

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?

Upvotes: 2

Views: 694

Answers (1)

Mureinik
Mureinik

Reputation: 311198

PostgreSQL uses the following syntax:

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

Upvotes: 1

Related Questions