4 ms·
You wouldn't even need an extension to the SQL parser - you could just expose a SQL function to do the JSONPath query. e.g. SELECT users.id, jsonpath('$.t
by samstokes 15y ago
You wouldn't even need an extension to the SQL parser - you could just expose a SQL function to do the JSONPath query. e.g.
SELECT users.id, jsonpath('$.timezone', users.preferences_json) AS tz FROM users WHERE tz LIKE 'America/%';
- jaylevitt 15y agoThat's not going to help when you need to restrict your query with JSON, though; the select list is processed after the whole FROM clause, including JOINs, so you'd be producing the whole table and then throwing away whatever didn't match. In general, a few core limitations of the current optimizer - lack of LATERAL key among them - make it impossible to create a PostgreSQL function that blends well with SQL, AFAICT.
- pilif 15y ago> select uid from users wehere jsonpath('$.country', address) = 'CH' PostgreSQL does support functional indexes, so you can easily make this use indexes and thus be fast enough for real use (it's a bad example - I'd probably put the address into an addresses table, but it's enough to illustrate the point)