Skip to content

Failed to parse CASE-ELSE clause with v1.18.0 #2237

Closed
@nozaq

Description

@nozaq

Version

Other

What happened?

sqlc fails to parse the query when CASE expression has ELSE clause and its value is a constant.

The example query is as below.

SELECT CASE 
  WHEN id = $1 THEN 'foo'
  ELSE 'bar'
END is_one
FROM foo

sqlc fails to parse this query with the error: parse table name: unexpected node type: *ast.Null.

Relevant log output

parse table name: unexpected node type: *ast.Null

Database schema

CREATE TABLE foo (id text not null);

SQL queries

SELECT CASE 
  WHEN id = $1 THEN 'foo'
  ELSE 'bar'
END is_one
FROM foo

Configuration

{
  "version": "1",
  "packages": [
    {
      "path": "go",
      "engine": "postgresql",
      "sql_package": "pgx/v5",
      "name": "querytest",
      "schema": "query.sql",
      "queries": "query.sql"
    }
  ]
}

Playground URL

https://play.sqlc.dev/p/968c7c9391b3aa32774930ab1d635c081c72d6f23bdf2db7ff9c94dfba0f178a

What operating system are you using?

macOS

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions