alias name inside the function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kirthikasubramanian
    New Member
    • Jul 2007
    • 10

    #1

    alias name inside the function

    i am writing a function to return a table in the select query i am using a join and for some columns i want to give alias name but alias name given within" " is not accepting pls give me some suggestions as soon as possible


    select a.answer as "choice",a.answ erno as "choiceno",q.qu estionid,q.answ er as "answerno",
    q.solution,s.qu estion from answer a , question q, qpselection s where (q.questionid=a .questionid )
    and (s.questionid =a.questionid ) and s.qpid =$1

    this is the query i tryed to run within the function
  • kirthikasubramanian
    New Member
    • Jul 2007
    • 10

    #2
    Originally posted by kirthikasubrama nian
    i am writing a function to return a table in the select query i am using a join and for some columns i want to give alias name but alias name given within" " is not accepting pls give me some suggestions as soon as possible


    select a.answer as "choice",a.answ erno as "choiceno",q.qu estionid,q.answ er as "answerno",
    q.solution,s.qu estion from answer a , question q, qpselection s where (q.questionid=a .questionid )
    and (s.questionid =a.questionid ) and s.qpid =$1

    this is the query i tryed to run within the function

    i got it......

    we have to specify the alias name while creating type

    for eg:
    CREATE TYPE fret AS(choice character varying(5000), choiceno integer, questionid integer,answer integer,solutio n character varying(5000),q uestion character varying(5000));

    and if we write the above select query inside a function the result be shown in the given alias name

    Comment

    • michaelb
      Recognized Expert Contributor
      • Nov 2006
      • 534

      #3
      kirthikasubrama nian,
      please read the Posting Guidelines at the top of the forum and remember to use the CODE tags in your future postings.

      As for your question, I don't quite understand what column aliases inside a function have to do with defining a new type. Very often functions do not involve any custom types at all.

      You are correct that column aliases provided inside the function are not visible when you call it. Considering the function return type (SETOF, I suppose) and how this function is typically called this comes as no surprise.

      You can however provide the aliases when you call the function.
      I would generally consider it a bad practice, but just for the sake of argument you can do something like this:

      [CODE=sql]
      select fld1 as "FIELD ONE", fld2 as "FIELD TWO" from my_function();
      [/CODE]

      Comment

      Working...