Skip to content
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

ORDER BY does not enforce column to exist #1411

Closed
theFong opened this issue Feb 2, 2022 · 2 comments
Closed

ORDER BY does not enforce column to exist #1411

theFong opened this issue Feb 2, 2022 · 2 comments
Labels
📚 mysql bug Something isn't working 💻 darwin

Comments

@theFong
Copy link

theFong commented Feb 2, 2022

Version

1.11.0

What happened?

When creating a query that orders by a non-existent column, sqlc does not emit a query.sql:x:y: column "adfadsf" does not exist error.

Relevant log output

No response

Database schema

-- Example queries for sqlc
CREATE TABLE authors (
  id   BIGSERIAL PRIMARY KEY,
  name text      NOT NULL,
  bio  text
);

SQL queries

-- name: ListAuthors :many
SELECT * FROM authors
ORDER BY adfadsf;

Configuration

version: 1
packages:
  - path: "sqlc"
    name: "sqlc"
    engine: "mysql"
    schema: "schema.sql"
    queries: "query.sql"

Playground URL

https://play.sqlc.dev/p/9b40e9e704f08dc389049f02786f9d072d0c51839a432ff196dadcdfa6b19900

What operating system are you using?

macOS

What database engines are you using?

MySQL

What type of code are you generating?

Go

@theFong theFong added bug Something isn't working triage New issues that hasn't been reviewed labels Feb 2, 2022
@kyleconroy kyleconroy added 📚 mysql 💻 darwin and removed triage New issues that hasn't been reviewed labels Feb 3, 2022
@kimtore
Copy link

kimtore commented Oct 21, 2022

It would be great if sqlc could enforce validity of ORDER BY columns. We just had a regression because of dropped columns that were not removed from queries, and it passed straight through generation.

FWIW, we use Postgres.

@akutschera
Copy link
Contributor

You are right. While there was code for checking "GROUP BY" clauses, the "ORDER BY" checks were missing. The commit above should fix that.

akutschera added a commit to akutschera/sqlc that referenced this issue Nov 10, 2022
akutschera added a commit to akutschera/sqlc that referenced this issue Nov 12, 2022
akutschera added a commit to akutschera/sqlc that referenced this issue Nov 12, 2022
Tell the uses how to switch off validation here.
akutschera added a commit to akutschera/sqlc that referenced this issue Nov 12, 2022
kyleconroy added a commit that referenced this issue Jun 8, 2023
* fix: check column references in ORDER BY (#1411)

* test: move test cases to endtoend tests

* feat: add validate_order_by config option #1411

* feat: expand error message #1411

Tell the uses how to switch off validation here.

* feat: add expanded error message to test #1411

* compiler: Add functions to the compiler struct

Don't pass configuration around as a parameter

---------

Co-authored-by: Kyle Conroy <kyle@conroy.org>
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📚 mysql bug Something isn't working 💻 darwin
Projects
None yet
Development

No branches or pull requests

4 participants