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

From: "Chris Spotts" <rfusca(at)gmail(dot)com>
To: "'DaNieL'" <daniele(dot)pignedoli(at)gmail(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: ERROR: syntax error at or near "IF"... why?
Date: 2009-05-01 11:12:31
Message-ID: EF74469339F84A6789BF79D6732FBB9D@tcore.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Could if be referencing the second IF..the one in your "END IF" that doesn't
have a semicolon after it...?

-----Original Message-----
From: pgsql-general-owner(at)postgresql(dot)org
[mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of DaNieL
Sent: Wednesday, April 29, 2009 9:54 AM
To: pgsql-general(at)postgresql(dot)org
Subject: [GENERAL] ERROR: syntax error at or near "IF"... why?

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...

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jasen Betts 2009-05-01 11:12:38 Re: Export Data from one DB and Import into a new DB
Previous Message Jasen Betts 2009-05-01 11:05:29 Re: Connecting to a postgreSQL database with windows CE over wi-fi; failing gracefully