如何使用SQL语句测试表中是否存在列 [英] How can I test if a column exists in a table using an SQL statement

查看:97
本文介绍了如何使用SQL语句测试表中是否存在列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PostgreSQL中,有没有一种简单的替代方法可以代替Oracle中生成的该语句?

Is there a simple alternative in PostgreSQL to this statement produced in Oracle?

select table_name from user_tab_columns
where table_name = myTable and column_name = myColumn;

我正在测试查询是否返回任何内容,以证明该列存在。

I am then testing whether the query returns anything so as to prove the column exists.

我知道使用psql可以单独找到它们,但这是在我编写的程序中产生结果所必需的,以验证我的数据库表中是否存在所请求的属性字段。

I am aware that using psql I can find these out individually but this is required to produce a result in a program I am writing to validate that a requested attribute field exists in my database table.

推荐答案

尝试一下:

SELECT column_name 
FROM information_schema.columns 
WHERE table_name='your_table' and column_name='your_column';

这篇关于如何使用SQL语句测试表中是否存在列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆