小编kus*_*shi的帖子

具有NULL值的NOT LIKE的行为

我想获取表的所有列,除了类型为serial的列.最接近这个问题的查询我能够得到这个:

SELECT column_name FROM information_schema.columns
WHERE table_name = 'table1' AND column_default NOT LIKE 'nextval%'
Run Code Online (Sandbox Code Playgroud)

但问题是它还排除/过滤具有column_default空值的行.我不知道为什么Postgres的行为是这样的.所以我不得不将我的查询更改为以下内容:

SELECT column_name FROM information_schema.columns
WHERE table_name = 'table1'
AND ( column_default IS NULL OR column_default NOT LIKE 'nextval%')
Run Code Online (Sandbox Code Playgroud)

欢迎任何更好的建议或背后的理由.

sql postgresql null information-schema

12
推荐指数
1
解决办法
2万
查看次数

标签 统计

information-schema ×1

null ×1

postgresql ×1

sql ×1