By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,905 Members | 1,783 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,905 IT Pros & Developers. It's quick & easy.

passing table field name in postgres function

P: 138
hi all,
can i pass field name of a table as a parameter in a function created in postgres,
what i mean is i have one table :student with field names

can i create a function where i can pass either of the fieldname as a parameter.
so that 1 function can be used for either of the conditions.

Feb 9 '10 #1
Share this Question
Share on Google+
3 Replies

Expert 100+
P: 700
Probably Yes, but I don't knwo what do you want to achieve? Can you put an example which describes how do you want the function work?
Feb 9 '10 #2

P: 138
thanx for your quick response.

what i want is i have a table tbl_student with field names:

if the stage of the student is 1 then i have to search by applied_date, if the stage is 2 then the search is by registered_date and if the stage is 3 then the search is by confirmed_date,
what i want is if i know the stage, then i have to pass the different date in a single function .
create or replace function fn_getStudent('registered_date' .......
create or replace function fn_getStudent('applied_date') .......
create or replace function fn_getStudent('confirmed_date') .......

the same function but with different fieldname of the table.
i think u now understand what i mean...
thank you.
Feb 10 '10 #3

Expert 100+
P: 700
But don't you pass only a date value as a parameter? All those columns are type of date I guess so the function that accepts date as parameter would be enough.
Or you want to pass a column name as parameter ?
Feb 21 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.