Re: - Mailing list pgsql-sql

From Tom Lane
Subject Re:
Date
Msg-id 10801.1064778322@sss.pgh.pa.us
Whole thread Raw
In response to ...  (Dan Langille <dan@langille.org>)
Responses Re:
List pgsql-sql
Dan Langille <dan@langille.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'';
RETURNNEXT r;   END LOOP;
 

        regards, tom lane


pgsql-sql by date:

Previous
From: Dan Langille
Date:
Subject: ...
Next
From: Oliver Elphick
Date:
Subject: Re: SUM() & GROUP BY