Skip to content

Instantly share code, notes, and snippets.

@pilgrim2go
Forked from wilig/gist:611952
Created October 27, 2016 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pilgrim2go/502a2fa6f42952c70585e6c4c297900a to your computer and use it in GitHub Desktop.
Save pilgrim2go/502a2fa6f42952c70585e6c4c297900a to your computer and use it in GitHub Desktop.
create or replace function update_asset_json(text, text, integer) returns setof integer as $$
import simplejson
from datetime import datetime
now = datetime.now()
updated_data = simplejson.loads(args[1])
rs = plpy.execute("select id, data from assets where id in (%s)" % args[0])
resp = []
for r in rs:
data = simplejson.loads(r['data'])
data.update(updated_data)
id = r['id']
resp.append(id)
plpy.warning("Updating %s" % str(id))
plpy.execute("update assets set updated_by=%d, data='%s' where id=%d" % (args[2], simplejson.dumps(data), id))
return resp
$$ language plpythonu;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment