2013-08-20 3 views
1

Я в контексте триггера и пытаюсь получить следующий фрагмент для работы.Расширение строки через «*» здесь не поддерживается

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 

Любое предложение о том, как исправить расширения строки с помощью "*" не поддерживается здесь? Соединение с конкретной схемой не является вариантом.

+0

Не работает hstore, который выполняет формат выполнения ('insert into% I select' 'i' ', now(), user, ($ 1). *', Tg_table_name || '_audit'), используя new; return new; – user2624443

ответ

0

Из верхней части моей головы, он должен работать так:

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.
И вы можете cast a record to hstore directly with hstore(record).

Смежные вопросы