Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,


I want to know how to write function using output parameter in postgresql.

this is my table actor structure with data and datatype.
actorid|fistname |lastname| last_update|
integer|character|character|timestamp|
1;"Penelope";"Guiness";"2013-05-26 14:47:57.62"
2;"Nick";"Wahlberg";"2013-05-26 14:47:57.62"

What I have tried:

I have written one function to get result set from the query using out keyword in function.

create or replace function view_setactor(id int,out first_name TEXT,lastname TEXT)
returns setof record
as
$$
select * from actor where actor_id=$1;
$$
language 'sql' STABLE;


but iam getting error..

ERROR: function result type must be text because of OUT parameters
********** Error **********

ERROR: function result type must be text because of OUT parameters
SQL state: 42P13


what is this pleas help me on this..any solution would be greatly appreciated.
Posted
Updated 20-Jun-16 0:37am

1 solution

When you have out parameters, your SELECT statement have to select the number and type fitting the parameter list...
In your case you have to do something like this:
SQL
select first_name, lastname from actor where actor_id=$1;
 
Share this answer
 
Comments
Member 11337367 20-Jun-16 7:23am    
Can you tell me what is the difference between using volatile and stable .
Kornfeld Eliyahu Peter 20-Jun-16 7:27am    
Read here: https://www.postgresql.org/docs/current/static/xfunc-volatility.html

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900