Re:

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Dan Langille <dan(at)langille(dot)org>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re:
Date: 2003-09-28 19:45:22
Message-ID: 10801.1064778322@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Dan Langille <dan(at)langille(dot)org> writes:
> WHERE lastlogin between current_date - interval \''' ||
> quote_literal(i - 1) || '' days\'
> AND current_date - interval \''' ||
> quote_literal(i) || '' days\''';

IIRC, quote_literal() puts single quotes around its result. So you have
too many quotes there. Given that you know i is an integer, you don't
really need quote_literal for it. Actually, you don't need EXECUTE
here at all. Why not just

FOR i IN 1..MaxDays LOOP
SELECT count(*)
INTO r
FROM users
WHERE lastlogin between current_date - (i-1) * interval ''1 day''
AND current_date - i * interval ''1 day'';
RETURN NEXT r;
END LOOP;

regards, tom lane

In response to

  • at 2003-09-28 19:24:59 from Dan Langille

Responses

  • Re: at 2003-09-28 20:06:20 from Dan Langille
  • Re: at 2003-09-29 14:04:08 from Jean-Luc Lachance

Browse pgsql-sql by date

  From Date Subject
Next Message Oliver Elphick 2003-09-28 19:56:56 Re: SUM() & GROUP BY
Previous Message Dan Langille 2003-09-28 19:24:59