X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 7ED38D1B522 for ; Sun, 28 Sep 2003 19:26:08 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 09302-03 for ; Sun, 28 Sep 2003 16:25:38 -0300 (ADT) Received: from bast.unixathome.org (bast.unixathome.org [66.11.174.150]) by svr1.postgresql.org (Postfix) with ESMTP id 8CC13D1B4EF for ; Sun, 28 Sep 2003 16:25:36 -0300 (ADT) Received: from laptop.unixathome.org (laptop.unixathome.org [192.168.0.34]) by bast.unixathome.org (Postfix) with ESMTP id 616963F52 for ; Sun, 28 Sep 2003 15:25:16 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by laptop.unixathome.org (Postfix) with ESMTP id C77004F for ; Sun, 28 Sep 2003 15:25:00 -0400 (EDT) Date: Sun, 28 Sep 2003 15:24:59 -0400 (EDT) From: Dan Langille X-X-Sender: dan@laptop.unixathome.org To: pgsql-sql@postgresql.org Message-ID: <20030928151910.S78282@laptop.unixathome.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/366 X-Sequence-Number: 15344 I'm trying to create a function which returns a result set using a dynamic query. The problem occurs when it compiles. I suspect it's my quoting, but I'm not sure of the cause. CREATE OR REPLACE FUNCTION LoginCounts(int) RETURNS SETOF logincounts_record AS ' DECLARE MaxDays ALIAS for $1; r logincounts_record%rowtype; i integer; BEGIN FOR i IN 1..MaxDays LOOP EXECUTE '' SELECT count(*) INTO r FROM users WHERE lastlogin between current_date - interval \''' || quote_literal(i - 1) || '' days\' AND current_date - interval \''' || quote_literal(i) || '' days\'''; RETURN NEXT r; END LOOP; RETURN; END ' LANGUAGE plpgsql; # select * from LoginCounts(2); WARNING: Error occurred while executing PL/pgSQL function logincounts WARNING: line 9 at execute statement ERROR: parser: parse error at or near "days" at character 151 thnks -- Dan Langille - http://www.langille.org/