Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Error] there is allways - 'syntax error near " CREATE TABLE authors"' #3680

Unanswered
GARcraft asked this question in Q&A
Discussion options

Windows 11 using docker (but if I try to use sql.exe, there is same results)

sqlc.yaml:

version: '2'
sql:
 - schema: "schema.sql"
 queries: "query.sql"
 engine: "mysql"
 gen:
 go:
 out: "MySqlExample"

schema.sql:

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

query.sql:

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

command:

docker run --rm -v ${pwd}:/src -w /src sqlc/sqlc generate

response:

# package 
schema.sql:1:9: syntax error near "CREATE TABLE authors"

^ allways shows first line of schema.sql file

If I will try to use 'sqlite' instead of 'mysql' there is another error:

line 1:0 extraneous input '' expecting {<EOF>, ';', ALTER_, ANALYZE_, ATTACH_, BEGIN_, COMMIT_, CREATE_, DEFAULT_, DELETE_, DETACH_, DROP_, END_, EXPLAIN_, INSERT_, PRAGMA_, REINDEX_, RELEASE_, REPLACE_, ROLLBACK_, SAVEPOINT_, SELECT_, UPDATE_, VACUUM_, VALUES_, WITH_}
# package
schema.sql:1:1: extraneous input '' expecting {<EOF>, ';', ALTER_, ANALYZE_, ATTACH_, BEGIN_, COMMIT_, CREATE_, DEFAULT_, DELETE_, DETACH_, DROP_, END_, EXPLAIN_, INSERT_, PRAGMA_, REINDEX_, RELEASE_, REPLACE_, ROLLBACK_, SAVEPOINT_, SELECT_, UPDATE_, VACUUM_, VALUES_, WITH_}

Could someone has this issue? Please tell me what did you do, to make it work.

You must be logged in to vote

Replies: 2 comments

Comment options

Running with all of those files in a 'testing' folder on ubuntu running:
% cd testing; sqlc generate
and
% cd testing; sqlc -f ./sqlc.yaml generate
work fine in all cases. I can't get it to break. Similar on macos and win11.

I would guess it's something between your docker command and your container's files.

db.go:
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.27.0

package MySqlExample

import (
"context"
"database/sql"
)

type DBTX interface {
ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
PrepareContext(context.Context, string) (*sql.Stmt, error)
QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
QueryRowContext(context.Context, string, ...interface{}) *sql.Row
}

func New(db DBTX) *Queries {
return &Queries{db: db}
}

type Queries struct {
db DBTX
}

func (q *Queries) WithTx(tx *sql.Tx) *Queries {
return &Queries{
db: tx,
}
}

models.go:
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.27.0

package MySqlExample

import (
"database/sql"
)

type Author struct {
ID int32
Name string
Bio sql.NullString
}

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

package MySqlExample

import (
"context"
)

const listAuthors = -- name: ListAuthors :many SELECT id, name, bio FROM authors ORDER BY name

func (q *Queries) ListAuthors(ctx context.Context) ([]Author, error) {
rows, err := q.db.QueryContext(ctx, listAuthors)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Author
for rows.Next() {
var i Author
if err := rows.Scan(&i.ID, &i.Name, &i.Bio); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}

You must be logged in to vote
0 replies
Comment options

Try removing the byte-order mark (BOM) from your .sql files.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

AltStyle によって変換されたページ (->オリジナル) /