Hi guys, I'm new with postgresql, and already have my first problem..
Well, I wrote some code to understand how transactions work, following step by step the manual.
To make it short, I've created 2 tables, user and movements: in the first one there are the name, email and credit columns, in the second the columns 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: Don't focus on the example functionality, its just a trial for me to understand the transactions.. and now, the IF clause...