7

有没有更好的方法将表格的一行转换为 hstore 格式而不是去

SELECT hstore(ARRAY['col1','col2','col3'], ARRAY[col1::text, col2::text, col3::text]) FROM tbl;

它有效,但我认为必须有比输入每一列更好的方法。hstore 采用记录类型作为输入,但我不知道如何将单行生成查询输入到函数中并使其满意。Postgres 版本 9.0.4。

4

1 回答 1

13

是的 - 您可以使用函数将 row 转换为 hstore 类型hstore()

SELECT hstore(tbl.*) FROM tbl;

为我工作:

filip@filip=# select hstore(foo.*) from foo;
         hstore
------------------------
 "bar"=>"1", "baz"=>"2"
(1 row)

http://www.postgresql.org/docs/9.0/static/hstore.html#HSTORE-FUNC-TABLE

于 2012-01-10T21:41:03.123 回答