Re: Opposite function of hstore each function

From: ChoonSoo Park <luispark(at)gmail(dot)com>
To: Bosco Rama <postgres(at)boscorama(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Opposite function of hstore each function
Date: 2012-03-02 18:12:18
Message-ID: CACgbiFvghM6AZEZvUa52z5OgUyxTaEHEcf2KJaUf+ho4doPq=Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

It works!

Thank you,
Choon Park

On Fri, Mar 2, 2012 at 12:19 PM, Bosco Rama <postgres(at)boscorama(dot)com> wrote:

> 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.
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Vincent de Phily 2012-03-02 18:19:30 concatenating text and bytea
Previous Message Bosco Rama 2012-03-02 17:19:56 Re: Opposite function of hstore each function