判断一个表中是否存在某字段
SELECT case when count(*) > 0 then 'true'else 'false'endFROM(SELECTa.attname as Columns,pg_catalog.format_type(a.atttypid, a.atttypmod) as "Datatype"FROMpg_catalog.pg_attribute aWHEREa.attnum > 0AND NOT a.attisdroppedAND a.attrelid = (SELECT c.oidFROM pg_catalog.pg_class cLEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespaceWHERE c.relname ~ '^(views)$'AND pg_catalog.pg_table_is_visible(c.oid))) as a where a.Columns = 'ad_id';用了上次博客的文章的SQL,通过输入表名和你要判断的列名,他通过返回true或者false来告诉你是否存在。
页:
[1]