sqlpostgresqlgosqlc

error parsing queries: no queries contained in paths ./db/queries


here is my sqlc.yaml file created with sqlc init

sql:
  - engine: "postgresql"
    queries: "db/queries"  # directory containing query files (e.g account.sql)
    schema: "db/migrations"  # directory containing schema files (e.g 000001_init_schema.up.sql)
    gen:
      go:
        package: "db"        
        sql_package: "pgx/v5"    
        out: "db/sqlc"               
        emit_json_tags: true    
        emit_interface: true    

when running the command sqlc generate getting the following error

➜  go_bank sqlc generate
# package db
error parsing queries: path error: stat <my-dir>/db/queries: no such file or directory

Here’s the SQL query located in db/queries/account.sql

INSERT INTO accounts (owner, balance, currency)
VALUES ($1, $2, $3)
RETURNING *;

Note: The SQL itself is syntactically valid for PostgreSQL and should work with sqlc if properly detected. The problem lies in sqlc not finding this file, not in the SQL content.

I have tried both version 2 structure and version 1 getting same error in both

version: "1"
packages:
  - name: "db"
    path: "internal/db"
    queries: "./db/queries"
    schema: "./db/migrations"
    engine: "postgresql"

here is my project structure

.
├── db
│   ├── migrations
│   │   ├── 000001_init_schema.down.sql
│   │   └── 000001_init_schema.up.sql
│   └── queries
│       └── account.sql
└── sqlc.yaml

desired output Running sqlc generate should:


Solution

  • I figured out the issue after digging into the sqlc documentation. The problem was that my query.sql file was missing a required annotation comment. According to Query Annotations every query must have a comment in the format -- name: QueryName :commandType directly above it.

    Updated query.sql

    -- name: CreateAccount :one
    insert into accounts(
        owner, balance, currency
    ) values (
        $1, $2, $3
    ) returning *;
    

    Why It Happens ?

    sqlc requires these annotations to parse queries and map them to Go structs or functions. Without them, it treats the file as having no valid queries, even if the SQL itself is correct. My original comment -- return all columns * didn’t follow the required format and was ignored.