Postgresql: how to create table only if it does not already exist?

后端 未结 10 952
不思量自难忘°
不思量自难忘° 2021-01-31 08:04

In Postgresql, how can I do a condition to create a table only if it does not already exist?

Code example appreciated.

10条回答
  •  花落未央
    2021-01-31 08:11

    I think to check the pg_class table perhaps help you, something like that:

    SELECT COUNT (relname) as a FROM pg_class WHERE relname = 'mytable'
    
    if a = 0 then (CREATE IT)
    

    Regards.

提交回复
热议问题