Created
October 5, 2010 17:29
-
-
Save wilig/611952 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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