pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Create and access a dictionary type
8+ messages / 4 participants
[nested] [flat]

* Create and access a dictionary type
@ 2022-01-05 13:17 Shaozhong SHI <shishaozhong@gmail.com>
  2022-01-05 13:22 ` Re: Create and access a dictionary type Tomas Vondra <tomas.vondra@enterprisedb.com>
  0 siblings, 1 reply; 8+ messages in thread

From: Shaozhong SHI @ 2022-01-05 13:17 UTC (permalink / raw)
  To: pgsql-general <pgsql-general@lists.postgresql.org>

Any examples in Postgres to create a dictionary type to store and access
key value pairs?

Regards,

David

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Create and access a dictionary type
  2022-01-05 13:17 Create and access a dictionary type Shaozhong SHI <shishaozhong@gmail.com>
@ 2022-01-05 13:22 ` Tomas Vondra <tomas.vondra@enterprisedb.com>
  2022-01-05 13:36   ` Re: Create and access a dictionary type Shaozhong SHI <shishaozhong@gmail.com>
  2022-01-05 16:24   ` Re: Create and access a dictionary type Ron <ronljohnsonjr@gmail.com>
  0 siblings, 2 replies; 8+ messages in thread

From: Tomas Vondra @ 2022-01-05 13:22 UTC (permalink / raw)
  To: Shaozhong SHI <shishaozhong@gmail.com>; pgsql-general <pgsql-general@lists.postgresql.org>

On 1/5/22 14:17, Shaozhong SHI wrote:
> Any examples in Postgres to create a dictionary type to store and access 
> key value pairs?
> 

I'd say JSONB can be used as an associative array, and e.g. in Python 
can map to dict data type.


regards

-- 
Tomas Vondra
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Create and access a dictionary type
  2022-01-05 13:17 Create and access a dictionary type Shaozhong SHI <shishaozhong@gmail.com>
  2022-01-05 13:22 ` Re: Create and access a dictionary type Tomas Vondra <tomas.vondra@enterprisedb.com>
@ 2022-01-05 13:36   ` Shaozhong SHI <shishaozhong@gmail.com>
  2022-01-05 16:37     ` Re: Create and access a dictionary type Tomas Vondra <tomas.vondra@enterprisedb.com>
  1 sibling, 1 reply; 8+ messages in thread

From: Shaozhong SHI @ 2022-01-05 13:36 UTC (permalink / raw)
  To: Tomas Vondra <tomas.vondra@enterprisedb.com>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>

I just checked operators.  I could not find any operator to set a new value
given a key.

Regards,

David

On Wed, 5 Jan 2022 at 13:22, Tomas Vondra <tomas.vondra@enterprisedb.com>
wrote:

> On 1/5/22 14:17, Shaozhong SHI wrote:
> > Any examples in Postgres to create a dictionary type to store and access
> > key value pairs?
> >
>
> I'd say JSONB can be used as an associative array, and e.g. in Python
> can map to dict data type.
>
>
> regards
>
> --
> Tomas Vondra
> EnterpriseDB: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company
>

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Create and access a dictionary type
  2022-01-05 13:17 Create and access a dictionary type Shaozhong SHI <shishaozhong@gmail.com>
  2022-01-05 13:22 ` Re: Create and access a dictionary type Tomas Vondra <tomas.vondra@enterprisedb.com>
  2022-01-05 13:36   ` Re: Create and access a dictionary type Shaozhong SHI <shishaozhong@gmail.com>
@ 2022-01-05 16:37     ` Tomas Vondra <tomas.vondra@enterprisedb.com>
  0 siblings, 0 replies; 8+ messages in thread

From: Tomas Vondra @ 2022-01-05 16:37 UTC (permalink / raw)
  To: Shaozhong SHI <shishaozhong@gmail.com>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>

On 1/5/22 14:36, Shaozhong SHI wrote:
> I just checked operators.  I could not find any operator to set a new 
> value given a key.
> 

I'd say jsonb_set is what you're looking for.

Postgres does not have a thing that'd match the Oracle feature exactly, 
you'll have to adjust your application to use what's available.

regards


-- 
Tomas Vondra
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Create and access a dictionary type
  2022-01-05 13:17 Create and access a dictionary type Shaozhong SHI <shishaozhong@gmail.com>
  2022-01-05 13:22 ` Re: Create and access a dictionary type Tomas Vondra <tomas.vondra@enterprisedb.com>
@ 2022-01-05 16:24   ` Ron <ronljohnsonjr@gmail.com>
  2022-01-05 16:35     ` Re: Create and access a dictionary type Tomas Vondra <tomas.vondra@enterprisedb.com>
  1 sibling, 1 reply; 8+ messages in thread

From: Ron @ 2022-01-05 16:24 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

On 1/5/22 7:22 AM, Tomas Vondra wrote:
> On 1/5/22 14:17, Shaozhong SHI wrote:
>> Any examples in Postgres to create a dictionary type to store and access 
>> key value pairs?
>>
>
> I'd say JSONB can be used as an associative array, and e.g. in Python can 
> map to dict data type.

The question confuses me.  Why isn't "create a table with Primary Key" the 
answer to "Any examples in Postgres to create a dictionary type to store and 
access key value pairs?"

-- 
Angular momentum makes the world go 'round.





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Create and access a dictionary type
  2022-01-05 13:17 Create and access a dictionary type Shaozhong SHI <shishaozhong@gmail.com>
  2022-01-05 13:22 ` Re: Create and access a dictionary type Tomas Vondra <tomas.vondra@enterprisedb.com>
  2022-01-05 16:24   ` Re: Create and access a dictionary type Ron <ronljohnsonjr@gmail.com>
@ 2022-01-05 16:35     ` Tomas Vondra <tomas.vondra@enterprisedb.com>
  2022-01-05 16:57       ` Re: Create and access a dictionary type Ron <ronljohnsonjr@gmail.com>
  0 siblings, 1 reply; 8+ messages in thread

From: Tomas Vondra @ 2022-01-05 16:35 UTC (permalink / raw)
  To: Ron <ronljohnsonjr@gmail.com>; pgsql-general@lists.postgresql.org

On 1/5/22 17:24, Ron wrote:
> On 1/5/22 7:22 AM, Tomas Vondra wrote:
>> On 1/5/22 14:17, Shaozhong SHI wrote:
>>> Any examples in Postgres to create a dictionary type to store and 
>>> access key value pairs?
>>>
>>
>> I'd say JSONB can be used as an associative array, and e.g. in Python 
>> can map to dict data type.
> 
> The question confuses me.  Why isn't "create a table with Primary Key" 
> the answer to "Any examples in Postgres to create a dictionary type to 
> store and access key value pairs?"
> 

Well, yes - you can always decompose the dict and store it in an EAV, 
but sometimes it's more convenient to just use "nested" dictionary at 
the row level. Which is what a JSONB column does.

regards

-- 
Tomas Vondra
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Create and access a dictionary type
  2022-01-05 13:17 Create and access a dictionary type Shaozhong SHI <shishaozhong@gmail.com>
  2022-01-05 13:22 ` Re: Create and access a dictionary type Tomas Vondra <tomas.vondra@enterprisedb.com>
  2022-01-05 16:24   ` Re: Create and access a dictionary type Ron <ronljohnsonjr@gmail.com>
  2022-01-05 16:35     ` Re: Create and access a dictionary type Tomas Vondra <tomas.vondra@enterprisedb.com>
@ 2022-01-05 16:57       ` Ron <ronljohnsonjr@gmail.com>
  2022-01-05 16:59         ` Re: Create and access a dictionary type Rob Sargent <robjsargent@gmail.com>
  0 siblings, 1 reply; 8+ messages in thread

From: Ron @ 2022-01-05 16:57 UTC (permalink / raw)
  To: Tomas Vondra <tomas.vondra@enterprisedb.com>; pgsql-general@lists.postgresql.org

On 1/5/22 10:35 AM, Tomas Vondra wrote:
> On 1/5/22 17:24, Ron wrote:
>> On 1/5/22 7:22 AM, Tomas Vondra wrote:
>>> On 1/5/22 14:17, Shaozhong SHI wrote:
>>>> Any examples in Postgres to create a dictionary type to store and 
>>>> access key value pairs?
>>>>
>>>
>>> I'd say JSONB can be used as an associative array, and e.g. in Python 
>>> can map to dict data type.
>>
>> The question confuses me.  Why isn't "create a table with Primary Key" 
>> the answer to "Any examples in Postgres to create a dictionary type to 
>> store and access key value pairs?"
>>
>
> Well, yes - you can always decompose the dict and store it in an EAV, but 
> sometimes it's more convenient to just use "nested" dictionary at the row 
> level. Which is what a JSONB column does.

Edgar Codd is rolling in his grave.


-- 
Angular momentum makes the world go 'round.





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Create and access a dictionary type
  2022-01-05 13:17 Create and access a dictionary type Shaozhong SHI <shishaozhong@gmail.com>
  2022-01-05 13:22 ` Re: Create and access a dictionary type Tomas Vondra <tomas.vondra@enterprisedb.com>
  2022-01-05 16:24   ` Re: Create and access a dictionary type Ron <ronljohnsonjr@gmail.com>
  2022-01-05 16:35     ` Re: Create and access a dictionary type Tomas Vondra <tomas.vondra@enterprisedb.com>
  2022-01-05 16:57       ` Re: Create and access a dictionary type Ron <ronljohnsonjr@gmail.com>
@ 2022-01-05 16:59         ` Rob Sargent <robjsargent@gmail.com>
  0 siblings, 0 replies; 8+ messages in thread

From: Rob Sargent @ 2022-01-05 16:59 UTC (permalink / raw)
  To: Ron <ronljohnsonjr@gmail.com>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>



>> 
>> Well, yes - you can always decompose the dict and store it in an EAV, but sometimes it's more convenient to just use "nested" dictionary at the row level. Which is what a JSONB column does.
> 
> Edgar Codd is rolling in his grave.
> 
> 
Contributing mightily to the global angular momentum, for sure.
> -- 
> Angular momentum makes the world go 'round.

^ permalink  raw  reply  [nested|flat] 8+ messages in thread


end of thread, other threads:[~2022-01-05 16:59 UTC | newest]

Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-01-05 13:17 Create and access a dictionary type Shaozhong SHI <shishaozhong@gmail.com>
2022-01-05 13:22 ` Tomas Vondra <tomas.vondra@enterprisedb.com>
2022-01-05 13:36   ` Shaozhong SHI <shishaozhong@gmail.com>
2022-01-05 16:37     ` Tomas Vondra <tomas.vondra@enterprisedb.com>
2022-01-05 16:24   ` Ron <ronljohnsonjr@gmail.com>
2022-01-05 16:35     ` Tomas Vondra <tomas.vondra@enterprisedb.com>
2022-01-05 16:57       ` Ron <ronljohnsonjr@gmail.com>
2022-01-05 16:59         ` Rob Sargent <robjsargent@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox