2024-04-29 13:19:15
写作课要求:在课堂上写一篇简短故事,要包括宗教、皇室、性与神秘四个成分。
那些羽毛未丰的作家下课时才把故事写完,
但是有个学生很快就写好了:“我的上帝,女王怀孕了!谁的杰作?”
PostgreSQL中arry_to_string如何使用
数据准备
创建表ay_tree_test:
CREATE TABLE ay_tree_test
(
id character varying(3),
pid character varying(3),
name character varying(10)
)
插入数据:
INSERT INTO ay_tree_test values('001','0','厦门市');
INSERT INTO ay_tree_test values('002','001','海沧区','2100');
INSERT INTO ay_tree_test values('003','001','集美区','2500');
INSERT INTO ay_tree_test values('004','001','同安区','1500');
INSERT INTO ay_tree_test values('005','002','区政府','1');
INSERT INTO ay_tree_test values('006','002','青春海岸','10');
INSERT INTO ay_tree_test values('007','002','未来海岸','15');
例一:
结果如下:
解释:
array(SELECT att.name FROM ay_tree_test2 att) 即把查询出来的name字段转化成array数组
array_to_string("数组","/") 即把数组转化为字符串,并用“/”连接(使用提供的分隔符连接数组元素)
更加详细,请参考:
http://www.cnblogs.com/stephen-liu74/archive/2012/05/07/2295273.html