PostgreSQL special sql 1 - list all the columns and primary key

前端之家收集整理的这篇文章主要介绍了PostgreSQL special sql 1 - list all the columns and primary key前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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;
原文链接:https://www.f2er.com/postgresql/195809.html

猜你在找的Postgre SQL相关文章