GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — compiler: a scalar subquery's column is nullable by ken-talltree-io · Pull Request #4654 · sqlc-dev/sqlc

Conversation

@ken-talltree-io

@ken-talltree-io ken-talltree-io commented Oct 24, 2026

Copy link
Copy Markdown

A scalar subquery yields NULL when it matches no row, but the legacy analyzer gave its column the nullability of the column it selects, so (select r.id from reviews r where r.book_id = b.id limit 1) came out non-null. This makes it nullable unless the subquery always yields exactly one row: an aggregate with no GROUP BY, HAVING or LIMIT ((select count(*) …) stays non-null), or a SELECT with no FROM.

Fixes #4262. The new nullable_scalar_subquery fixture covers a subquery through a view and inline; it fails without the change in both the base and managed-db contexts. With PostgreSQL available, every TestReplay case passes, and no existing expected output changes.

CASE … ELSE NULL::type has the same problem on this path; I've left it to #3739, which reworks CASE (see my comment there about column-reference results).

🤖 Generated with Claude Code

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ken-talltree-io @claude
compiler: a scalar subquery's column is nullable
0bb6a6e
A scalar subquery yields NULL when it matches no row, so its column is nullable
unless the subquery always yields one row: an aggregate with no GROUP BY,
HAVING or LIMIT, or a SELECT with no FROM.

Fixes sqlc-dev#4262

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

SQLC does not infer nullability for subqueries in view SELECT

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@ken-talltree-io
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.