Combining scalar and row types in RETURNING
От | Ray O'Donnell |
---|---|
Тема | Combining scalar and row types in RETURNING |
Дата | |
Msg-id | 01020197369aac89-01a7b7b4-b775-471e-ac8e-de8b28d87008-000000@eu-west-1.amazonses.com обсуждение исходный текст |
Список | pgsql-general |
Can you combine scalar and row types in a RETURNING clause? My use-case is getting the results of a MERGE - I'd like to be able to capture both the action performed and the modified row, something like this (this is in a plpgsql function): declare m_action text; m_new_data record; begin merge into my_table t using ( .... ) s on (t.id = s.id) when matched then update ..... when not matched then insert ..... returning merge_action(), t.* into m_action, m_new_data; end; In my case, m_new_data is actually a table row type rather than plain "record". The row is passed on to another function which calculates the altered columns and logs the changes. I've tried it, and it doesn't seem to work; I get an error, "m_new_data is not a scalar variable", so I'm guessing it's not possible, but it's worth asking... I know I can list the returned columns individually in the RETURNING and then use a row constructor to construct the row.... but it'd be handier if I could just derive the row directly from the MERGE query. Thanks in advance, Ray. -- Raymond O'Donnell // Galway // Ireland ray@rodonnell.ie
В списке pgsql-general по дате отправления: