using a plpgsql function argument as a table column. - Mailing list pgsql-general

From Shaun Savage
Subject using a plpgsql function argument as a table column.
Date
Msg-id f460b997-49e4-87ab-f867-90436647c92a@taxnvote.org
Whole thread Raw
Responses Re: using a plpgsql function argument as a table column.
Re: using a plpgsql function argument as a table column.
List pgsql-general
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 by date:

Previous
From: Andreas Kretschmer
Date:
Subject: Re: WAL replay issue from 9.6.8 to 9.6.10
Next
From: ss
Date:
Subject: using a plpgsql function argument as a table column.