Hi thescripts team,
I would like to ask for your help once again regarding returning set of records in plpgsql. I followed examples presented in other sites regarding this function but my script doesnt work.
here's my code -
create or replace function find_postal(varchar, varchar, varchar) returns setof record as
-
'
-
declare
-
ret_row record;
-
prefnme alias for $1;
-
cty alias for $2;
-
dname alias for $3;
-
begin
-
for ret_row in select * from area where pref_nme like coalesce ($1,''%'') or city like COALESCE($2,''%'') or district_nme like coalesce ($3,''%'') loop
-
return next ret_row;
-
end loop;
-
return;
-
end;
-
'
-
language 'plpgsql';
And here's the error being returned:
ERROR: set-valued function called in context that cannot accept a set
CONTEXT: PL/pgSQL function "find_postal" line 8 at return next
Thanks in advance for those who can help me
6 18307
I think this is the easiest way to make this function work: - Drop the function
- Change the function return type from "setof record" to "setof <table-name>"
("setof area" in this case) - Optionally, you may also like to change declaration "ret_row record;" to "ret_row area%rowtype;"
(it should work either way) - Recompile, and don't forget that functions returning setof must be called as
select * from func_name (...)
select func_name (...) will not work.
Hi michaelb,
Thanks again for helping! It worked now!
hi
i have the problem like this but i couldn't solve this yet.
i have the function below; -
CREATE OR REPLACE FUNCTION "public"."fnc_dupps" (x integer, out y integer, out z integer, out t varchar) RETURNS SETOF "pg_catalog"."record" AS
-
$body$
-
declare cur_koyler cursor for
-
select koy_bolgeid,koy_idno from tbl_koyler;
-
declare k integer;
-
begin
-
open cur_koyler;
-
loop
-
exit when not found;
-
fetch cur_koyler into y,z;
-
raise exception 'Hata ';
-
return next;
-
end loop;
-
end;
-
$body$
-
LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;
-
When i execute the function it turns me nothing.
but -
select koy_bolgeid,koy_idno from tbl_koyler
-
query has a records. i send this for example. the original has the much outputs. so i dont want to set return type to table. (if there is no way i have to do sure.)
Best Regards.
Pg : 8.2
Platform : xp sp2
Best Regards.
hi
i create the type for this function -
create type typ_dupps as
-
(x integer,
-
y integer,
-
z varchar )
-
and the functions latest version is below -
CREATE OR REPLACE FUNCTION "public"."fnc_dupps" (x integer) RETURNS SETOF "pg_catalog"."record" AS
-
$body$
-
declare sonuc typ_dupps;
-
declare crs_koyler cursor for
-
select koy_idno,koy_bolgeid,koy_ad from tbl_koyler;
-
declare i integer;
-
declare k varchar;
-
-
begin
-
open crs_koyler;
-
loop
-
exit when not found;
-
fetch crs_koyler into sonuc.x,sonuc.y;
-
return next sonuc;
-
end loop;
-
end;
-
$body$
-
LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;
-
it is running perfectly .
Best Regards.
HI
i tried to run the following function. Can you help me. It is giving runtime error as
ERROR: cursor "cusr" does not exist
CONTEXT: PL/pgSQL function "com_attr_ins" line 15 at fetch
The function code is - CREATE OR REPLACE FUNCTION "public"."com_attr_ins" () RETURNS "pg_catalog"."void" AS
-
$body$
-
DECLARE
-
attr_id integer;
-
cat_attr_id integer;
-
nam varchar(512);
-
lbl varchar(512);
-
val_type bigint;
-
aggr_type bigint;
-
allow_null bool;
-
cusr CURSOR for select id , comp_cat_attr_id from component_attr;
-
BEGIN
-
loop
-
fetch cusr INTO attr_id , cat_attr_id;
-
if not found then
-
exit;
-
end if;
-
select into nam name from component_category_attr where id = cat_attr_id;
-
select into lbl label from component_category_attr where id = cat_attr_id;
-
select into val_type value_type from component_category_attr where id = cat_attr_id;
-
select into aggr_type AGGREGATION_TYPE from component_category_attr where id = cat_attr_id;
-
select into allow_null ALLOW_NULL_VALUE from component_category_attr where id = cat_attr_id;
-
update temp_attr set label = lbl ,
-
value_type = val_type ,
-
aggregation_type = aggr_type,
-
allow_null_value = allow_null
-
where id = attr_id and COMP_CAT_ATTR_ID = cat_attr_id;
-
end loop;
-
end;
-
$body$
-
LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;
rski 700
Expert 512MB
see here
i don't see where do you open a cursor
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Julie May |
last post by:
I have 90% of my function working and I know to get the next 10% it is justa matter of getting the quotations and the escaping quotations correct. Here is the portion that does work:
<working...
|
by: Christopher Murtagh |
last post by:
Greetings,
I'm trying to write a pl/perl function that will return multiple rows.
I've looked all over the web and only found vague references as to how
to do this (some said it was possible,...
|
by: Christopher Murtagh |
last post by:
Greetings,
I've got a fairly simple function that I'm trying to return a set, but
seem to have come across a stumbling block. When I execute the function
below (the input params are not used at...
|
by: Ron St-Pierre |
last post by:
On a daily basis I place a lot of data into the empty table dailyList,
and from that data update certain fields in currentList. I thought that
using a function would be a good way to do this(?)....
|
by: ezra epstein |
last post by:
I'm been banging my head over this for a little while now.
Here's a simple function to return a record:
<code>
CREATE OR REPLACE FUNCTION create_item_record_for_override(INTEGER,
VARCHAR )...
|
by: Karl O. Pinc |
last post by:
I want to return multiple values, but not a set, only a single row,
from a
plpgsql function and I can't seem to get it to work. (I suppose I'd be
happy to return a set, but I can't seem to make...
|
by: Robert Fitzpatrick |
last post by:
Can someone point me to some more information or perhaps show an example
of returning a recordset from a plpgsql function. I'd like to send an
argument or arguments to the function, do some queries...
|
by: Vladimir M |
last post by:
Hi
I am writing a function with PL/pgSQL, which returns result of some complex query with several tables. In manual i found such example:
CREATE OR REPLACE FUNCTION Test() RETURNS SETOF...
|
by: lazybee26 |
last post by:
Hello –
I’m trying to findout a better solution to this approach.
Currently if I have to return columns from multiple tables, I have to define my own TYPE and then return SETOF that type in...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |