Unix Technical Forum

Transaction in the funtions

This is a discussion on Transaction in the funtions within the pgsql Novice forums, part of the PostgreSQL category; --> Hello all !! Can anyone help me please ?? I would like to get the execution of each the ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Novice

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008, 10:51 PM
Vladimir Calmic
 
Posts: n/a
Default Transaction in the funtions

Hello all !!

Can anyone help me please ?? I would like to get
the execution of each the statement in the LOOP ( in the function
change_owner() below) each in its own transaction.

the construction like the folowing errors out with
ERROR: syntax error at or near "LOOP"

LOOP
BEGIN;
PERFORM change_schema_owner( sch_rec.nspname );
COMMIT;
END LOOP;

getting same errors when tried to start the transaction into the function
change_schema_owner()
tried something similar to
BEGIN
BEGIN;
EXECUTE 'ALTER SCHEMA ' ||sch_name || ' OWNER TO new_role' ;
COMMIT;
RETURN ;
END;

called SET TRANSACTION ISOLATION LEVEL SERIALIZABLE before the calls ..
but looks like all the LOOP calls are bieng done in one transaction since I am
getting an error like :

ERROR: out of shared memory
HINT: You may need to increase max_locks_per_transaction.
CONTEXT: SQL statement "ALTER TABLE "test"."test_ages" OWNER TO "test""
PL/pgSQL function "change_schema_owner" line 24 at execute statement



-- functions I am using for that

CREATE OR REPLACE FUNCTION owner_migration()
...
$BODY$
DECLARE
sch_rec RECORD;
BEGIN
FOR sch_rec IN SELECT * FROM pg_catalog.pg_namespace
LEFT JOIN pg_catalog.pg_user ON
pg_user.usesysid=pg_namespace.nspowner
WHERE pg_user.usename = 'test'
LOOP
PERFORM change_schema_owner( sch_rec.nspname );
END LOOP;
RETURN ;
END;

CREATE OR REPLACE FUNCTION change_schema_owner(sch_name character varying)
....
....
BEGIN
-- here I would like to have a transaction and commit it on return
EXECUTE 'ALTER SCHEMA ' ||sch_name || ' OWNER TO new_role' ;
{ statements to change owner for all the objects in the schema }

RETURN ;
END;



-----------------------------------
Vladimir Calmic
Systems Analyst
OPTIMUM-WEB
http://www.optimum-web.com
+373 22 571458
+373 79 573313 (mobile)

---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate

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 12:12 PM.


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