品易云推流 关闭
文章详情页
文章 > PostgreSQL > PostgreSQL如何判断字段是否存在

PostgreSQL如何判断字段是否存在

头像

月亮邮递员

2020-03-27 18:13:286668浏览 · 0收藏 · 0评论

PostgreSQL如何判断字段是否存在

方法一:

select count(*) from information_schema.columns WHERE table_schema = 'table_schema'
     and table_name = 'table_name' and column_name = 'column_name';

方法二:

select * from information_schema.columns WHERE table_schema = 'table_schema' 
    and table_name = 'table_name' and column_name = 'column_name';

补充:

判断表是否存在:

select count (*) from information_schema.tables WHERE table_schema = 'table_schema' 
    and table_name = 'table_name';
    
select * from information_schema.tables WHERE table_schema = 'table_schema' 
    and table_name = 'table_name';

推荐:postgresql教程

关注

关注公众号,随时随地在线学习

本教程部分素材来源于网络,版权问题联系站长!

底部广告图