Re: sql and timestamp variable - Mailing list pgsql-general

From nolan@celery.tssi.com
Subject Re: sql and timestamp variable
Date
Msg-id 20030515165543.4064.qmail@celery.tssi.com
Whole thread Raw
In response to sql and timestamp variable  ("Johnson, Shaunn" <SJohnson6@bcbsm.com>)
List pgsql-general
> select count(*) from  db2_ps_regprof_$datemonth where mbr is null ;
>
> [/snip wishful thinking]
>
> How can you do this?  Otherwise, I may have to do this in Perl,
> perhaps?

Try this in psql:

\set datemonth xxxxxxx  (fill in whatever you need here)

select count(*) from db2_ps_regprof_:datemonth where mbr is null;

Is that what you're after?

You could even pre-load some values via the .psqlrc file (and update
that file with a cron job as needed) to pre-load some values:

select count(*) from db2_ps_regprof_:current where mbr is null;
select count(*) from db2_ps_regprof_:last where mbr is null;
etc.

There's some stuff in the psql documentation about % and backticks, but
that appears to only work with prompts.  What would be nice would be if the
text in backticks could also be executed and the results fed into a
set command, so that you could do the following:

\set datemonth `select table_name from table_select where month = 'Jan';`
--
Mike Nolan

pgsql-general by date:

Previous
From: "Fernando Papa"
Date:
Subject: Declaring cursors in pl/pgsql and using with FOR/LOOP
Next
From: "Nigel J. Andrews"
Date:
Subject: Re: - what protocol for an Internet postgres