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

Relation does not exists when name is surrounded by ` character #3800

Open
Codebreaker101 opened this issue Jan 21, 2025 · 1 comment
Open

Comments

@Codebreaker101
Copy link

Codebreaker101 commented Jan 21, 2025

Version

1.28.0

What happened?

I'm using this sqlite3 command to export schema from the database: sqlite3 db/data.db '.schema authors' > ./db/schema.sql and it generates an sql schema where all table and column names are surrounded with a backtick character. This schema cannot be parsed by sqlc . Removing the backtick characters using command sed -i "s/\`//g" db/schema.sql allows sqlc to generate the code.

Relevant log output

# package db
db/query.sql:6:1: relation "authors" does not exist

Database schema

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

SQL queries

-- name: GetAuthor :one
SELECT * FROM authors WHERE id = ? LIMIT 1;

Configuration

version: "2"
sql:
  - engine: "sqlite"
    queries: "db/query.sql"
    schema: "db/schema.sql"
    gen:
      go:
        package: "db"
        out: "db"

Playground URL

https://play.sqlc.dev/p/5d35e2538160c53e61fe204c3a2f05fe489687ac10a8d74304a82c2d7ec95871

What operating system are you using?

Linux

What database engines are you using?

SQLite

What type of code are you generating?

Go

@thomasquinn
Copy link

Commenting here since it seems related to the same issue, potentially caused by #3657. I see the same issue with non-backtick-quoted identifiers in UPDATE statements.

I noticed that this issue is not present with 3657.patch reverted (ignoring testdata conflicts) on tag v1.28.0:

git apply -R 3657.patch --exclude="internal/endtoend/testdata/*"

Version

1.28.0

Relevant log output

# package 
queries.sql:1:1: relation "Foo" does not exist

Database schema

CREATE TABLE Foo (id TEXT PRIMARY KEY);

SQL queries

-- name: UpdateFoo :one
UPDATE Foo SET id = ? WHERE id = ? RETURNING *;

Configuration

version: "2"
sql:
- engine: sqlite
  schema:
    - schema.sql
  queries:
    - queries.sql
  gen:
    go:
      out: db

What operating system are you using?

macOS

What database engines are you using?

SQLite

What type of code are you generating?

Go

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

2 participants