From: John Summerfield <postgres@herakles.homelinux.org>
To: pgsql-sql@postgresql.org
Subject: Re: Using a variable as a view name in a select
Date: Tue, 03 Apr 2007 21:21:35 +0800
Message-ID: <461254DF.5090500@herakles.homelinux.org> (raw)
In-Reply-To: <7CCC5BEF5E72394C963E529B54EB4A642A19B3@SD01ITMV12.PROD.NET>
References: <7CCC5BEF5E72394C963E529B54EB4A642A19B3@SD01ITMV12.PROD.NET>
Wilkinson, Jim wrote:
> I have created a view, called april_may. I need to select this view by
> combineing to fields in the database to create the view name etc ...
Jim
Learn to use "compose" or "write" and not "reply" when you want to ask a
fresh question. My email rolled this into the "LOCK" thread making it
incredibly difficult to find.
>
>
>
> Create view as select * from table_X;
>
>
>
> I need to do something like this ...
>
>
>
> Select * from (select table.start_month||_||table.end_month);
>
> ==================
>
> Start_month = april
>
> End_month = May
>
>
>
> What I what to pass to the select is the combination of the 2 fields as
> the view name.
>
>
>
> Any ideas ?
The simple ways I can think of are external to postgresql, and depend on
your host environment.
For example, on Linux (or OS X) I might do something like this:
psql -c "select * from (select table.$(date +%B -d 'last
month')_table.$(date +%B))"
Note, the above para is really a single line, there is a space between
"last" and "month."
on DOS it might be a little trickier, but probably VB Script can do it.
In Java, it is somewhat similar but different.
If this doesn't answer, give better info and maybe someone else can help
you properly.
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: postgres@herakles.homelinux.org
Subject: Re: Using a variable as a view name in a select
In-Reply-To: <461254DF.5090500@herakles.homelinux.org>
* 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