Problem with CASE statement?

Is this a known problem or something? I’m trying to perform a very simple query with a CASE statement and I get an error. I even dumbed it down to the simplest possible query similar to what’s shown in the documentation and I still get an error.

SELECT
  id,
  CASE
      WHEN status = 1 THEN 'ACTIVE'
  END as status
FROM
  nt_product;

When trying to do this in the web console, I get the following error with a red dot on the CASE line.

exception in function factory:

Checking the logs I can see this:

Feb 17 22:26:14 10228 questdb[787]: 2025-02-17T21:26:14.724534Z E i.q.g.FunctionParser exception in function factory:
Feb 17 22:26:14 10228 questdb[787]: java.lang.UnsupportedOperationException
Feb 17 22:26:14 10228 questdb[787]:         at io.questdb.griffin.engine.functions.IntFunction.getByte(IntFunction.java:55)
Feb 17 22:26:14 10228 questdb[787]:         at io.questdb.griffin.engine.functions.conditional.SwitchFunctionFactory.getByte(SwitchFunctionFactory.java:174)
Feb 17 22:26:14 10228 questdb[787]:         at io.questdb.griffin.engine.functions.conditional.SwitchFunctionFactory.getIntKeyedFunction(SwitchFunctionFactory.java:420)
Feb 17 22:26:14 10228 questdb[787]:         at io.questdb.griffin.engine.functions.conditional.SwitchFunctionFactory.newInstance(SwitchFunctionFactory.java:136)

Looks like an unimplemented branch, these slip through from time to time.

I can test in a bit, but a cast should fix it for now, i.e. WHEN cast(status as int) = 1 ...

Will raise a PR to fix it. Thanks for the report!

PR here: fix(sql): exception thrown when comparing byte column to int literal in case statement by nwoolmer · Pull Request #5401 · questdb/questdb · GitHub

Thanks. I opened a GitHub issue with more details also, which I think you saw and referenced already in the PR. I couldn’t post while waiting for this to be approved, but the CAST was a valid workaround. Thanks for putting up the PR also. :smiley:

No problem! Should go into the next release.

1 Like