我是postgres的新手,我正在處理我的任務。我不得不創建一個表,只有1列和,然後我得到了此語句的pgAdmin III運行:Postgres語法錯誤在「IF」處或附近
BEGIN;
INSERT INTO mytable VALUES (1);
SAVEPOINT savepoint1;
INSERT INTO mytable VALUES (2);
ROLLBACK TO SAVEPOINT savepoint1;
INSERT INTO mytable VALUES (3);
SAVEPOINT savepoint2;
INSERT INTO mytable VALUES (4);
INSERT INTO mytable VALUES (5);
SAVEPOINT savepoint3;
SELECT * FROM mytable;
--NOTE: You need to run this IF statement as PGScript
--(button next to the normal run button)
IF (CAST ((SELECT MAX(id) FROM mytable) AS INTEGER) = 4)
BEGIN
RELEASE SAVEPOINT savepoint2;
END
ELSE
BEGIN
INSERT INTO mytable VALUES(6);
END
--Run the next steps normally
SAVEPOINT savepoint2;
INSERT INTO mytable VALUES (7);
RELEASE SAVEPOINT savepoint2;
INSERT INTO mytable VALUES (8);
ROLLBACK TO savepoint2;
COMMIT;
當我運行此我得到這個錯誤:語法錯誤或接近「IF」
我已經看一看這個38.6.2. Conditionals38.6.2. Conditionals,我不明白這一點非常好,我是否需要更改查詢有
IF (CAST ((SELECT MAX(id) FROM mytable) AS INTEGER) = 4) THEN
BEGiN
,然後當它結束我應該結束它:
END IF
爲什麼所有的錯誤都是?
您錯過了'THEN' ...這是'如果...然後...其他...'。你有'如果...... ELSE'。 –
@MarcB我試了一下,但仍然收到錯誤 –