Opened 5 years ago

Closed 5 years ago

#30615 closed New feature (wontfix)

Add row_to_json(row) postgresql function.

Reported by: Julián Perelli Owned by: nobody
Component: contrib.postgres Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Add row_to_json(row) postgresql function, reference here: https://www.postgresql.org/docs/11/functions-json.html

see here for a simple implementation that also adds useful Table() Expression

I spent a lot of time trying to solve how to send an aliased table as an argument to a function (row_to_json). I think it will be super useful for a lot of people handling json documents in postgresql, the most difficult part was understanding the Table() Expression

Change History (2)

comment:1 by Mariusz Felisiak, 5 years ago

Component: Database layer (models, ORM)contrib.postgres
Summary: Add row_to_json(row) postgresql functionAdd row_to_json(row) postgresql function.
Version: 2.2master

I think you can achieve the same by serializing instances to JSON format serialization-formats-json, e.g.

instance = MyModel.objects.first()
json_data = serialize('json', [instance])

comment:2 by Mariusz Felisiak, 5 years ago

Resolution: wontfix
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top