PostgreSQL IF-THEN-ELSE control structure
Why do I always get the following error from Postgres? syntax error at or near "IF" I read PostgreSQL: Documentation: 8.3: Control Structures . First I tried to execute a difficult query (with subquery), but then I tried to execute a simple one like this: IF 2 <> 0 THEN select * from users; END IF; The error is still the same. What am I doing wrong? IF 2 <> 0 THEN select * from users; END IF; You cannot use PL/pgSQL statements outside plpgsql functions. And if this fragment is from plpgsql function, then it is nonsense too. You cannot directly return result of query like T-SQL does. CREATE OR