pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Pavel Stehule <pavel.stehule@gmail.com>
To: Daniel Myers <danielsmyers@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: PL/pgsql: function passing argument to IN operator
Date: Sat, 29 Dec 2007 08:29:22 +0100
Message-ID: <162867790712282329x2ff4d99cyd8057ec6aca76d70@mail.gmail.com> (raw)
In-Reply-To: <455d64770712282240h3c93a2f0y9e357d1d23882b10@mail.gmail.com>
References: <455d64770712282240h3c93a2f0y9e357d1d23882b10@mail.gmail.com>

Hello

it has sense only for array type

so you can try:
create replace function foo(anyarray)
returns bool as $$
begin
  return (select 1 = any($1));
end ; $$ language plpgsql;


postgres=# select foo(array[1,2,3]);
 foo
-----
 t
(1 row)

postgres=# select foo(array[2,3]);
 foo
-----
 f
(1 row)

Regards
Pavel Stehule

On 29/12/2007, Daniel Myers <danielsmyers@gmail.com> wrote:
> Hello list,
>    I'm trying to write a function that uses one of its arguments as
> an input to an IN operator in a WHERE clause. I.e., something like:
>
> -- ids are actually integers
> CREATE FUNCTION foo(ids SOMETYPE) RETURNS [whatever] AS $$
> BEGIN
>    SELECT id, [other stuff] FROM table WHERE [other conditions] AND
> id IN (ids);
>    RETURN;
> END
> $$ plpgsql
>
> I had wanted to avoid using the EXECUTE statement and dynamically
> creating the query string, because 1) I'd rather not recompile the
> query each time and 2) I'm doing a SELECT INTO, which apparently
> doesn't work with EXECUTE.
>
> Can anyone help me out?
>
> Thanks,
> Daniel
>
> P.S.: Sorry if capitalizing SQL keywords is bad list etiquette...
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
>                http://www.postgresql.org/docs/faq
>



view thread (2+ messages)

Message-ID: <162867790712282329x2ff4d99cyd8057ec6aca76d70@mail.gmail.com>
Permalink:  ../162867790712282329x2ff4d99cyd8057ec6aca76d70@mail.gmail.com/
Also on:    postgresql.org/message-id/162867790712282329x2ff4d99cyd8057ec6aca76d70@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: pavel.stehule@gmail.com, danielsmyers@gmail.com
  Subject: Re: PL/pgsql: function passing argument to IN operator
  In-Reply-To: <162867790712282329x2ff4d99cyd8057ec6aca76d70@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox