pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Dan Langille <dan@langille.org>
Cc: pgsql-sql@postgresql.org
Subject: Re:
Date: Sun, 28 Sep 2003 15:45:22 -0400
Message-ID: <10801.1064778322@sss.pgh.pa.us> (raw)
In-Reply-To: <20030928151910.S78282@laptop.unixathome.org>
References: <20030928151910.S78282@laptop.unixathome.org>

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'';
        RETURN NEXT r;
    END LOOP;


			regards, tom lane



view thread (6+ messages)  latest in thread

Message-ID: <10801.1064778322@sss.pgh.pa.us>
Permalink:  ../10801.1064778322@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/10801.1064778322@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, dan@langille.org
  Subject: Re:
  In-Reply-To: <10801.1064778322@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox