我需要使用"提升通知"报告记录项目,但包括项目名称。
raise notice 'rec=%',r; -- is not very good
有没有可能做一些类似的事情:
声明r记录;itemname varchar(200);开始从my_table_unknown_structure中选择*into r;对于pg_record_item_names(r)中的itemname环发出通知'%=%,itemname,pg_record_item_value(r,itemname);末端回路;终止
表的每一行都可以有一个JSON对象
select row_to_json(t)
from t;
row_to_json
-----------------------------
{"a":1,"b":"a_value"}
{"a":2,"b":"another_value"}
如果您只需要第一行,并希望它作为一组键/值对
select *
from json_each ((
select row_to_json(t)
from t
limit 1
))
;
key | value
-----+-----------
a | 1
b | "a_value"
答案基于CRAIG RINGER的注释,使用"hstore"扩展
我想宣传他的评论作为答案。
声明r记录;h矿石;开始从更多的joined_tables中选择*into r;从hstore(r)中选择*into h;发出通知"%",h;终止
或
声明r记录;h记录;开始从price_list中选择*into r;对于h,从每个中选择*(hstore(r))环发出通知"%",h;末端回路;终止