Received: from localhost (unknown [200.46.204.184]) by developer.postgresql.org (Postfix) with ESMTP id 134D02E0045 for ; Thu, 3 Apr 2008 08:09:28 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 59844-04 for ; Thu, 3 Apr 2008 08:09:18 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.186]) by developer.postgresql.org (Postfix) with ESMTP id D56BD2E0033 for ; Thu, 3 Apr 2008 08:09:24 -0300 (ADT) Received: from webserv.wug.de ([194.25.154.138]) by mrelayeu.kundenserver.de (node=mrelayeu8) with ESMTP (Nemesis) id 0ML31I-1JhNJo3F3o-0003qn; Thu, 03 Apr 2008 13:09:22 +0200 Received: from kretschmer by webserv.wug.de with local (Exim 3.36 #1) id 1JhNJn-0000Wo-00 for pgsql-sql@postgresql.org; Thu, 03 Apr 2008 13:09:19 +0200 Date: Thu, 3 Apr 2008 13:09:19 +0200 From: "A. Kretschmer" To: pgsql-sql@postgresql.org Subject: Re: BROBLEM IN BETWEEN QUERY (plpgsql) Message-ID: <20080403110919.GF23029@a-kretschmer.de> References: <1a027d210804030324x263be097x8be6f2fea6ca183d@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1a027d210804030324x263be097x8be6f2fea6ca183d@mail.gmail.com> X-OS: Debian/GNU Linux - weil ich es mir Wert bin! User-Agent: Mutt/1.5.9i X-Provags-ID: V01U2FsdGVkX1+5HBdkDNgluBk+CdhVnK64S8bhO9xud5jD21D Y6vhT4GE5slZxcZngRK4sleyL+uxJH1Shefbs62ZiUet8d96JF Es8IVIxdh82+soxpdPO2kylseNmXMOt X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200804/19 X-Sequence-Number: 30558 am Thu, dem 03.04.2008, um 15:54:56 +0530 mailte Anoop G folgendes: > hai all, > I want to select dat_replacement between now () and now - 5 dyas or now -7 > days like that i want to pass the integer value as argument to the function. I show you a similar solution: test=*# select * from foo; i | ts ---+------------------------------- 1 | 2008-03-31 15:11:36.214272+02 (1 row) test=*# create or replace function f1(in i int, out t timestamptz) returns setof timestamptz as $$ declare r record;s timestamptz; begin s:=current_timestamp-i * '1day'::interval; for r in select * from foo where ts between s and current_timestamp loop raise notice '--> %',$1; t:=r.ts; return next; end loop; raise notice '%',s; end; $$ language plpgsql; CREATE FUNCTION test=*# select * from f1(1); NOTICE: 2008-04-02 13:05:08.48866+02 t --- (0 rows) test=*# select * from f1(10); NOTICE: --> 10 NOTICE: 2008-03-24 13:05:08.48866+01 t ------------------------------- 2008-03-31 15:11:36.214272+02 (1 row) More examples with IN/OUT - parameters: http://people.planetpostgresql.org/xzilla/index.php?/archives/149-out-parameter-sql-plpgsql-examples.html#extended HTH, Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net