Skip to content

CASE expressions aren't being parsed/read #92

Description

@eullerpereira94

Queries using conditional expressions like NULLIF and COALESCE generate proper Go code. Meanwhile, the CASE conditional expression does not. The generated go code doesn't generate an additional field in the result struct, making the Scan fail each time is called. I will try to investigate this issue later on the week and try to provide a fix. The following query can be used to reproduce the observed behavior:

SELECT
  id,
  CASE 
    WHEN id = $1 THEN true
    ELSE false
  END is_one
FROM
  author;

Activity

  1. eullerpereira94 commented on Sep 30, 2019

    @eullerpereira94
    ContributorAuthor

    Actually, NULLIF also smells bad. When using it in a query, the Go struct is generated with a field with the bool type, instead of a Null* type. The following query:

    SELECT
      NULLIF(id, $1) restricted_id
    FROM
      author

    Will generate the following strange code:

    type FuncResult struct {
      RestrictedID bool `json:"restricted_id"`
    }

    When correct type would be sql.NullInt64.

  2. kyleconroy commented on Oct 3, 2019

    @kyleconroy
    Collaborator

    Yeah, these are indeed two problems. I hope to get a chance to look at them this weekend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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