Re: Appending new data to existing field of Json data type

From: VENKTESH GUTTEDAR <venkteshguttedar(at)gmail(dot)com>
To: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-general(at)postgresql(dot)org>
Subject: Re: Appending new data to existing field of Json data type
Date: 2014-10-30 06:26:02
Message-ID: CA+iwz4=hWpg0Gp5HcoWppLicgUPk25iD==c=OezD-2g4yZawoQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

@Adrian Klaver, Thanks for this idea but still m really confused with how
to update the json filed in the DB. is there any way to update the json
field in the DB through view.?

On Wed, Oct 29, 2014 at 7:37 PM, Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
wrote:

> On 10/29/2014 01:06 AM, VENKTESH GUTTEDAR wrote:
>
>> Ya agreed thats not legal JSON, that was typing mistake sorry for that,
>>
>> let me make you clear what i need exactly,
>>
>> I have table named (exampleTable) with json field as (example_list), and
>> when i say
>> SELECT * FROM exampleTable;
>>
>> id | example_list
>> ---+----------------------------------------------
>> 2 | {"abc":[ { "a":"b","c":"d" } ] }
>>
>>
>> And this data i am inserting through DJango view by writing the
>> following statement
>>
>> test = ExampleTable(id = 2, example_list = {"abc" : [ { "a":"b","c":"d"
>> } ] })
>> test.save()
>>
>> now i want to append { "e":"f", "g":"h" } to example_list by specifying
>> the id.
>> and after appending the data should be stored in the following way :
>> After appending,
>> for example if i say :
>> SELECT * FROM exampleTable;
>> i should get this.
>>
>> id | example_list
>> ---+--------------------------------------------------------
>> 2 | {"abc":[ { "a":"b","c":"d" }, { "e":"f", "g":"h" } ] }
>>
>> Hope your clear now.
>>
>> So now Guide me to append it through Python Djnago View. or through raw
>> sql query.
>>
>
> If it where me I would bring the data into the view and do the work there
> in Python using dicts and lists. There is a Python module out there that
> make this easier to do:
>
> https://pypi.python.org/pypi/django-jsonfield
>
>
>
>>
> --
>> Regards :
>> Venktesh Guttedar.
>>
>>
>
> --
> Adrian Klaver
> adrian(dot)klaver(at)aklaver(dot)com
>

--
Regards :
Venktesh Guttedar.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Postgres India 2014-10-30 07:47:17 Re: DBlink, postgres to DB2
Previous Message Fabio Ugo Venchiarutti 2014-10-30 06:12:20 Unexpected planner behavior with *_pattern_ops index matching