Re: Overlap function for hstore?

From: Stefan Keller <sfkeller(at)gmail(dot)com>
To: Postgresql General <pgsql-general(at)postgresql(dot)org>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Subject: Re: Overlap function for hstore?
Date: 2015-04-06 00:10:22
Message-ID: CAFcOn2_vsG2HJ+Ty+EALkHrgF-yTJoFOTGZ1=LdBm76G=D6=bA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi David

2015-04-04 3:16 GMT+02:00 David G. Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>:
> Not tested!
>
> SELECT hstore(array_agg(key), array_agg(value)) FROM (
> SELECT each(...)
> INTERSECT
> SELECT each(...)
> ) src
>
> David J.

Thanks!

SELECT hstore(array_agg((tmp_attr).key), array_agg((tmp_attr).value))
FROM (
SELECT each((select 'a=>1,b=>2,c=>3'::hstore)) as tmp_attr
INTERSECT ALL
SELECT each((select 'a=>2,d=>4,b=>2'::hstore)) as tmp_attr
) tmp_table;

Cheers, S,

2015-04-04 3:16 GMT+02:00 David G. Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>:
> On Fri, Apr 3, 2015 at 5:37 PM, Stefan Keller <sfkeller(at)gmail(dot)com> wrote:
>>
>> Hi,
>>
>> I'd like to get an overlap function similar to '&&' but for key-value
>> pairs of hstore!
>>
>> This underfits:
>>
>> postgres=# select hstore_to_array('a=>1,b=>2,c=>3'::hstore) &&
>> hstore_to_array('a=>2,d=>4,b=>2'::hstore)
>>
>> ...because array overlaps op takes every element (even 'a' or 2 alone)
>> and doesn't test for key and value together like in 'b=>2'!
>>
>> Any clever ideas?
>
>
> Not tested!
>
> SELECT hstore(array_agg(key), array_agg(value)) FROM (
> SELECT each(...)
> INTERSECT
> SELECT each(...)
> ) src
>
> David J.
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Steve Atkins 2015-04-06 01:46:43 Re: Postgresql Development Options
Previous Message Michael Paquier 2015-04-05 23:26:59 Re: Policy.c program