Skip to content

Blank lines between common table expressions (CTEs) misreported as syntax error #372

Closed
@aleclarson

Description

@aleclarson

I assume this has to do with how statement splitting is implemented.

The SQL formatter I use likes to put blank lines between CTEs.

WITH users_cte AS (
  SELECT
    id,
    email
  FROM account
  WHERE tier = 'Pro'
),

active_sessions_cte AS (
  SELECT
    accountid,
    count(*) AS session_count
  FROM session
  WHERE expiresat > current_timestamp
  GROUP BY accountid
)

SELECT
  u.id,
  u.email,
  coalesce(s.session_count, 0) AS active_sessions
FROM users_cte AS u
LEFT JOIN active_sessions_cte AS s ON u.id = s.accountid
ORDER BY active_sessions DESC;

Output

path/to/example.sql:7:3 syntax ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  × Expected Ident
  
     5 │   FROM account
     6 │   WHERE tier = 'Pro'
   > 7 │ ),
       │   
   > 8 │ 
   > 9 │ active_sessions_cte AS (
       │ 
    10 │   SELECT
    11 │     accountid,
  

path/to/example.sql:7:3 syntax ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  × Expected As
  
     5 │   FROM account
     6 │   WHERE tier = 'Pro'
   > 7 │ ),
       │   
   > 8 │ 
   > 9 │ active_sessions_cte AS (
       │ 
    10 │   SELECT
    11 │     accountid,
  

path/to/example.sql:7:3 syntax ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  × Expected Ascii40
  
     5 │   FROM account
     6 │   WHERE tier = 'Pro'
   > 7 │ ),
       │   
   > 8 │ 
   > 9 │ active_sessions_cte AS (
       │ 
    10 │   SELECT
    11 │     accountid,
  

Checked 1 file in 37ms. No fixes applied.
Found 3 errors.
check ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  × Some errors were emitted while running checks.
  

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions