passing table field name in postgres function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • coolminded
    New Member
    • Mar 2007
    • 137

    passing table field name in postgres function

    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
    id
    name
    add.

    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.

    TIA
  • rski
    Recognized Expert Contributor
    • Dec 2006
    • 700

    #2
    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?

    Comment

    • coolminded
      New Member
      • Mar 2007
      • 137

      #3
      thanx for your quick response.

      what i want is i have a table tbl_student with field names:
      id
      name
      class
      applied_date
      registered_date
      confirmed_date
      stage

      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 .
      eg:
      create or replace function fn_getStudent(' registered_date ' .......
      or
      create or replace function fn_getStudent(' applied_date') .......
      or
      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.

      Comment

      • rski
        Recognized Expert Contributor
        • Dec 2006
        • 700

        #4
        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 ?

        Comment

        Working...