Re: Calling the same function more than once with the same arguments

From: "Clodoaldo Pinto" <clodoaldo(dot)pinto(at)gmail(dot)com>
To: Ben <bench(at)silentmedia(dot)com>
Cc: "pgsql-general postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Calling the same function more than once with the same arguments
Date: 2006-04-20 17:55:50
Message-ID: a595de7a0604201055t287785f0t4779b50e9082379d@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2006/4/19, Ben <bench(at)silentmedia(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andrus 2006-04-20 18:17:37 Re: How to replace rows in table so that foreign key rows
Previous Message Fernan Aguero 2006-04-20 16:52:38 Re: grant privileges across schemas