<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Forum PostgreSQL - sql:trigger.sql:13: BŁĄD:  missing "THEN" at end of SQL expression]]></title>
	<link rel="self" href="http://forum.postgresql.org.pl/extern.php?action=feed&amp;tid=376&amp;type=atom"/>
	<updated>2010-01-18T22:11:34Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.postgresql.org.pl/viewtopic.php?id=376</id>
		<entry>
			<title type="html"><![CDATA[Odp: sql:trigger.sql:13: BŁĄD:  missing "THEN" at end of SQL expression]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=1722#p1722"/>
			<content type="html"><![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 :)]]></content>
			<author>
				<name><![CDATA[peiner]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=1041</uri>
			</author>
			<updated>2010-01-18T22:11:34Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=1722#p1722</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: sql:trigger.sql:13: BŁĄD:  missing "THEN" at end of SQL expression]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=1721#p1721"/>
			<content type="html"><![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]]></content>
			<author>
				<name><![CDATA[rski]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=26</uri>
			</author>
			<updated>2010-01-18T22:03:36Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=1721#p1721</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: sql:trigger.sql:13: BŁĄD:  missing "THEN" at end of SQL expression]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=1720#p1720"/>
			<content type="html"><![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]]]></content>
			<author>
				<name><![CDATA[peiner]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=1041</uri>
			</author>
			<updated>2010-01-18T21:55:10Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=1720#p1720</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: sql:trigger.sql:13: BŁĄD:  missing "THEN" at end of SQL expression]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=1718#p1718"/>
			<content type="html"><![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.]]></content>
			<author>
				<name><![CDATA[rski]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=26</uri>
			</author>
			<updated>2010-01-18T21:21:41Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=1718#p1718</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: sql:trigger.sql:13: BŁĄD:  missing "THEN" at end of SQL expression]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=1715#p1715"/>
			<content type="html"><![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]]]></content>
			<author>
				<name><![CDATA[peiner]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=1041</uri>
			</author>
			<updated>2010-01-18T21:12:02Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=1715#p1715</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: sql:trigger.sql:13: BŁĄD:  missing "THEN" at end of SQL expression]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=1714#p1714"/>
			<content type="html"><![CDATA[Usuń ";" który jest na końcu linijki z IF'em]]></content>
			<author>
				<name><![CDATA[rski]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=26</uri>
			</author>
			<updated>2010-01-18T21:09:20Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=1714#p1714</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[sql:trigger.sql:13: BŁĄD:  missing "THEN" at end of SQL expression]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=1713#p1713"/>
			<content type="html"><![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 ?]]></content>
			<author>
				<name><![CDATA[peiner]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=1041</uri>
			</author>
			<updated>2010-01-18T21:07:11Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=1713#p1713</id>
		</entry>
</feed>
