最近看了一位大神的博客,感觉挺受用的,记录一下,里边引用了一篇文章如下:
http://www.postgresonline.com/journal/archives/41-How-to-SELECT-ALL-EXCEPT-some-columns-in-a-table.html
大堆字段排除几个字段select出
方法一、命令行方式
输入:
SELECT 'SELECT ' || array_to_string(ARRAY(SELECT 'o' || '.' || c.column_name
FROM information_schema.columns As c
WHERE table_name = 'officepark'
AND c.column_name NOT IN('officeparkid','contractor')
),',') || ' FROM officepark As o' As sqlstmt
输出:
SELECT o.officepark,o.owner,o.squarefootage
FROM officepark As o
方式二、借助pgAdmin III, 在数据表上鼠标右键,创建Select 脚本,可以把所有字段都列出来了,删除不要的字段很简单的。
方式三、psql | awk 处理
psql -h host -d datebase -U user -c '\d schame.table_name' | awk -F ' ' 'BEGIN{ print "SELECT "; ORS=" "} { if (NR > 3) {print $1","} } END{print "\n" }';
输出格式为:
SELECT
id,num,test,....