Tag: postgresql 8.4

如何排除array_agg中的空值像使用postgres的string_agg?

如果我使用array_agg来收集名称,我得到我的名字用逗号分隔,但如果有一个null值,该空值也被视为聚合中的名称。 例如 : SELECT g.id, array_agg(CASE WHEN g.canonical = 'Y' THEN g.users ELSE NULL END) canonical_users, array_agg(CASE WHEN g.canonical = 'N' THEN g.users ELSE NULL END) non_canonical_users FROM groups g GROUP BY g.id; 它返回,Larry,Phil而不是Larry,Phil (在我的9.1.2,它显示NULL,Larry,Phil )。 就像这个小提琴一样 相反,如果我使用string_agg() ,它只显示这里的名称(没有空的逗号或空) 问题是我在服务器上安装了Postgres 8.4 ,而string_agg()在那里不起作用。 有没有办法使array_agg工作类似于string_agg()?

如何在Postgres 8.4中导入模块或安装扩展?

我试图导入几个与8.4.1 postgres捆绑在一起的模块,并且所有这些命令(如contrib.import等)都不起作用或者找不到。 请帮帮我。

如何添加“删除级联”约束?

在PostgreSQL 8中,可以在下表中添加“删除级联”到两个外键而不丢弃后者? # \d pref_scores Table "public.pref_scores" Column | Type | Modifiers ———+———————–+———– id | character varying(32) | gid | integer | money | integer | not null quit | boolean | last_ip | inet | Foreign-key constraints: "pref_scores_gid_fkey" FOREIGN KEY (gid) REFERENCES pref_games(gid) "pref_scores_id_fkey" FOREIGN KEY (id) REFERENCES pref_users(id) 这两个引用的表格如下: # \d pref_games Table […]

在Postgres插入语句生成一个UUID?

我的问题很简单。 我知道的UUID的概念,我想要生成一个引用从我的数据库中的“商店”每个“项目”。 似乎合理的权利? 问题是以下行返回一个错误: honeydb=# insert into items values( uuid_generate_v4(), 54.321, 31, 'desc 1', 31.94); ERROR: function uuid_generate_v4() does not exist LINE 2: uuid_generate_v4(), 54.321, 31, 'desc 1', 31.94); ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. 我已阅读网页: http : //www.postgresql.org/docs/current/static/uuid-ossp.html 我在Ubuntu 10.04 x64上运行Postgres […]

拆分逗号分隔列数据到其他列

我在一列中有逗号分隔的数据: Column ——- a,b,c,d 我想将逗号分隔的数据分成多列来获得这个输出: Column1 Column2 Column3 Column4 ——- ——- ——- ——- abcd 这怎么能实现?