Hi.
Im taking my first steps with plpgsql.
I want my function to react to the result of a query in the following way:
begin
select column into variable from table where condition;
exception
when <<data_found>> then return variable;
when <<no_data_found>> then <<do nothing/continue>> ;
when <<any_other_exception>> then <<raise some error message>> ;
end ;
Is something like this possible en plpgsql without recurring to a select
count(*) to check how many results I will get?
Actual code is:
CREATE OR REPLACE FUNCTION test(p_line text) RETURNS text AS
$body$
DECLARE
v_len integer DEFAULT 8;
v_search varchar;
v_register num_geo%ROWTYPE;
BEGIN
-- Search loop
WHILE v_len > 0 LOOP
v_search := substring(p_line, 1, v_len);
begin
SELECT * INTO v_register WHERE prefix = v_search;
exception
when no_data then -- Getting error here
continue;
when others then
return v_register.prefix;
end;
v_len := v_len - 1;
END LOOP;
raise 'Not found';
END;
$body$
LANGUAGE 'plpgsql' VOLATILE ;
ERROR: unrecognized exception condition "no_data"
SQL state: 42704
Context: compile of PL/pgSQL function "test" near line 14
Thanks,
Fernando.
---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly