Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

NO DATA FOUND Exception



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.





Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group