I am trying to use subselect in my code but it gives me an error. I have found a lot of solution but it still does not work:
Here is my code:
BEGIN;
IF (SELECT COUNT(*) FROM table1 WHERE Z = 'aaaaa') = 0
THEN
INSERT INTO table2 (X, Y) VALUES ("abc", 7)
END IF;
END;
and error:
ERROR: syntax error at or near "IF"
LINE 2: IF (SELECT COUNT(*) FROM table1 WHERE Path = 'aaaaa') = 0
^
********** Error **********
ERROR: syntax error at or near "IF"
SQL state: 42601
Character: 8
Could you help me?
DOblock or function definition. You cannot run anonymous PL/PgSQL blocks in PostgreSQL, they must be surrounded by aDOorCREATE [OR REPLACE] FUNCTIONwith aLANGUAGEclause.