2 messages in com.mysql.lists.mysqlCASE WHEN .. THEN .. ELSE .. END| From | Sent On | Attachments |
|---|---|---|
| Alexander I. Barkov | 11 Oct 1999 08:51 | |
| Tonu Samuel | 11 Oct 1999 11:59 |
| Subject: | CASE WHEN .. THEN .. ELSE .. END![]() |
|---|---|
| From: | Alexander I. Barkov (ba...@titan.izhcom.ru) |
| Date: | 10/11/1999 08:51:58 AM |
| List: | com.mysql.lists.mysql |
Hi, MySQLers!
I have very easy implemented CASE in MySQL-3.22.27
According to ANSI SQL there is this structure:
CASE WHEN <boolean expression> THEN <expression1> ELSE <expression2> END
I have added only two these in sql_yacc.yy at line 1196:
| CASE WHEN expr THEN expr ELSE expr END { $$= new Item_func_if($3,$5,$7); }
and made all required changes in all related files.
Now I can do this:
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 to server version: 3.22.27
Type 'help' for help.
mysql> select case when 1<2 then 1 else 2 end; +---------------------------------+ | case when 1<2 then 1 else 2 end | +---------------------------------+ | 1 | +---------------------------------+ 1 row in set (0.00 sec)
mysql> select case when 1>2 then 1 else 2 end; +---------------------------------+ | case when 1>2 then 1 else 2 end | +---------------------------------+ | 2 | +---------------------------------+ 1 row in set (0.01 sec)
Or more complex sample: mysql> select case when 1>2 then case when 3>4 then 4 else 5 end else 2 end; +---------------------------------------------------------------+ | case when 1>2 then case when 3>4 then 4 else 5 end else 2 end | +---------------------------------------------------------------+ | 2 | +---------------------------------------------------------------+ 1 row in set (0.00 sec)
mysql>
The question to developers. Could it be included in next MySQL releases?
Thanks.
--- Alexander Barkov IZHCOM, Izhevsk email: ba...@izhcom.ru | http://www.izhcom.ru Phone: +7 (3412) 51-55-45 | Fax: +7 (3412) 78-70-10




