Skip to content

COALESCE returns a NullInt instead of an int in JOIN #1096

Description

@kevinburke1

If I have COALESCE(connected_clients, 0), sqlc generates a NullInt64 for this instead of an int64. This is a regression from 1.7.0. (At least I can fix it by casting to the right value).

Activity

  1. added this to the v1.9.0 milestone on Aug 4, 2021
  2. kyleconroy commented on Aug 11, 2021

    @kyleconroy
    Collaborator

    @kevinburkemeter What is the type of connected_clients?

  3. kevinburke1 commented on Aug 11, 2021

    @kevinburke1
    ContributorAuthor

    Here are some examples

    SELECT stats.*,
    COALESCE(device_query.device_count, 0) AS device_count
    FROM stats
    LEFT JOIN device_query ON device_query.controller = stats.controller;
    

    Produces this diff when run on tip

    @@ -89,7 +90,7 @@ type GetControllerStatsAndDeviceCountRow struct {
     	DownloadBytes      float64
     	BandwidthUpdatedAt time.Time
     	LastRebootedAt     time.Time
    -	DeviceCount        int64
    +	DeviceCount        sql.NullInt64
     }
  4. kevinburke1 commented on Aug 11, 2021

    @kevinburke1
    ContributorAuthor

    even simpler

    CREATE TABLE foo(id bigserial primary key);
    CREATE TABLE bar(id bigserial primary key);
    SELECT foo.*,
    COALESCE(bar.id, 0) AS device_count
    FROM foo
    LEFT JOIN bar ON foo.id = bar.id;
    
  5. changed the title [-]COALESCE returns a NullInt instead of an int[/-] [+]COALESCE returns a NullInt instead of an int in JOIN[/+] on Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions