From fa1678feb2fc168fc01bc1690a6b9fbe3fc507ae Mon Sep 17 00:00:00 2001 From: ygrek Date: Sat, 16 Jul 2016 17:27:58 -0700 Subject: [PATCH] sql: support IF in SELECT (fix #39) --- lib/sql_parser.mly | 1 + test/bug39_select_if.sql | 2 ++ test/out/bug39_select_if.xml | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+) create mode 100644 test/bug39_select_if.sql create mode 100644 test/out/bug39_select_if.xml diff --git a/lib/sql_parser.mly b/lib/sql_parser.mly index 2b90ed9..f987a7b 100644 --- a/lib/sql_parser.mly +++ b/lib/sql_parser.mly @@ -347,6 +347,7 @@ expr: let v_args = maybe Prelude.identity e1 @ List.flatten branches @ maybe Prelude.identity e2 in Fun (F (Var 1, t_args), v_args) } + | IF LPAREN e1=expr COMMA e2=expr COMMA e3=expr RPAREN { Fun (F (Var 0, [Typ Bool;Var 0;Var 0]), [e1;e2;e3]) } case_branch: WHEN e1=expr THEN e2=expr { [e1;e2] } like: LIKE | LIKE_OP { } diff --git a/test/bug39_select_if.sql b/test/bug39_select_if.sql new file mode 100644 index 0000000..7c2f85f --- /dev/null +++ b/test/bug39_select_if.sql @@ -0,0 +1,2 @@ +create table profiles (id int, host text, today_count int); +select id, host, if(@x < now() - interval 1 day, 0, today_count) from profiles; diff --git a/test/out/bug39_select_if.xml b/test/out/bug39_select_if.xml new file mode 100644 index 0000000..beeafe2 --- /dev/null +++ b/test/out/bug39_select_if.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + -- 2.11.4.GIT