Re: Using a variable as a view name in a select - Mailing list pgsql-sql

From John Summerfield
Subject Re: Using a variable as a view name in a select
Date
Msg-id 461254DF.5090500@herakles.homelinux.org
Whole thread Raw
In response to Using a variable as a view name in a select  ("Wilkinson, Jim" <Jim.Wilkinson@cra-arc.gc.ca>)
List 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.



pgsql-sql by date:

Previous
From: "A. Kretschmer"
Date:
Subject: Re: Using a variable as a view name in a select
Next
From: Peter Eisentraut
Date:
Subject: Re: LOCK command inside a TRANSACTION