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@sss.pgh.pa.us
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