From: Dan Langille <dan(at)langille(dot)org>
To: pgsql-sql(at)postgresql(dot)org
Subject:
Date: 2003-09-28 19:24:59
Message-ID: 20030928151910.S78282@laptop.unixathome.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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/

Responses

  • Re: at 2003-09-28 19:45:22 from Tom Lane

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2003-09-28 19:45:22 Re:
Previous Message Tom Lane 2003-09-28 19:04:13 Re: Mystery function error