0

I have a query like below:

if extract(dow from current_date)=1 then
select * form dev
else
select * from dev1
end if 

Error:

ERROR: syntax error at or near "if" LINE 1: if extract(dow from current_date)=1 then

How can I perform ddl and dml operation in single execution?

Ralf Stubner
  • 26,263
  • 3
  • 40
  • 75
  • There is no `IF` in SQL. Try rewriting it into one or two `WHERE` clauses. – joop Jun 01 '18 at 09:44
  • 1
    You seem to think SQL is a programming language. Maybe have a look at PL/pgSQL: https://www.postgresql.org/docs/current/static/plpgsql-control-structures.html – moooeeeep Jun 01 '18 at 09:46
  • Related: https://stackoverflow.com/q/11299037/1025391 – moooeeeep Jun 01 '18 at 09:49
  • This seems like a rather strange request and might indicate a badly designed data model. –  Jun 01 '18 at 10:02
  • Use conditional expression provided by postgres: https://www.postgresql.org/docs/7.4/static/functions-conditional.html – RKT Jun 01 '18 at 11:05

0 Answers0