Skip to content

Unable to pass in variable for limit in update queries #2131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bbody opened this issue Mar 6, 2023 · 6 comments
Closed

Unable to pass in variable for limit in update queries #2131

bbody opened this issue Mar 6, 2023 · 6 comments
Milestone

Comments

@bbody
Copy link

bbody commented Mar 6, 2023

Version

1.16.0

What happened?

I want to allow my application to limit how many records get updated but SQLC does not expose it in the code. I don't have the option to use a subquery with a limit (the code generation works) due to my MySQL version.

Relevant log output

const test = `-- name: Test :exec
UPDATE authors
SET bio="test"
WHERE name IS NULL
LIMIT ?
`

func (q *Queries) Test(ctx context.Context) error {
	_, err := q.db.ExecContext(ctx, test)
	return err
}

Database schema

CREATE TABLE authors (
  id   INT PRIMARY KEY,
  name text      NOT NULL,
  bio  text
);

SQL queries

-- name: Test :exec
UPDATE authors
SET bio="hello"
WHERE name IS NULL
LIMIT ?;

Configuration

{
  "version": "1",
  "packages": [
    {
      "path": "db",
      "engine": "mysql",
      "schema": "query.sql",
      "queries": "query.sql"
    }
  ]
}

Playground URL

https://play.sqlc.dev/p/732de1ddc031aba2c5bfce20367a16435eedd43745324af4249b2b6803862430

What operating system are you using?

macOS

What database engines are you using?

MySQL

What type of code are you generating?

Go

@bbody bbody added bug Something isn't working triage New issues that hasn't been reviewed labels Mar 6, 2023
@kyleconroy kyleconroy added this to the v1.19.0 milestone Jun 7, 2023
@kyleconroy kyleconroy added 📚 mysql 🔧 golang 💻 darwin and removed triage New issues that hasn't been reviewed labels Jun 7, 2023
Jille added a commit to Jille/sqlc that referenced this issue Jun 24, 2023
PostgreSQL doesn't support UPDATE-LIMIT

issue sqlc-dev#2131
@Jille
Copy link
Contributor

Jille commented Jun 24, 2023

Kyle added this to the milestone, and I'd like to have the next release, so I wrote a PR :P

@SnoozeThis #2365 -> close

@SnoozeThis
Copy link

I don't have privileges to execute this action. Please install the SnoozeThis GitHub app (https://github.com/apps/snoozethis).

@Jille
Copy link
Contributor

Jille commented Jun 24, 2023

@SnoozeThis #2365

@SnoozeThis
Copy link

(https://snoozeth.is/j3WmMD-oYu4) I will wait until #2365 is closed and then add a comment.

kyleconroy pushed a commit that referenced this issue Jun 27, 2023
PostgreSQL doesn't support UPDATE-LIMIT

issue #2131
@SnoozeThis
Copy link

Resolved.

andrewmbenton pushed a commit that referenced this issue Jun 27, 2023
PostgreSQL doesn't support UPDATE-LIMIT

issue #2131
@bbody
Copy link
Author

bbody commented Jun 28, 2023

Thank you @kyleconroy

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

No branches or pull requests

4 participants