ERROR: syntax error at or near "IF"... why?

Поиск
Список
Период
Сортировка
От DaNieL
Тема ERROR: syntax error at or near "IF"... why?
Дата
Msg-id 4a0a8510-8a08-4194-ba35-1e6760e50ced@x1g2000prh.googlegroups.com
обсуждение исходный текст
Ответы Re: ERROR: syntax error at or near "IF"... why?  (Johan Nel <johan555.nel555@xsinet555.co.za>)
Re: ERROR: syntax error at or near "IF"... why?  ("Chris Spotts" <rfusca@gmail.com>)
Re: ERROR: syntax error at or near "IF"... why?  (Sam Mason <sam@samason.me.uk>)
Список pgsql-general
Hi guys, im new with postgresql, and already got my first problem..

Well, I wroted some code for understend how the transaction works,
following step by step the manual.

TO make it short, i've created 2 tables, user and movements: in the
firs one there are the name, email and credit colons, in the second
the colons from, to, import.

So, i was triyng that way:

BEGIN;
INSERT INTO movements (from, to, import) VALUES ('mary', 'steve',
600);
UPDATE users SET credit = credit - 600 WHERE name = 'mary';
UPDATE users SET credit = credit + 600 WHERE name = 'steve';
--here comes the problem!
IF (SELECT credit FROM users WHERE name = 'mary') < 0 THEN
 ROLLBACK;
END IF
COMMIT;

i always get the error
ERROR:  syntax error at or near "IF"

Where am i mistaken?

p.s: dont focus on the example functionality, its just a trial for me
to understand the transactions.. and now, the IF clause...

В списке pgsql-general по дате отправления:

Предыдущее
От: Dave Page
Дата:
Сообщение: Re: Any way to execute ad-hoc pl/pgsql?
Следующее
От: Raymond O'Donnell
Дата:
Сообщение: Re: Do TEMP Tables have an OID? Can this be a problem if used too frequently?