Bruno
Bruno

Reputation: 115

How to avoid serialization of postgres json result in Sequel

In a web server, I'm running a query in Postgres that performs a select json_build_object of an aggregation(json_agg). I'm using Sequel to fetch this data, and I'm getting as a value an instance of Sequel::Postgres::JSONHash. Then, I perform a to_json in order to send it to the web client.

The output of this query is very big and I think that it could be more performant If I could grab the raw json response of postgres directly and send it to the client, instead of parsing it into JSONHash (which is done by Sequel) and then converting it again to json.

How could I do it?

Upvotes: 1

Views: 224

Answers (1)

Jeremy Evans
Jeremy Evans

Reputation: 12139

Cast the json_build_object from json to text in the query: SELECT json_build_object(...)::text ...

Upvotes: 4

Related Questions