<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Forum PostgreSQL - sql:trigger.sql:13: BŁĄD:  missing "THEN" at end of SQL expression]]></title>
		<link>https://forum.postgresql.org.pl/viewtopic.php?id=376</link>
		<description><![CDATA[Najświeższe odpowiedzi w sql:trigger.sql:13: BŁĄD:  missing "THEN" at end of SQL expression.]]></description>
		<lastBuildDate>Mon, 18 Jan 2010 22:11:34 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Odp: sql:trigger.sql:13: BŁĄD:  missing "THEN" at end of SQL expression]]></title>
			<link>https://forum.postgresql.org.pl/viewtopic.php?pid=1722#p1722</link>
			<description><![CDATA[[code]create function term() 
returns trigger as '
DECLARE
zmienna integer;
BEGIN
select count(data) into zmienna from rezerwacja_samochodu WHERE data=new.data and godz=new.godz AND nr_rejestr=new.nr_rejestr group by data;
if (zmienna>1)
then
raise notice ''ten termin jest juz zarezerwowany'';
delete from rezerwacja_samochodu where nr_rez=new.nr_rez;
return null;
end if;
return null;
END;'
LANGUAGE 'plpgsql';

CREATE TRIGGER przyklad AFTER INSERT ON rezerwacja_samochodu FOR EACH ROW EXECUTE PROCEDURE term();
[/code]
Oto ostateczny kod, teraz już działa. Dziękuję Ci [b]rski[/b] za pomoc i pozdrawiam :)]]></description>
			<author><![CDATA[dummy@example.com (peiner)]]></author>
			<pubDate>Mon, 18 Jan 2010 22:11:34 +0000</pubDate>
			<guid>https://forum.postgresql.org.pl/viewtopic.php?pid=1722#p1722</guid>
		</item>
		<item>
			<title><![CDATA[Odp: sql:trigger.sql:13: BŁĄD:  missing "THEN" at end of SQL expression]]></title>
			<link>https://forum.postgresql.org.pl/viewtopic.php?pid=1721#p1721</link>
			<description><![CDATA[[quote]
mozesz ten count(...) wstawic do zmiennej

[code]
select count(data) into zmienna from ....
[/code]
i potem zrobic IF ale z ta zmienna.
[/quote]

?! chyba nie doczytałeś :) Napisałem Ci jak masz wpisać wartośc do zmiennej: SELECT ... INTO]]></description>
			<author><![CDATA[dummy@example.com (rski)]]></author>
			<pubDate>Mon, 18 Jan 2010 22:03:36 +0000</pubDate>
			<guid>https://forum.postgresql.org.pl/viewtopic.php?pid=1721#p1721</guid>
		</item>
		<item>
			<title><![CDATA[Odp: sql:trigger.sql:13: BŁĄD:  missing "THEN" at end of SQL expression]]></title>
			<link>https://forum.postgresql.org.pl/viewtopic.php?pid=1720#p1720</link>
			<description><![CDATA[[code]DECLARE
zmienna int:=(count(data) FROM rezerwacja_samochodu WHERE data=new.data and godz=new.godz AND nr_rejestr=new.nr_rejestr group by data);
BEGIN
if (zmienna>1)[/code]

wywala

[code]psql:trigger.sql:14: BŁĄD:  błąd składni w lub blisko "FROM"
LINE 1: SELECT (count(data) FROM rezerwacja_samochodu WHERE data= $1...
                            ^
QUERY:  SELECT (count(data) FROM rezerwacja_samochodu WHERE data= $1  and godz= $2  AND nr_rejestr= $3  group by data)
CONTEXT:  SQL statement in PL/PgSQL function "term" near line 2
psql:trigger.sql:16: BŁĄD:  funkcja term() nie istnieje
[/code]]]></description>
			<author><![CDATA[dummy@example.com (peiner)]]></author>
			<pubDate>Mon, 18 Jan 2010 21:55:10 +0000</pubDate>
			<guid>https://forum.postgresql.org.pl/viewtopic.php?pid=1720#p1720</guid>
		</item>
		<item>
			<title><![CDATA[Odp: sql:trigger.sql:13: BŁĄD:  missing "THEN" at end of SQL expression]]></title>
			<link>https://forum.postgresql.org.pl/viewtopic.php?pid=1718#p1718</link>
			<description><![CDATA[A no fakt, tak sie nie da.
[quote]
IF    ((count(data) from rezerwacja_samochodu where data=new.data and godz=new.godz and         nr_rejestr=new.nr_rejestr group by data)>1);
THEN

[/quote]
mozesz ten count(...) wstawic do zmiennej

[code]
select count(data) into zmienna from ....
[/code]
i potem zrobic IF ale z ta zmienna.]]></description>
			<author><![CDATA[dummy@example.com (rski)]]></author>
			<pubDate>Mon, 18 Jan 2010 21:21:41 +0000</pubDate>
			<guid>https://forum.postgresql.org.pl/viewtopic.php?pid=1718#p1718</guid>
		</item>
		<item>
			<title><![CDATA[Odp: sql:trigger.sql:13: BŁĄD:  missing "THEN" at end of SQL expression]]></title>
			<link>https://forum.postgresql.org.pl/viewtopic.php?pid=1715#p1715</link>
			<description><![CDATA[[code]psql:trigger.sql:16: BŁĄD:  błąd składni w lub blisko "from"
LINE 1: SELECT ((count(data) from rezerwacja_samochodu where data= $...
                             ^
QUERY:  SELECT ((count(data) from rezerwacja_samochodu where data= $1  and godz= $2  and nr_rejestr= $3  group by data)>1)
CONTEXT:  SQL statement in PL/PgSQL function "term" near line 5
psql:trigger.sql:18: BŁĄD:  funkcja term() nie istnieje
[/code]]]></description>
			<author><![CDATA[dummy@example.com (peiner)]]></author>
			<pubDate>Mon, 18 Jan 2010 21:12:02 +0000</pubDate>
			<guid>https://forum.postgresql.org.pl/viewtopic.php?pid=1715#p1715</guid>
		</item>
		<item>
			<title><![CDATA[Odp: sql:trigger.sql:13: BŁĄD:  missing "THEN" at end of SQL expression]]></title>
			<link>https://forum.postgresql.org.pl/viewtopic.php?pid=1714#p1714</link>
			<description><![CDATA[Usuń ";" który jest na końcu linijki z IF'em]]></description>
			<author><![CDATA[dummy@example.com (rski)]]></author>
			<pubDate>Mon, 18 Jan 2010 21:09:20 +0000</pubDate>
			<guid>https://forum.postgresql.org.pl/viewtopic.php?pid=1714#p1714</guid>
		</item>
		<item>
			<title><![CDATA[sql:trigger.sql:13: BŁĄD:  missing "THEN" at end of SQL expression]]></title>
			<link>https://forum.postgresql.org.pl/viewtopic.php?pid=1713#p1713</link>
			<description><![CDATA[[code]
create function term()
returns trigger as '
BEGIN
IF    ((count(data) from rezerwacja_samochodu where data=new.data and godz=new.godz and         nr_rejestr=new.nr_rejestr group by data)>1);
THEN
    raise notice ''ten termin jest juz zarezerwowany'';
    delete from rezerwacja_samochodu where nr_rez=new.nr_rez;
    return null;
ELSE    return null;
END IF;
END;
' 
LANGUAGE 'plpgsql';
CREATE TRIGGER przyklad AFTER INSERT ON rezerwacja_samochodu FOR EACH ROW EXECUTE PROCEDURE term();
[/code]
Wywala mi taki błąd:

[code]psql:trigger.sql:13: BŁĄD:  missing "THEN" at end of SQL expression
CONTEXT:  compile of PL/pgSQL function "term" near line 2
psql:trigger.sql:14: BŁĄD:  funkcja term() nie istnieje[/code]

Skąd się to pierze ?]]></description>
			<author><![CDATA[dummy@example.com (peiner)]]></author>
			<pubDate>Mon, 18 Jan 2010 21:07:11 +0000</pubDate>
			<guid>https://forum.postgresql.org.pl/viewtopic.php?pid=1713#p1713</guid>
		</item>
	</channel>
</rss>
