Re: using a plpgsql function argument as a table column.

Поиск
Список
Период
Сортировка
От Thomas Boussekey
Тема Re: using a plpgsql function argument as a table column.
Дата
Msg-id CALUeYmfs6w_FBB98fLPXaNmGVfSM_R7pJwOc8r8RF117HqMjDg@mail.gmail.com
обсуждение исходный текст
Ответ на using a plpgsql function argument as a table column.  (ss <ss@tuxclub.org>)
Ответы Re: using a plpgsql function argument as a table column.  (Shaun Savage <savages@taxnvote.org>)
Список pgsql-general
Hello,

Yes, you can :-)

Using a functional that returns a table, like in the following example: http://www.postgresqltutorial.com/plpgsql-function-returns-a-table/

You will have to generate a dynamic sql statement for querying your table with the accurate WHERE clause. Like in this example: https://stackoverflow.com/questions/12780275/dynamic-sql-query-in-postgres

Hope this helps 
Have a nice day 
Thomas 

Le mer. 29 août 2018 à 07:11, ss <ss@tuxclub.org> a écrit :
I have a table with many years as columns. y1976, y2077, .. ,
y2019,y2020 I want to dynamically return a column from a function.


select * from FUNCTION('y2016') .....

select t1.cola t1.colb, t1.colc, t2.y2016 from ..... Where t2.y2016 != 0;

or if I select year y2012 I want FUNCTION('y2012')

select t1.cola t1.colb, t1.colc, t2.y2012 from ..... Where t2.y2012 != 0;


to generalize

select * from FUNCTION( year_column )

select t1.cola t1.colb, t1.colc, t2.year_column from ..... Where
t2.year_column != 0;

is it possible? if so how?


В списке pgsql-general по дате отправления:

Предыдущее
От: ss
Дата:
Сообщение: using a plpgsql function argument as a table column.
Следующее
От: Tim Cross
Дата:
Сообщение: Re: using a plpgsql function argument as a table column.