# Problem with CASE statement?

**URL:** <https://community.questdb.com/t/problem-with-case-statement/757>\
**Category:** Community\
**Created:** [February 18, 2025, 8:41am UTC](https://community.questdb.com/t/problem-with-case-statement/757 "2025-02-18T08:41:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cardilloscreations](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.questdb.com/cardilloscreations/32/348_2.png) [@cardilloscreations](https://community.questdb.com/u/cardilloscreations)\
**Post date:** [February 18, 2025, 8:41am UTC](https://community.questdb.com/t/problem-with-case-statement/757/1 "2025-02-18T08:41:34Z")

</div>

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.

```auto
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.

```auto
exception in function factory:

```

Checking the logs I can see this:

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![nwoolmer](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.questdb.com/nwoolmer/32/24_2.png) [@nwoolmer](https://community.questdb.com/u/nwoolmer)\
**Post date:** [February 18, 2025, 8:45am UTC](https://community.questdb.com/t/problem-with-case-statement/757/2 "2025-02-18T08:45:28Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![nwoolmer](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.questdb.com/nwoolmer/32/24_2.png) [@nwoolmer](https://community.questdb.com/u/nwoolmer)\
**Post date:** [February 18, 2025, 11:12am UTC](https://community.questdb.com/t/problem-with-case-statement/757/3 "2025-02-18T11:12:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cardilloscreations](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.questdb.com/cardilloscreations/32/348_2.png) [@cardilloscreations](https://community.questdb.com/u/cardilloscreations)\
**Post date:** [February 19, 2025, 9:52am UTC](https://community.questdb.com/t/problem-with-case-statement/757/4 "2025-02-19T09:52:15Z")

</div>

Thanks. I opened a [GitHub issue](https://github.com/questdb/questdb/issues/5400) 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. 😃

---

<div class="post-metadata">

**Author:** ![nwoolmer](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.questdb.com/nwoolmer/32/24_2.png) [@nwoolmer](https://community.questdb.com/u/nwoolmer)\
**Post date:** [February 19, 2025, 9:52am UTC](https://community.questdb.com/t/problem-with-case-statement/757/5 "2025-02-19T09:52:42Z")

</div>

No problem! Should go into the next release.
