D
D
Dmitry Volkhontsev2016-09-26 20:17:29
PostgreSQL
Dmitry Volkhontsev, 2016-09-26 20:17:29

How to write SQL query with CASE?

Good day.
How to write a query like this:

SELECT CASE WHEN a=0 THEN
          UPDATE table SET b=0
          my_function()
    WHEN a=1
          UPDATE table SET b=1
          my_function()
   ELSE my_function()
END;

On Mysql, this worked, although IF was used instead of CASE. And postgresql throws the error "syntax error (example position: 'table')"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
romy4, 2016-09-26
@DarkDD

don't forget about ;
but in your case you can't use update inside select. it's against the rules. Either write storage, or some other option.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question