Re: Calling the same function more than once with the same arguments - Mailing list pgsql-general

From Clodoaldo Pinto
Subject Re: Calling the same function more than once with the same arguments
Date
Msg-id a595de7a0604201055t287785f0t4779b50e9082379d@mail.gmail.com
Whole thread Raw
In response to Re: Calling the same function more than once with the same  (Ben <bench@silentmedia.com>)
List pgsql-general
2006/4/19, Ben <bench@silentmedia.com>:
> Look into the immutable flag on function creation:

I have read that section and I'm still not sure about it.

This is the caller() function:

create or replace function caller(int4)
returns some_type as

$body$

select
  array(select distinct a from called($1)) as a
  ,
  array(select distinct b from called($1)) as b
;

$body$
language 'sql' stable strict;

Since called() will read from a table that can be modified it is
declared as stable and not as immutable.

This is what is in section 32.6:
" A STABLE function cannot modify the database and is guaranteed to
return the same results given the same arguments FOR ALL ROWS WITHIN A
SINGLE STATEMENT."

Is called() called from within a single statement in caller()?

Will the optimizer optimize the multiple calls (there will be about
30) to a single call?

Regards, Clodoaldo Pinto

pgsql-general by date:

Previous
From: Fernan Aguero
Date:
Subject: Re: grant privileges across schemas
Next
From: "Andrus"
Date:
Subject: Re: How to replace rows in table so that foreign key rows