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

Поиск
Список
Период
Сортировка
От John Summerfield
Тема Re: Using a variable as a view name in a select
Дата
Msg-id 461254DF.5090500@herakles.homelinux.org
обсуждение исходный текст
Ответ на Using a variable as a view name in a select  ("Wilkinson, Jim" <Jim.Wilkinson@cra-arc.gc.ca>)
Список 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 по дате отправления:

Предыдущее
От: "A. Kretschmer"
Дата:
Сообщение: Re: Using a variable as a view name in a select
Следующее
От: Peter Eisentraut
Дата:
Сообщение: Re: LOCK command inside a TRANSACTION