DavyJonesLocker / postgres_ext-serializers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

use json_agg instead of chaining array_to_json(array_agg(row_to_json(table_attributes_filter)))

chollier opened this issue · comments

I've been playing a little bit with this gem, and looking at the queries I feel like we could avoid chaining array_to_json and array_agg and row_to_json

and just use instead json_agg ( http://www.postgresql.org/docs/9.3/static/functions-aggregate.html )

well, writing that I just realized that it was a pg 9.3 feature.

Anyways I thought it could maybe simplify the code 😉

I'm OK with pushing the 9.3 feature if it is available. Is there a way to detect the feature to activate? This should speed things up by avoiding the chaining

SELECT 1 FROM pg_proc WHERE proname = 'json_agg' AND proisagg; on postgres database can check if it exists, but I'm not sure if this is feasible because you aren't usually connected to postgres database.

I think the PostgreSQL adapter has the version of postgres it's connected to, so we could check that as well. Definitely will use when available

On Sat, Aug 9, 2014 at 3:30 PM, Michael J. Cohen notifications@github.com
wrote:

SELECT 1 FROM pg_proc WHERE proname = 'json_agg' AND proisagg; on postgres database can check if it exists, but I'm not sure if this is feasible because you aren't usually connected to postgres database.

Reply to this email directly or view it on GitHub:
#10 (comment)

Usage of json_agg was added in db57839 / PR #23.