Running a PL/pgSQL function

Started by Christophe Pettusover 17 years ago4 messagesgeneral
Jump to latest
#1Christophe Pettus
xof@thebuild.com

I'm startled that I've never done this before, but... I have a PL/
pgSQL function that takes no arguments, returns VOID, and has a bunch
of side effects on the database. The correct way of invoking this
function is:

SELECT my_func();

... yes? Thanks; it seems to work fine, but using SELECT here is
causing some part of my brain to scream "counter-intuitive."

#2Adrian Klaver
adrian.klaver@aklaver.com
In reply to: Christophe Pettus (#1)
Re: Running a PL/pgSQL function

On Monday 11 August 2008 4:24:17 pm Christophe wrote:

I'm startled that I've never done this before, but... I have a PL/
pgSQL function that takes no arguments, returns VOID, and has a bunch
of side effects on the database. The correct way of invoking this
function is:

SELECT my_func();

... yes? Thanks; it seems to work fine, but using SELECT here is
causing some part of my brain to scream "counter-intuitive."

Similar to doing:

test=# SELECT 1+1;
?column?
----------
2
(1 row)

--
Adrian Klaver
aklaver@comcast.net

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Christophe Pettus (#1)
Re: Running a PL/pgSQL function

Christophe <xof@thebuild.com> writes:

I'm startled that I've never done this before, but... I have a PL/
pgSQL function that takes no arguments, returns VOID, and has a bunch
of side effects on the database. The correct way of invoking this
function is:
SELECT my_func();
... yes? Thanks; it seems to work fine, but using SELECT here is
causing some part of my brain to scream "counter-intuitive."

Yeah, it is a little weird but it works fine. We treat VOID as a
more-or-less-real datatype that has only one value, an empty string...

regards, tom lane

#4Scott Marlowe
scott.marlowe@gmail.com
In reply to: Adrian Klaver (#2)
Re: Running a PL/pgSQL function

On Mon, Aug 11, 2008 at 6:03 PM, Adrian Klaver <aklaver@comcast.net> wrote:

On Monday 11 August 2008 4:24:17 pm Christophe wrote:

I'm startled that I've never done this before, but... I have a PL/
pgSQL function that takes no arguments, returns VOID, and has a bunch
of side effects on the database. The correct way of invoking this
function is:

SELECT my_func();

... yes? Thanks; it seems to work fine, but using SELECT here is
causing some part of my brain to scream "counter-intuitive."

Similar to doing:

test=# SELECT 1+1;
?column?
----------
2

Hey, it beats select 1+1 from dual!