pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
How best to create and use associative array type in Postgres?
6+ messages / 3 participants
[nested] [flat]

* How best to create and use associative array type in Postgres?
@ 2022-01-05 12:10 Shaozhong SHI <shishaozhong@gmail.com>
  2022-01-05 14:54 ` Re: How best to create and use associative array type in Postgres? Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 6+ messages in thread

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

In Oracle, one can create and use associative array.  For instance,
TYPE FID_MEASURE IS TABLE OF NUMBER INDEX BY VARCHAR2(38);
NODES_WAITING FID_SET;

How best to create and use associative array type in Postgres?

Or, what is the best/most efficient equivalent in Postgres?

Regards,

David

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

* Re: How best to create and use associative array type in Postgres?
  2022-01-05 12:10 How best to create and use associative array type in Postgres? Shaozhong SHI <shishaozhong@gmail.com>
@ 2022-01-05 14:54 ` Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-05 16:11   ` Re: How best to create and use associative array type in Postgres? Shaozhong SHI <shishaozhong@gmail.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Tom Lane @ 2022-01-05 14:54 UTC (permalink / raw)
  To: Shaozhong SHI <shishaozhong@gmail.com>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>

Shaozhong SHI <shishaozhong@gmail.com> writes:
> How best to create and use associative array type in Postgres?

I think the closest thing you'd find to that is jsonb, or
contrib/hstore if you'd like something with a bit less complexity.
The notation is unlikely to look much like Oracle, but they
both have the ability to store sets of key/value pairs.

https://www.postgresql.org/docs/current/datatype-json.html
https://www.postgresql.org/docs/current/hstore.html

			regards, tom lane





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

* Re: How best to create and use associative array type in Postgres?
  2022-01-05 12:10 How best to create and use associative array type in Postgres? Shaozhong SHI <shishaozhong@gmail.com>
  2022-01-05 14:54 ` Re: How best to create and use associative array type in Postgres? Tom Lane <tgl@sss.pgh.pa.us>
@ 2022-01-05 16:11   ` Shaozhong SHI <shishaozhong@gmail.com>
  2022-01-05 16:24     ` Re: How best to create and use associative array type in Postgres? Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 6+ messages in thread

From: Shaozhong SHI @ 2022-01-05 16:11 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>

What do you think this attempt by using create type and create a function?

Managing Key/Value Pairs in PostgreSQL (justatheory.com)
<https://justatheory.com/2010/08/postgres-key-value-pairs/;

Regards,

David

On Wed, 5 Jan 2022 at 14:54, Tom Lane <tgl@sss.pgh.pa.us> wrote:

> Shaozhong SHI <shishaozhong@gmail.com> writes:
> > How best to create and use associative array type in Postgres?
>
> I think the closest thing you'd find to that is jsonb, or
> contrib/hstore if you'd like something with a bit less complexity.
> The notation is unlikely to look much like Oracle, but they
> both have the ability to store sets of key/value pairs.
>
> https://www.postgresql.org/docs/current/datatype-json.html
> https://www.postgresql.org/docs/current/hstore.html
>
>                         regards, tom lane
>

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

* Re: How best to create and use associative array type in Postgres?
  2022-01-05 12:10 How best to create and use associative array type in Postgres? Shaozhong SHI <shishaozhong@gmail.com>
  2022-01-05 14:54 ` Re: How best to create and use associative array type in Postgres? Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-05 16:11   ` Re: How best to create and use associative array type in Postgres? Shaozhong SHI <shishaozhong@gmail.com>
@ 2022-01-05 16:24     ` Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-05 20:26       ` Re: How best to create and use associative array type in Postgres? Shaozhong SHI <shishaozhong@gmail.com>
  0 siblings, 1 reply; 6+ messages in thread

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

Shaozhong SHI <shishaozhong@gmail.com> writes:
> What do you think this attempt by using create type and create a function?
> Managing Key/Value Pairs in PostgreSQL (justatheory.com)
> <https://justatheory.com/2010/08/postgres-key-value-pairs/;

The date alone should suggest to you that there might be
better ways to do it by now.

			regards, tom lane





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

* Re: How best to create and use associative array type in Postgres?
  2022-01-05 12:10 How best to create and use associative array type in Postgres? Shaozhong SHI <shishaozhong@gmail.com>
  2022-01-05 14:54 ` Re: How best to create and use associative array type in Postgres? Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-05 16:11   ` Re: How best to create and use associative array type in Postgres? Shaozhong SHI <shishaozhong@gmail.com>
  2022-01-05 16:24     ` Re: How best to create and use associative array type in Postgres? Tom Lane <tgl@sss.pgh.pa.us>
@ 2022-01-05 20:26       ` Shaozhong SHI <shishaozhong@gmail.com>
  2022-01-05 20:34         ` Re: How best to create and use associative array type in Postgres? Adrian Klaver <adrian.klaver@aklaver.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Shaozhong SHI @ 2022-01-05 20:26 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>

Have a look at this one.

GitHub - theory/kv-pair: A key/value pair data type for PostgreSQL
<https://github.com/theory/kv-pair;

There is no documentation on how to use it.

Regards,

David

On Wed, 5 Jan 2022 at 16:24, Tom Lane <tgl@sss.pgh.pa.us> wrote:

> Shaozhong SHI <shishaozhong@gmail.com> writes:
> > What do you think this attempt by using create type and create a
> function?
> > Managing Key/Value Pairs in PostgreSQL (justatheory.com)
> > <https://justatheory.com/2010/08/postgres-key-value-pairs/;
>
> The date alone should suggest to you that there might be
> better ways to do it by now.
>
>                         regards, tom lane
>

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

* Re: How best to create and use associative array type in Postgres?
  2022-01-05 12:10 How best to create and use associative array type in Postgres? Shaozhong SHI <shishaozhong@gmail.com>
  2022-01-05 14:54 ` Re: How best to create and use associative array type in Postgres? Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-05 16:11   ` Re: How best to create and use associative array type in Postgres? Shaozhong SHI <shishaozhong@gmail.com>
  2022-01-05 16:24     ` Re: How best to create and use associative array type in Postgres? Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-05 20:26       ` Re: How best to create and use associative array type in Postgres? Shaozhong SHI <shishaozhong@gmail.com>
@ 2022-01-05 20:34         ` Adrian Klaver <adrian.klaver@aklaver.com>
  0 siblings, 0 replies; 6+ messages in thread

From: Adrian Klaver @ 2022-01-05 20:34 UTC (permalink / raw)
  To: Shaozhong SHI <shishaozhong@gmail.com>; Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>

On 1/5/22 12:26, Shaozhong SHI wrote:
> Have a look at this one.
> 
> GitHub - theory/kv-pair: A key/value pair data type for PostgreSQL 
> <https://github.com/theory/kv-pair;
> 
> There is no documentation on how to use it.

Why use it when you have:

https://www.postgresql.org/docs/current/datatype-json.html

Or if you want something simpler:

https://www.postgresql.org/docs/current/hstore.html

> 
> Regards,
> 
> David
> 
> On Wed, 5 Jan 2022 at 16:24, Tom Lane <tgl@sss.pgh.pa.us 
> <mailto:tgl@sss.pgh.pa.us>> wrote:
> 
>     Shaozhong SHI <shishaozhong@gmail.com
>     <mailto:shishaozhong@gmail.com>> writes:
>      > What do you think this attempt by using create type and create a
>     function?
>      > Managing Key/Value Pairs in PostgreSQL (justatheory.com
>     <http://justatheory.com;)
>      > <https://justatheory.com/2010/08/postgres-key-value-pairs/
>     <https://justatheory.com/2010/08/postgres-key-value-pairs/>;
> 
>     The date alone should suggest to you that there might be
>     better ways to do it by now.
> 
>                              regards, tom lane
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com





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


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

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-01-05 12:10 How best to create and use associative array type in Postgres? Shaozhong SHI <shishaozhong@gmail.com>
2022-01-05 14:54 ` Tom Lane <tgl@sss.pgh.pa.us>
2022-01-05 16:11   ` Shaozhong SHI <shishaozhong@gmail.com>
2022-01-05 16:24     ` Tom Lane <tgl@sss.pgh.pa.us>
2022-01-05 20:26       ` Shaozhong SHI <shishaozhong@gmail.com>
2022-01-05 20:34         ` Adrian Klaver <adrian.klaver@aklaver.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