sql - Query has no destination for result data, although it should -
here simplified version of function have:
create or replace function my_funct(user_id integer) returns integer $body$ declare my_var integer; begin //.................... if not exists (select * table1) return 0; end if; my_var := (select count(*) table2 inner join .............. ); return (select field1 table3) - my_var; end; $body$ language plpgsql volatile cost 100; alter function my_funct(integer) owner postgres;
but call play framework, error:
[psqlexception: error: query has no destination result data hint: if want discard results of select, use perform instead. where: pl/pgsql function my_funct(integer) @ sql statement]
update:
------------------------------------------------ if not exists (select * table1) select try_to_update_table1(user_id); -- cause. updates table1 end if; if not exists (select * table1) return 0; end if; ------------------------------------------------
the code display should work is. (i tested in 9.3 , does.)
error message unrelated , caused not in question. answer that:
error: query has no destination result data while using cursor
asides
(select field1 table3)
without where
condition doesn't make lot of sense, still work.
your original code:
if not exists (select * table1) return 0; end if;
is superior suggested alternative:
perform * table1; if not found return null; end if;
returning 0
or null
question of requirements. there no "standard behavior".
Comments
Post a Comment