How to create alias like Mysql's IF function?

137 views
Skip to first unread message

Strong cat

unread,
Aug 2, 2018, 7:46:34 AM8/2/18
to H2 Database

When I use spring boot framework to write spock testing,this is my appliction.yml setting
datasource: password: sa url: jdbc:h2:mem:agile_service;DB_CLOSE_DELAY=-1;MODE=Mysql;TRACE_LEVEL_SYSTEM_OUT=2; username: sa
image

and then I get a error :
image
So I read h2 document to solve this problem,then I create a ALIAS like this:
image

this is ifFunction:
image

So far I solve this problem.But I discover param、paramTwo and return value may be not Boolean like this:
IF(a=1,"a","b")
I change param、paramTwo and return value to Object ,but it didn't work and return a conver error
image

what should I do?

Noel Grandin

unread,
Aug 2, 2018, 8:29:20 AM8/2/18
to h2-da...@googlegroups.com

Unfortunately, creating an ALIAS will not work because IF is a keyword, and we don't allow keywords to be overriden by
user defined functions.

I suggest that you instead use CASE .. WHEN

http://h2database.com/html/grammar.html#case_when
https://dev.mysql.com/doc/refman/5.7/en/control-flow-functions.html#operator_case

which both MySQL and H2 supports.

丁丁煌

unread,
Aug 2, 2018, 2:28:31 PM8/2/18
to h2-da...@googlegroups.com
Thanks for you answer.But If is a key word.Why it show me a error Which If is not function.Now I use case when to solve problem.

--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to h2-database...@googlegroups.com.
To post to this group, send email to h2-da...@googlegroups.com.
Visit this group at https://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages