X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 41210D1E742 for ; Fri, 30 Apr 2004 09:15:31 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 68996-01 for ; Fri, 30 Apr 2004 09:15:13 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by svr1.postgresql.org (Postfix) with ESMTP id C1E99D1E7AA for ; Fri, 30 Apr 2004 09:15:09 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.12.9/8.12.9) with ESMTP id i3UCF9Sx055701 for ; Fri, 30 Apr 2004 12:15:09 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id i3UCE6Xs055148 for pgsql-sql@postgresql.org; Fri, 30 Apr 2004 12:14:06 GMT From: CoL X-Newsgroups: comp.databases.postgresql.sql Subject: Re: Check a value in array Date: Fri, 30 Apr 2004 14:14:04 +0200 Organization: Hub.Org Networking Services Lines: 49 Message-ID: References: <1083260230.20352.7.camel@macbeth.intranet.noze.it> <1083261407.30065.303.camel@jester> <1083313092.7734.3.camel@macbeth.intranet.noze.it> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@news.hub.org User-Agent: Mozilla Thunderbird 0.6+ (Windows/20040422) X-Accept-Language: en-us, en In-Reply-To: <1083313092.7734.3.camel@macbeth.intranet.noze.it> To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200405/25 X-Sequence-Number: 17739 hi, Marco Lazzeri wrote: > Il gio, 2004-04-29 alle 19:56, Rod Taylor ha scritto: > >>On Thu, 2004-04-29 at 13:37, Marco Lazzeri wrote: >> >>>Hi all. >>> >>>I have to check if a value is in an array. >>> >>>I've got a date array in a table and I would like to perform queries >>>like: >>> >>>SELECT * FROM table WHERE date IN dates_array; >> >>If you're using 7.4 or later, try: >> >> SELECT * FROM table WHERE date = ANY(dates_array); >> >>This will work without the contrib package. > > Thank you Rod, I forgot to specify I'm using PostgreSQL 7.3.5. or, you can write a procedure, and make and it immutable:) CREATE OR REPLACE FUNCTION in_array (numeric [], numeric) RETURNS boolean AS' declare array_to alias for $1; array_value alias for $2; i integer default 1; begin while array_to[i] is not null loop if array_value = array_to[i] then return true; end if; i := i+1; end loop; return false; end; 'LANGUAGE 'plpgsql' immutable RETURNS NULL ON NULL INPUT SECURITY INVOKER; change the numeric to your specified type and: WHERE in_array(dates_array,date) = true C.