Skip to content

warn when using quotes or parse the SQL #3162

Closed
@mpldr

Description

@mpldr

What do you want to change?

I have the following setup:

queries.sql

-- name: CheckDatabase :exec
SELECT
	COUNT(ID),
	COUNT(Destination),
	COUNT(Hits),
	COUNT(Owner)
FROM redirections;

schema.sql

CREATE TABLE "redirections" (
	"ID"	TEXT NOT NULL,
	"Destination"	TEXT NOT NULL,
	"Hits"	INTEGER NOT NULL DEFAULT 0,
	"Owner"	TEXT NOT NULL,
	PRIMARY KEY("ID")
);

sqlc.json

{
	"version": "2",
	"sql": [{
		"schema": "./internal/datastore/db/schema.sql",
		"queries": "./internal/datastore/db/queries.sql",
		"engine": "sqlite",
		"gen": {
			"go": {
				"out": "db"
			}
		}
	}]
}

I think this should work, and in fact play.sqlc.dev agrees with me there. BUT

$ go run github.com/sqlc-dev/sqlc/cmd/sqlc@latest generate
# package 
internal/datastore/db/queries.sql:1:1: relation "redirections" does not exist
exit status 1

Thanks to @qbit, I learned about the use of quotations in the CREATE statement leading to all uses of the identifier having to be quoted. Leaving aside how … unideal … this limitation is, I would consider this unexpected behaviour, so I propose one of the following solutions:

  • actually parse the name of the identifier (preferred)
  • warn the user about this pitfall (if not in the CLI output, then in the docs)

Since I don't think this affects any specific database engine, or language backend, I have not selected any of them. If that's incorrect, I apologise.

What database engines need to be changed?

No response

What programming language backends need to be changed?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions