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 — Missing sqlc.arg in SQL UPDATE query with EXISTS subquery · Issue #4512 · sqlc-dev/sqlc

Missing sqlc.arg in SQL UPDATE query with EXISTS subquery #4512

New issue
Copy link
New issue
Copy link
Open
Open
Missing sqlc.arg in SQL UPDATE query with EXISTS subquery#4512
Copy link
Labels
bugSomething isn't workingSomething isn't working

Description

@paulkoehlerdev
paulkoehlerdev
opened on Jul 13, 2026
Issue body actions

Version

1.31.1

What happened?

When running sqlc 1.31.1 with go tool sqlc generate I dont get any error log, but the output does not include the specified parameter. I would expect a timestamp parameter in this example.

Expectation:

// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.31.1
// source: query.sql

package db

import (
	"context"
	"time"
)

const updateEntities = `-- name: UpdateEntities :execrows
UPDATE target_table
SET active = 0
WHERE EXISTS (
  SELECT 1
  FROM source_table s
  WHERE s.updated_at >= ?
)
`

func (q *Queries) UpdateEntities(ctx context.Context, updatedAfter time.Time) (int64, error) {
	result, err := q.db.ExecContext(ctx, updateEntities, updatedAfter)
	if err != nil {
		return 0, err
	}
	return result.RowsAffected()
}

Actual output:

// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.25.0
// source: query.sql

package db

import (
	"context"
)

const updateEntities = `-- name: UpdateEntities :execrows
UPDATE target_table
SET active = 0
WHERE NOT (
    EXISTS (
        SELECT 1
        FROM source_table s
        WHERE s.updated_at >= sqlc.arg(updated_after)
    )
)
`

func (q *Queries) UpdateEntities(ctx context.Context) (int64, error) {
	result, err := q.db.ExecContext(ctx, updateEntities)
	if err != nil {
		return 0, err
	}
	return result.RowsAffected()
}

Relevant log output

-- no output --

Database schema

CREATE TABLE target_table
(
    id     BIGINT PRIMARY KEY,
    active BOOLEAN NOT NULL
);

CREATE TABLE source_table
(
    id         BIGINT PRIMARY KEY,
    updated_at TIMESTAMP NOT NULL
);

SQL queries

-- name: UpdateEntities :execrows
UPDATE target_table
SET active = 0
WHERE NOT (
    EXISTS (
        SELECT 1
        FROM source_table s
        WHERE s.updated_at >= sqlc.arg(updated_after)
    )
);

Configuration

{
  "version": "2",
  "sql": [{
    "schema": "schema.sql",
    "queries": "query.sql",
    "engine": "mysql",
    "gen": {
      "go": {
        "out": "db"
      }
    }
  }]
}

Playground URL

https://play.sqlc.dev/p/29743a26dc241fe38660c6a2c7d7fb37505e1cecb4251f6f0876a14747efb431

What operating system are you using?

macOS

What database engines are you using?

MySQL

What type of code are you generating?

Go

Edit: Make the problem more clear, by adding expectation/ reality

Reacted by pavhl

Activity

  1. paulkoehlerdev
    added
    bugSomething isn't workingSomething isn't working
    on Jul 13, 2026
  2. muratmirgun commented on Jul 25, 2026

    @muratmirgun
    muratmirgun
    on Jul 25, 2026
    More actions

    It looks like the MySQL converter currently treats UnaryOperationExpr as a TODO node, so the parameter walker never reaches the sqlc.arg inside NOT (EXISTS (...)).

    I’d like to work on a fix for this if no one else has started yet.

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 workingSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      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.