If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > PostgreSQL > return select statement in multiple columns when using a function

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-15-11, 15:09
skyStream skyStream is offline
Registered User
 
Join Date: Aug 2011
Posts: 1
return select statement in multiple columns when using a function

Greetings all

I am new to postgresql and have been attempting to create a function in which I can specifiy a variable for it to use in the select statement.

here is what I have so far.

Code:
create type type_f_test as (project_id int, hospital_name text, project_name text, project_type text, project_status text);

create or replace function f_test(integer)
returns setof type_f_test as 

$$
select a.project_id, b.hospital_name, a.project_name, a.project_type, a.project_status  

  from t_projects a 
  join t_hospitals b 
  on a.hospital_id = b.hospital_id 

  join r_projects_users c 
  on a.project_id = c.project_id 

  where a.is_deleted = 0 
  and c.is_deleted = 0 
  and a.project_status <> 'Closed' 
  and a.project_status <> 'Completed' 
  and c.user_id = $1
  order by b.hospital_name, a.project_name asc;
$$

LANGUAGE SQL;
This seems to work; however, it is returning the results in a single column instead of multiple columns.

any help would be appreciated.

Last edited by skyStream; 08-15-11 at 15:24.
Reply With Quote
  #2 (permalink)  
Old 08-25-11, 14:32
loquin loquin is offline
Super Moderator
 
Join Date: Jun 2004
Location: Arizona, USA
Posts: 1,797
I believe you'll need to return a table type with the function - it looks like you're currently returning an array.

Ref the documention here
__________________
Lou
使大吃一惊
"Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
"I have my standards. They may be low, but I have them!" - Bette Middler
"It's a book about a Spanish guy named Manual. You should read it." - Dilbert

Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On