通过“*”行扩张此处不支持(Row expansion via “*” is not support

2019-10-18 12:42发布

我在一个触发背景和试图让下面的代码片段工作。

execute format('insert into %I (user_name, action, new_values, query) 
    values (''%I'', ''i'', hstore(($1).*), current_query())', 
     tg_table_name::text || '_audit', current_user::text)
using new;

我收到以下错误

 [SQL]insert into book (title, n_pages) values ('PG is Great', 250); [Err] ERROR: row expansion via "*" is not supported here LINE 2: values ('u1', 'i', hstore(($1).*), current_q... ^ QUERY: insert into book_audit (user_name, action, new_values, query) values ('u1', 'i', hstore(($1).*), current_query()) CONTEXT: PL/pgSQL function "if_modified_func" line 8 at EXECUTE statement 

如何通过修复行扩张的任何建议“*”此处不支持 ? 耦合到特定的模式是不是一种选择。

Answer 1:

从我的头顶,它应该像这样工作:

EXECUTE format('
   INSERT INTO %I (user_name, action, new_values, query) 
   SELECT $1, ''i'', $2, current_query()'
   , tg_table_name::text || '_audit')
USING current_user, hstore(NEW);

这是更好地与供应的所有值USING条款。
你可以施放记录直接到hstore hstore(record)



文章来源: Row expansion via “*” is not supported here