Re: Test for array slice?

Lists: pgsql-general
From: Peter Fein <pfein(at)pobox(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Test for array slice?
Date: 2005-06-03 16:09:29
Message-ID: 42A080B9.7070901@pobox.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Hi-

I want to do something like this (pardon my pseudocode):

A=ARRAY[4, 5, 6, 7, 8]
B=ARRAY[5, 6]

is_sliceof(A, B), i.e., there exists a slice of A that equals B. My
best thought ATM is to convert both to strings and use pattern matching
- any better ideas?

--Pete


From: Joe Conway <mail(at)joeconway(dot)com>
To: Peter Fein <pfein(at)pobox(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Test for array slice?
Date: 2005-06-03 16:32:40
Message-ID: 42A08628.6010001@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Peter Fein wrote:
> I want to do something like this (pardon my pseudocode):
>
> A=ARRAY[4, 5, 6, 7, 8]
> B=ARRAY[5, 6]
>
> is_sliceof(A, B), i.e., there exists a slice of A that equals B. My
> best thought ATM is to convert both to strings and use pattern matching
> - any better ideas?

I can't think of a really good way to do that directly in Postgres, but
I'd bet (still not sure though) there is a way in R.
http://www.r-project.org/index.html
If so, you could use PL/R:
http://www.joeconway.com/plr/

HTH,

Joe


From: Sean Davis <sdavis2(at)mail(dot)nih(dot)gov>
To: Peter Fein <pfein(at)pobox(dot)com>
Cc: Postgresql-General list <pgsql-general(at)postgresql(dot)org>
Subject: Re: Test for array slice?
Date: 2005-06-03 17:06:39
Message-ID: e95c307299a9944b5fe742203c3052ea@mail.nih.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general


On Jun 3, 2005, at 12:32 PM, Joe Conway wrote:

> Peter Fein wrote:
>> I want to do something like this (pardon my pseudocode):
>> A=ARRAY[4, 5, 6, 7, 8]
>> B=ARRAY[5, 6]
>> is_sliceof(A, B), i.e., there exists a slice of A that equals B. My
>> best thought ATM is to convert both to strings and use pattern
>> matching
>> - any better ideas?
>
> I can't think of a really good way to do that directly in Postgres,
> but I'd bet (still not sure though) there is a way in R.
> http://www.r-project.org/index.html
> If so, you could use PL/R:
> http://www.joeconway.com/plr/

This is probably also easy in perl and python as well.

Sean


From: Peter Fein <pfein(at)pobox(dot)com>
To: Sean Davis <sdavis2(at)mail(dot)nih(dot)gov>
Cc: Postgresql-General list <pgsql-general(at)postgresql(dot)org>
Subject: Re: Test for array slice?
Date: 2005-06-03 17:46:32
Message-ID: 42A09778.4020005@pobox.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Sean Davis wrote:
>
> On Jun 3, 2005, at 12:32 PM, Joe Conway wrote:
>
>> Peter Fein wrote:
>>
>>> I want to do something like this (pardon my pseudocode):
>>> A=ARRAY[4, 5, 6, 7, 8]
>>> B=ARRAY[5, 6]
>>> is_sliceof(A, B), i.e., there exists a slice of A that equals B. My
>>> best thought ATM is to convert both to strings and use pattern matching
>>> - any better ideas?
>>
>>
>> I can't think of a really good way to do that directly in Postgres,
>> but I'd bet (still not sure though) there is a way in R.
>> http://www.r-project.org/index.html
>> If so, you could use PL/R:
>> http://www.joeconway.com/plr/
>
>
> This is probably also easy in perl and python as well.

Actually, I can't think of a great way to do this in python. Maybe
something clever with iterators or list.index... My elements will all
be integers, so the string conversion won't cause any trouble - regexps
seem to be the way to go. Inefficient, since it needs more comparisons
(by character) than comparing ints would, but at least it'll be at C
speed. ;) Thanks all.

--
Peter Fein pfein(at)pobox(dot)com 773-575-0694

Basically, if you're not a utopianist, you're a schmuck. -J. Feldman