How can we help you today? How can we help you today?

Collapse CASE statements

The "Collapse CASE statements shorter than N characters" option appears to conflict with the Lists --> List items --> "Place first item on new line" option, when the first expression in a SELECT statement is a CASE expression.

When I have "Place first item on new line" set to Always and "Collapse CASE statements" unchecked, my code looks like the following:
SELECT
	CASE
		WHEN 1 = 1
		THEN 1 END AS x
   ,1 AS y

SELECT
	0 AS w
   ,CASE
		WHEN 1 = 1
		THEN 1 END AS x
   ,1 AS y

When I check "Collapse CASE statements", it turns into this:
SELECT CASE WHEN 1 = 1 THEN 1 END AS x
   ,1 AS y

SELECT
	0 AS w
   ,CASE WHEN 1 = 1 THEN 1 END AS x
   ,1 AS y

Notice that the query with the CASE expression first goes back and forth between respecting the First Line option and ignoring it.


Closing nitpick: technically it's a CASE expression, not a CASE statement...
a.higgins
0

Comments

6 comments

  • Alex B
    Hi a.higgins,

    So just to confirm and/or clarify what you actually expect would be the following:
    SELECT 
       CASE WHEN 1 = 1 THEN 1 END AS x
       ,1 AS y
    
    SELECT
       0 AS w
       ,CASE WHEN 1 = 1 THEN 1 END AS x
       ,1 AS y
    

    Is that correct?

    Kind regards,
    Alex
    Alex B
    0
  • a.higgins
    Yes, that would be correct: I would expect the "place first item on new line" setting to supersede the "Collapse CASE statements" setting.
    a.higgins
    0
  • Alex B
    Hi a.higgins,

    Righto that makes sense. I've escalated this to the developers and will let you know what they say!

    Kind regards,
    Alex
    Alex B
    0
  • David Priddle
    Hi a.higgins,

    Thanks for sending this in, I'm looking at it now!

    And you're quite right - they are definitely expressions. I'll change the text.

    Best regards,

    David
    David Priddle
    0
  • David Priddle
    Hi a.higgins,

    I've got a fix for it, so this will be in the next beta release.

    Best regards,

    David
    David Priddle
    0
  • a.higgins
    Confirmed, this now works as expected (and thanks for calling it a CASE expression, too!)
    a.higgins
    0

Add comment

Please sign in to leave a comment.