1 命令行导入文本数据到表
psql -d bass_gp -h 10.243.4.145 -p 5432 -U dwadm -c "\copy dwtmp.tmp_test(cellid) from /data/22.txt "
bass_gp 是数据库名及database名
10.243.4.145 ip地址
5432 是端口号
dwadm 账号
2
类似于 oracle wm_concat (列名),该函数可以把列值以","号分隔起来,并显示成一行,接下来上例子,看看这个神奇的函数如何应用
string_agg
"empno" "ename" "job" "mgr" "hiredate" "sal" "comm" "deptno"
"7499" "ALLEN" "SALESMAN" "7698" "1981/2/20" "1600" "300" "30"
"7566" "JONES" "MANAGER" "7839" "1981/4/2" "2975" "" "20"
"7654" "MARTIN" "SALESMAN" "7698" "1981/9/28" "1250" "1400" "30"
其中7499和7654是同一个deptno的,为30,另外一个7566的deptno为20。
Select deptno,string_agg(ename,',’)ename_agg from emp group by deptno;
结果为:
Deptno ename_agg
20 JONES
30 ALLEN,MARTIN
3 postgresql存储过程使用方法 ,代码结构:
declare cursor record begin for cursor in ; loop enend loop;
4 查询表字段注释语句:
select a.attname as columnname, pg_catalog.format_type(a.atttypid, a.atttypmod) as data_type, decode(a.attnotnull,'t','not null','f',null),COALESCE(b.description,'') as comment from pg_catalog.pg_attribute a left join pg_catalog.pg_description b on b.objoid=a.attrelid and b.objsubid=a.attnum where a.attrelid ='dwctr.tc_newuser_10days_gsm_day'::regclass and a.attnum > 0 and not a.attisdropped order by a.attnum;