Question about function

Started by Bruno Lopesabout 24 years ago3 messagesgeneral
Jump to latest
#1Bruno Lopes
blvieira@pcsolution.com.br

Hello list.
That might sound very lame but I am new to postgres.
I was looking into the postgres guide and trying to make a function to make an insert to a table.
but postgres returns me an error in the RETURN of the function

query is:
CREATE FUNCTION test() RETURNS bool AS 'INSERT INTO b (nome) VALUES (\'PQP\');' LANGUAGE 'sql';

function declared to return type bool, but final query is not a retrieve

obviously my return type is incorrect... so what should I use?

______________________________________
Scanned and protected by Inflex
http://pldaniels.com/inflex

#2Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: Bruno Lopes (#1)
Re: Question about function

On Wed, 13 Mar 2002, Bruno Lopes wrote:

Hello list.
That might sound very lame but I am new to postgres.
I was looking into the postgres guide and trying to make a function to make an insert to a table.
but postgres returns me an error in the RETURN of the function

query is:
CREATE FUNCTION test() RETURNS bool AS 'INSERT INTO b (nome) VALUES (\'PQP\');' LANGUAGE 'sql';

function declared to return type bool, but final query is not a retrieve

obviously my return type is incorrect... so what should I use?

I think you need to end an sql language function with a select of some
sort (even if it's just say select true;)

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruno Lopes (#1)
Re: Question about function

Bruno Lopes (Desenvolvimento) <blvieira@pcsolution.com.br> writes:

CREATE FUNCTION test() RETURNS bool AS 'INSERT INTO b (nome) VALUES (\'PQP\');' LANGUAGE 'sql';
function declared to return type bool, but final query is not a retrieve

obviously my return type is incorrect... so what should I use?

It's unhappy because you're not returning anything (no final SELECT
statement).

You might consider updating to a more recent PG version; that error
message hasn't been worded that way for quite awhile.

regards, tom lane