<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Forum PostgreSQL - Transakcje w funkcji]]></title>
		<link>https://forum.postgresql.org.pl/viewtopic.php?id=436</link>
		<description><![CDATA[Najświeższe odpowiedzi w Transakcje w funkcji.]]></description>
		<lastBuildDate>Sat, 01 May 2010 21:14:00 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Odp: Transakcje w funkcji]]></title>
			<link>https://forum.postgresql.org.pl/viewtopic.php?pid=2016#p2016</link>
			<description><![CDATA[Już mam odpowiedź, chyba że źle to robie

CREATE OR REPLACE FUNCTION funkcja1 (varchar,integer)
RETURNS boolean AS
$body$
declare
il_wierszy integer := 0;
        begin
       
             Update tbl1 set pole = '$1' where id=$2;
           GET DIAGNOSTICS il_wierszy = ROW_COUNT;
        if il_wierszy>0 then
        return true;
        else     
		return false;
        end if;
        end;
$body$
LANGUAGE 'plpgsql']]></description>
			<author><![CDATA[dummy@example.com (adamleon)]]></author>
			<pubDate>Sat, 01 May 2010 21:14:00 +0000</pubDate>
			<guid>https://forum.postgresql.org.pl/viewtopic.php?pid=2016#p2016</guid>
		</item>
		<item>
			<title><![CDATA[Odp: Transakcje w funkcji]]></title>
			<link>https://forum.postgresql.org.pl/viewtopic.php?pid=2015#p2015</link>
			<description><![CDATA[W jaki sposób sprawdzić czy nastąpiło wykonanie polecenia, jezeli zostało wykonane to funkcja powinna zwrócic true, jezeli nie to false, ponizsza funkcja zwraca true ale jak wstawic warunek zeby zwracała tez false?

CREATE OR REPLACE FUNCTION funkcja1 (varchar,integer)
RETURNS boolean AS
$body$
		begin
		
			 Update tbl1 set pole = '$1' where id=$2;
		
		return true;
		end;
$body$
LANGUAGE 'plpgsql']]></description>
			<author><![CDATA[dummy@example.com (adamleon)]]></author>
			<pubDate>Sat, 01 May 2010 19:59:01 +0000</pubDate>
			<guid>https://forum.postgresql.org.pl/viewtopic.php?pid=2015#p2015</guid>
		</item>
		<item>
			<title><![CDATA[Odp: Transakcje w funkcji]]></title>
			<link>https://forum.postgresql.org.pl/viewtopic.php?pid=2014#p2014</link>
			<description><![CDATA[No chyba nie ma sensu.]]></description>
			<author><![CDATA[dummy@example.com (rski)]]></author>
			<pubDate>Sat, 01 May 2010 19:54:44 +0000</pubDate>
			<guid>https://forum.postgresql.org.pl/viewtopic.php?pid=2014#p2014</guid>
		</item>
		<item>
			<title><![CDATA[Transakcje w funkcji]]></title>
			<link>https://forum.postgresql.org.pl/viewtopic.php?pid=2013#p2013</link>
			<description><![CDATA[Witam 
Mam taka funkcyjke:

create or replace function xw() RETURNS integer 
AS
$BODY$
	declare
	  number_of_rows integer := 0;
		begin
			
			START TRANSACTION;
			jedna lub wiele instrukcji update, delete lub insert
			COMMIT;
			GET DIAGNOSTICS number_of_rows = ROW_COUNT;
		 return number_of_rows;
		end;
$BODY$
language plpgsql;

Czy jest tutaj sens stosowania transakcji, w internecie znalazłem takie informacje, które za tym nie przemawiają:

 Is it possible to use begin, commit and rollback commands within a transaction block in  SQL function in postgre?

I guess you can  use nested blocks in side a function(BEGIN,END) but not
commit   because a SQL function  runs as a single transaction. 

He could use SAVEPOINT

if you want to break plpgsql function, use exceptions. That will cause
transaction (which in it self is the whole procedure) to be rolled
back. 


Z góry dzieki za odpowiedź
AdamP.]]></description>
			<author><![CDATA[dummy@example.com (adamleon)]]></author>
			<pubDate>Sat, 01 May 2010 11:53:39 +0000</pubDate>
			<guid>https://forum.postgresql.org.pl/viewtopic.php?pid=2013#p2013</guid>
		</item>
	</channel>
</rss>
