Re: Argument type list

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Erik Jones <erik(at)myemma(dot)com>
Cc: Gustavo Tonini <gustavotonini(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Argument type list
Date: 2007-08-23 18:27:08
Message-ID: 10494.1187893628@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Erik Jones <erik(at)myemma(dot)com> writes:
> On Aug 23, 2007, at 11:56 AM, Gustavo Tonini wrote:
>> I want to create a function that receive a list argument and filter
>> data with IN operator. Example:

> CREATE OR REPLACE FUNCTION public.ffoo(list sometype[]) RETURNS VOID

this is right ...

> execute 'select * from foo where foo_column::text in (' ||
> array_to_string(list, ',') || ');';

this is pretty horrid. Use = ANY(array) instead of trying to construct
an IN on the fly.

select * from foo where foo_column = any(list)

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Christian Schröder 2007-08-23 18:30:46 Re: "out of memory" error
Previous Message Lewis Cunningham 2007-08-23 18:25:21 Re: PostgreSQL vs Firebird feature comparison finished