Search Postgresql Archives

plpgsql update row from record variable

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



hi,

I want to write a function that updates arbitrary columns and here's my
pseudocode:

CREATE OR REPLACE FUNCTION update_pet(id int, raw_data jsonb) RETURNS
VOID AS $$
DECLARE
  data record;
BEGIN
  SELECT jsonb_populate_record(null::pets, raw_data) INTO data;
  UPDATE pets [... from data ...] WHERE id = id; -- probably impossible
END;
$$ LANGUAGE plpgsql;

e.g.

SELECT update_pets(1, '{ "name" : "Jerry", "age": 9 }'::jsonb);

Back in 2004, Tom showed how to insert from a plpgsql record:

http://www.postgresql.org/message-id/17840.1087670348@xxxxxxxxxxxxx

Is there any way to "update *" from a record?

Thanks!
Seamus

PS. Whether I **should** do this is another matter, I just want to know
if it's possible.

--
Seamus Abshere, SCEA
https://github.com/seamusabshere
http://linkedin.com/in/seamusabshere


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux