From: | Charles Clavadetscher <clavadetscher(at)swisspug(dot)org> |
---|---|
To: | mrcasa bengaluru <mrcasablr(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: JSONB filed with default JSON from a file |
Date: | 2018-08-13 17:51:52 |
Message-ID: | 7D710F90-3332-497E-9390-54B1F302961B@swisspug.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi
-----------------------------------
Charles Clavadetscher
Neugasse 84
CH - 8005 Zürich
Tel: +41-79-345 18 88
-------------------------------------
> On 13.08.2018, at 19:40, mrcasa bengaluru <mrcasablr(at)gmail(dot)com> wrote:
>
> All,
>
> I'm new to JSONB datatype. We would like to store a nested JSON file in this field. Since the JSON is nested, we wanted to create JSON with default value from an external JSON file.
>
> My address table looks like,
>
> CREATE TABLE address (
> id CHAR(36) UNIQUE NOT NULL,
> address JSONB NOT NULL
> );
>
> For example, the default JSON will look like,
>
> $ cat address_default.json
>
> {
> "address": {
> "address1": "175 N Street",
> "address2": "Timabktu",
> "location": [
> {
> "city": "Utopia",
> "geolocation": [
> {
> "lat": "12.345",
> "long": "12.1234"
> }
> ],
> "state": "Nowhere"
> }
> ],
> "zip": "96001"
> }
> }
>
>
> How do I make the address_default.json as the default JSON value for the address column?
>
I assume that you could declare the column as
address jsonb not null default 'your json here'::jsonb;
I did not try it, but this is what you would do with other data types.
Regards
Charles
From | Date | Subject | |
---|---|---|---|
Next Message | mrcasa bengaluru | 2018-08-13 17:55:48 | Re: JSONB filed with default JSON from a file |
Previous Message | mrcasa bengaluru | 2018-08-13 17:40:41 | JSONB filed with default JSON from a file |