Re: Opposite function of hstore each function - Mailing list pgsql-general

From Bosco Rama
Subject Re: Opposite function of hstore each function
Date
Msg-id 4F51013C.6060503@boscorama.com
Whole thread Raw
In response to Opposite function of hstore each function  (ChoonSoo Park <luispark@gmail.com>)
Responses Re: Opposite function of hstore each function  (ChoonSoo Park <luispark@gmail.com>)
List pgsql-general
ChoonSoo Park wrote:
> Each function returns key/value pairs from hstore type.
> Is there any opposite function that returns hstore type from key/value rows?
>
> I know hstore (text[], text[]) can construct it. Is there any other choice?
>
> I have a table with ID & Description columns and want to return hstore type
>  (ID1=>Desc1,ID2=>Desc2,....) that matches a query condition.
>From top of my head, this is the only query I can think of
>
> SELECT hstore ((SELECT array(SELECT CAST(ID as TEXT) FROM T1 WHERE ....)),
> (SELECT array(SELECT Description FROM T1 WHERE ...)))
>
> But I don't want to run the same where condition twice.

You could try:
   select hstore(array_agg(CAST(ID as TEXT)), array_agg(Description)) from T1 where ...

I don't have hstore loaded but that seems like it should work.

HTH

Bosco.

pgsql-general by date:

Previous
From: ChoonSoo Park
Date:
Subject: Opposite function of hstore each function
Next
From: ChoonSoo Park
Date:
Subject: Re: Opposite function of hstore each function