3 ms·
Only problem I have with JSON on Postgres is you can't update a property of a JSON object like so: update table set jsonCol->propertyA = 42; You need to w
by xtrumanx 12y ago
Only problem I have with JSON on Postgres is you can't update a property of a JSON object like so:
update table set jsonCol->propertyA = 42;
You need to write an extension for that. Easiest to do so using Python but sadly Heroku doesn't support python on postgres since its unsafe.
- mm_throwaway 12y agoPlease correct me if I'm wrong, but isn't updating JSON properties one the big improvements of the soon-to-be-released 9.4 version?
- bencollier49 12y agoJust tried to google this, but couldn't find anything. Why is Python on Postgres considered unsafe?
- JonnieCache 12y agoJust because its a programming language. It can write to disk, open sockets, etc. "As of PostgreSQL 7.4, PL/Python is only available as an "untrusted" language, meaning it does not offer any way of restricting what users can do in it. It has therefore been renamed to plpythonu. The trusted variant plpython might become available again in future, if a new secure execution mechanism is developed in Python. The writer of a function in untrusted PL/Python must take care that the function cannot be used to do anything unwanted, since it will be able to do anything that could be done by a user logged in as the database administrator. Only superusers can create functions in untrusted languages such as plpythonu." http://www.postgresql.org/docs/current/static/plpython.html http://www.postgresql.org/docs/current/static/plpython.html Incidentally I've been merging my json in perl. It's automatically built into postgres, and the Hash::Merge library with it's configurable behaviour is very handy. Still, looking forward to not doing that. 9.4 is coming before xmas, right?
- yangyang 12y agoThat's not strictly true; PL/Perl is (obviously) a programming language and is available in trusted (with certain operations disabled) and untrusted variants: see [1]. The issue with PL/Python is that it's nigh on impossible to properly sandbox Python. [1] http://www.postgresql.org/docs/9.3/static/plperl-trusted.html http://www.postgresql.org/docs/9.3/static/plperl-trusted.htm...
- Erwin 12y agoHuh. That's a little silly given the venerable HSTORE already has this capability: create table foo (d hstore); insert into foo (d) values(hstore(ARRAY['key', 'key2'], ARRAY['value', 'value2'])); -- "key"=>"value", "key2"=>"value2" update foo set d = d || hstore('key', UPPER(d->'key')); -- "key"=>"VALUE", "key2"=>"value2" Seems like JSON / JSONB need operators to merge two objects. In fact isn't JSONB sharing the data format with the new HSTORE2?
- willlll 12y agoYou can use PLV8 to do that in javascript on heroku.
- xtrumanx 12y agoYou're right [0]. Thanks for the heads up. [0] https://blog.heroku.com/archives/2013/6/5/javascript_in_your_postgres https://blog.heroku.com/archives/2013/6/5/javascript_in_your...