加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

PostgreSQL special sql 1 - list all the columns and primary

发布时间:2020-12-13 17:30:34 所属栏目:百科 来源:网络整理
导读:There are a few special sql commands that I used often recently,mark them here. 1: Show all the columns' name SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='yourtablename'; another solution d 'yourtablename' 2: Show the primar

There are a few special sql commands that I used often recently,mark them here.


1: Show all the columns' name

SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='yourtablename';


another solution

d 'yourtablename'



2: Show the primary key:
SELECT               
  pg_attribute.attname,format_type(pg_attribute.atttypid,pg_attribute.atttypmod) 
FROM pg_index,pg_class,pg_attribute 
WHERE 
  pg_class.oid = 'nygeotwitters'::regclass AND
  indrelid = pg_class.oid AND
  pg_attribute.attrelid = pg_class.oid AND 
  pg_attribute.attnum = any(pg_index.indkey)
  AND indisprimary;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读