<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Forum PostgreSQL - Przechwycenie nazwy pola]]></title>
	<link rel="self" href="http://forum.postgresql.org.pl/extern.php?action=feed&amp;tid=607&amp;type=atom"/>
	<updated>2011-07-06T09:06:15Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.postgresql.org.pl/viewtopic.php?id=607</id>
		<entry>
			<title type="html"><![CDATA[Odp: Przechwycenie nazwy pola]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=2587#p2587"/>
			<content type="html"><![CDATA[[quote=Rogo]Witam

Proponuje zapoznanie się z tą konstrukcją :
[url]http://www.postgresql.org/docs/current/static/plpgsql-control-structures.html#PLPGSQL-ERROR-TRAPPING[/url]

oraz z tablicą błędów:
[url]http://www.postgresql.org/docs/8.3/static/errcodes-appendix.html[/url][/quote]


Już tam byłem, zrobiłem tak, ale nic to nie daje, nie wiem jaki wyjątek przechwycić

CREATE OR REPLACE FUNCTION "schemat_zakupy"."faktualizuj_dane_klienta22" (
  "zm_pole1" varchar
)
RETURNS boolean AS
$body$
  begin

       UPDATE schemat_zakupy.tab_klienci set  pole1=zm_pole1;
                            
       return TRUE;

        EXCEPTION
        WHEN string_data_length_mismatch THEN
            RAISE NOTICE 'Za duzo';
            RETURN false;
         end;
$body$
LANGUAGE 'plpgsql'
VOLATILE
CALLED ON NULL INPUT
SECURITY DEFINER
COST 100;

jeszcze pytanie, w jaki sposób uzyskać numer błędu np:

 EXCEPTION
        WHEN string_data_length_mismatch THEN
            RAISE NOTICE 'Za duzo';
          else return "numer_bledu lub nazwe bledu"]]></content>
			<author>
				<name><![CDATA[adamleon]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=873</uri>
			</author>
			<updated>2011-07-06T09:06:15Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=2587#p2587</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Przechwycenie nazwy pola]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=2585#p2585"/>
			<content type="html"><![CDATA[Ale do wyciągania nazwy kolumny, która spowodowała wujątek chyba będziesz musiał napisać jakąś własną funkcję.]]></content>
			<author>
				<name><![CDATA[rski]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=26</uri>
			</author>
			<updated>2011-07-05T20:08:26Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=2585#p2585</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Przechwycenie nazwy pola]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=2584#p2584"/>
			<content type="html"><![CDATA[Witam

Proponuje zapoznanie się z tą konstrukcją :
[url]http://www.postgresql.org/docs/current/static/plpgsql-control-structures.html#PLPGSQL-ERROR-TRAPPING[/url]

oraz z tablicą błędów:
[url]http://www.postgresql.org/docs/8.3/static/errcodes-appendix.html[/url]]]></content>
			<author>
				<name><![CDATA[Rogo]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=1161</uri>
			</author>
			<updated>2011-07-05T17:20:44Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=2584#p2584</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Przechwycenie nazwy pola]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=2581#p2581"/>
			<content type="html"><![CDATA[Witam
Aktualizuję i dodaję dane do tabeli za pomocą funkcji. Wszystko jest ok, tylko mam problem kiedy podaje dłuższy tekst niż rozmiar pola. Dostaję taki błąd "ERROR:  value too long for type character varying(50)". Chciałbym w funkcji jeżeli się da przechwycić taki wyjątek, podstawić do nie go własny komunikat i nazwę pola w którym jest ten błąd.
coś takiego:

EXCEPTION
        WHEN >>za_za_duzo_danych<< THEN
            RAISE NOTICE 'Zbyt dużo danych w polu' >> tu nazwa pola które jest zbyt małe zwrócone przez system<<;
            RETURN 0;

Z góry dzięki za pomoc
AdamP.]]></content>
			<author>
				<name><![CDATA[adamleon]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=873</uri>
			</author>
			<updated>2011-07-02T07:00:33Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=2581#p2581</id>
		</entry>
</feed>
