Re: Using a variable as a view name in a select

From: John Summerfield <postgres(at)herakles(dot)homelinux(dot)org>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Using a variable as a view name in a select
Date: 2007-04-03 13:21:35
Message-ID: 461254DF.5090500@herakles.homelinux.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Peter Eisentraut 2007-04-03 13:57:33 Re: LOCK command inside a TRANSACTION
Previous Message A. Kretschmer 2007-04-03 13:16:38 Re: Using a variable as a view name in a select