Running functions that return void in psql

Started by Eric Brownover 21 years ago5 messagesgeneral
Jump to latest
#1Eric Brown
eric.brown@propel.com

I've got quite a few plpgsql functions that insert, update or delete.
They're all declared to return void. All other functions, I can just
run 'select f(...);' from psql to test them. I don't understand how to
test these ones that return void from psql. Thanks.

#2Neil Conway
neilc@samurai.com
In reply to: Eric Brown (#1)
Re: Running functions that return void in psql

Eric Brown wrote:

I've got quite a few plpgsql functions that insert, update or delete.
They're all declared to return void. All other functions, I can just run
'select f(...);' from psql to test them. I don't understand how to test
these ones that return void from psql.

neilc=# create function xyz() returns void as 'begin return; end;'
language 'plpgsql';
CREATE FUNCTION
neilc=# select xyz();
xyz
-----

(1 row)

-Neil

#3Michael Fuhr
mike@fuhr.org
In reply to: Eric Brown (#1)
Re: Running functions that return void in psql

On Wed, Dec 15, 2004 at 12:19:14AM -0800, Eric Brown wrote:

I've got quite a few plpgsql functions that insert, update or delete.
They're all declared to return void. All other functions, I can just
run 'select f(...);' from psql to test them. I don't understand how to
test these ones that return void from psql. Thanks.

You could issue queries to verify that the expected inserts, updates,
or deletes (and only those operations) were actually done.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

#4Eric Brown
eric.brown@propel.com
In reply to: Neil Conway (#2)
Re: Running functions that return void in psql

Thanks. I forgot the 'return;' and the error message led me in the
wrong direction. Thanks!

On Dec 15, 2004, at 12:43 AM, Neil Conway wrote:

Show quoted text

Eric Brown wrote:

I've got quite a few plpgsql functions that insert, update or delete.
They're all declared to return void. All other functions, I can just
run 'select f(...);' from psql to test them. I don't understand how
to test these ones that return void from psql.

neilc=# create function xyz() returns void as 'begin return; end;'
language 'plpgsql';
CREATE FUNCTION
neilc=# select xyz();
xyz
-----

(1 row)

-Neil

#5Richard Huxton
dev@archonet.com
In reply to: Eric Brown (#1)
Re: Running functions that return void in psql

Eric Brown wrote:

I've got quite a few plpgsql functions that insert, update or delete.
They're all declared to return void. All other functions, I can just run
'select f(...);' from psql to test them. I don't understand how to test
these ones that return void from psql. Thanks.

I always return boolean or a count of rows affected in these situations.

--
Richard Huxton
Archonet Ltd