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

alias name inside the function

P: 10
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.answerno as "choiceno",q.questionid,q.answer as "answerno",
q.solution,s.question 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
Jul 26 '07 #1
Share this Question
Share on Google+
2 Replies


P: 10
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.answerno as "choiceno",q.questionid,q.answer as "answerno",
q.solution,s.question 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,solution character varying(5000),question character varying(5000));

and if we write the above select query inside a function the result be shown in the given alias name
Jul 31 '07 #2

Expert 100+
P: 534
kirthikasubramanian,
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:

Expand|Select|Wrap|Line Numbers
  1. select fld1 as "FIELD ONE", fld2 as "FIELD TWO"  from my_function(); 
  2.  
Aug 2 '07 #3

Post your reply

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