1

I have a MariaDB query like this:

select id, column_get(params, 'Variant' as char) as variant 
from runs 
where column_get(params, 'Variant' as char) in ('Whatever', 'Wherever');

Is there a way to not have to repeat the whole column_get() bit twice?

Edit: Fixed tautological example.

8
  • If so use WITH clause. But it may be less effective. Moreover, I think the expression is written twice, but calculated once. So if you solve your task you will save a lot of bytes only.
    – Akina
    Oct 16 '18 at 13:42
  • Yeah I'm not worried about the calculation - seems to be plenty fast enough. Just the repetitiveness. Can you explain the WITH clause? I can't see how it would help.
    – Timmmm
    Oct 16 '18 at 13:58
  • 1
    WITH cte AS (select id, column_get(params, 'Variant' as char) as variant from runs) SELECT * FROM cte WHERE variant IN ('Whatever', 'Wherever');
    – Akina
    Oct 16 '18 at 19:43
  • Ah I see. Will that have the same performance characteristics?
    – Timmmm
    Oct 17 '18 at 8:20
  • I don't know (not use MariaDB at all) - test it.
    – Akina
    Oct 17 '18 at 8:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.