Unix Technical Forum

Can a stored procedure that creates a temp table be declared STABLE?

This is a discussion on Can a stored procedure that creates a temp table be declared STABLE? within the Pgsql General forums, part of the PostgreSQL category; --> Hello, I need to write a stored procedure that does look something like this: CREATE FUNCTION foo() RETURNS SETOF ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-10-2008, 12:17 AM
Dennis Brakhane
 
Posts: n/a
Default Can a stored procedure that creates a temp table be declared STABLE?

Hello,

I need to write a stored procedure that does look something like this:

CREATE FUNCTION foo() RETURNS SETOF BIGINT LANGUAGE plpgsql AS $$
DECLARE
result RECORD;
BEGIN
EXECUTE 'CREATE TEMP TABLE foo (id int,...)';
-- Insert something into foo depending on contents of the database
...
FOR result IN EXECUTE 'SELECT * FROM foo' LOOP
RETURN NEXT result;
END LOOP;
EXECUTE 'DROP TABLE foo';
$$

In the documentation for CREATE FUNCTION, you will find the following
about the STABLE attribute:

>STABLE indicates that the function cannot modify the database, and

that within a single table scan
> it will consistently return the same result for the same argument values, but that its result could
> change across SQL statements.


Does that mean that the function cannot modify the database, or cannot
change the data in it?
Because the function cleary modified the database, but only
temporarily, and the result only changes when the dataset changes.

Does STABLE only tell the query optimizer that he can optimize two
simultanous calls away or does it imply some kind of write lock under
special circumstances?

To make a long question short: can I use STABLE or will I face problems?

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 11:23 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com