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

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: VENKTESH GUTTEDAR <venkteshguttedar(at)gmail(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: PostgreSQL mailing lists <pgsql-general(at)postgresql(dot)org>
Subject: Re: Appending new data to existing field of Json data type
Date: 2014-10-29 14:07:46
Message-ID: 5450F4B2.8040509@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jorge Arevalo 2014-10-29 18:06:03 Re: Query optimization
Previous Message Brilliantov Kirill Vladimirovich 2014-10-29 09:02:03 Re: undefined struct 'pg_conn' on Windows7