<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Forum PostgreSQL - Reguły i rekurencja]]></title>
	<link rel="self" href="http://forum.postgresql.org.pl/extern.php?action=feed&amp;tid=535&amp;type=atom"/>
	<updated>2011-01-26T19:31:20Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.postgresql.org.pl/viewtopic.php?id=535</id>
		<entry>
			<title type="html"><![CDATA[Odp: Reguły i rekurencja]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=2370#p2370"/>
			<content type="html"><![CDATA[Dzięki. Potestuję triggery.]]></content>
			<author>
				<name><![CDATA[Rayo]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=1158</uri>
			</author>
			<updated>2011-01-26T19:31:20Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=2370#p2370</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Reguły i rekurencja]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=2369#p2369"/>
			<content type="html"><![CDATA[No niestety z tymi regułami to nie jest tak prosto. Ogólnie raczej należy się ich wystrzegać.
W tym przypadku musiałbyś do update dodać warunek
[code]
WHERE <columna>=NEW.<columna>
[/code]
ale to musisz mieć w tabeli coś co jednoznacznie identyfikuje kolumny, jakiś klucz (może u Ciebie to jest gid).
A i tak nie mam pewności czy to zawsze zadziała, takie są reguły :).]]></content>
			<author>
				<name><![CDATA[rski]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=26</uri>
			</author>
			<updated>2011-01-26T19:19:30Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=2369#p2369</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Reguły i rekurencja]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=2368#p2368"/>
			<content type="html"><![CDATA[[quote=rski]Zamień to na triggera before insert[/quote]

OK spróbuję.
Próbowałem też zostawić oryginalnego INSERTA i dodać regułę

REATE OR REPLACE RULE ins2 AS
    ON INSERT TO test004 DO  UPDATE test004 SET "Data_wprow" = now();

ale uzupełnia mi wszystkie wiersze w kolumnie "Data_wprow", a nie tylko ten "insertowany".]]></content>
			<author>
				<name><![CDATA[Rayo]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=1158</uri>
			</author>
			<updated>2011-01-26T19:14:38Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=2368#p2368</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Reguły i rekurencja]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=2367#p2367"/>
			<content type="html"><![CDATA[Zamień to na triggera before insert]]></content>
			<author>
				<name><![CDATA[rski]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=26</uri>
			</author>
			<updated>2011-01-26T18:55:49Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=2367#p2367</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Reguły i rekurencja]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=2366#p2366"/>
			<content type="html"><![CDATA[Utworzyłem regułę do tabeli, która zastępuje INSERT

CREATE OR REPLACE RULE ins AS
    ON INSERT TO test004 DO INSTEAD  INSERT INTO test004 (gid, "NazwaCiagu", "NazwaLinii", the_geom, "Wprowadzil", "Data_wprow") 
  VALUES (new.gid, new."NazwaCiagu", new."NazwaLinii", new.the_geom, "current_user"(), now());

Jednak nie da się z niej skorzystać z powodu wywołania rekurencyjnego - jeden INSERT powoduje wywołanie następnego itd.

Jak to ominąć?]]></content>
			<author>
				<name><![CDATA[Rayo]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=1158</uri>
			</author>
			<updated>2011-01-26T18:49:20Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=2366#p2366</id>
		</entry>
</feed>
