jackc / jackc/pgx

parameter not accepted

Open
#2,148 2 comments 1 reaction 0 assignees View on GitHub
bug
Dominant language
Go
Stars
14.3k
Forks
1.1k
Avg merge
6d 9h
Merged PRs (30d)
11

Description

**Describe the bug**
A clear and concise description of what the bug is.
I submitted a query "select * from $1;" and executed con.Query(ctx, query, "table")
Received the error message: ERROR: syntax error at or near "$1" (SQLSTATE 42601)

I repeated the exercise with the query: "select * from table;" executed con.Query(ctx, query)
no error message

**From the documentation it is not clear to me whether this is an error or a feature limitation.**

**To Reproduce**
Steps to reproduce the behavior:
create a simple table with columns "first" and "last". Insert some dummy data and retrieve the data as outlined above

If possible, please provide runnable example such as:

```go
package main

import (
"context"
"log"
"os"

"github.com/jackc/pgx/v5"
)

func main() {
conn, err := pgx.Connect(context.Background(), os.Getenv("DATABASE_URL"))
if err != nil {
log.Fatal(err)
}
defer conn.Close(context.Background())

// Your code here...
var user_id int
var first, last string
query := "select user_id, first, last from $1;"

rows, err := dbcon.Query(ctx, query, "person")
if err != nil {
fmt.Printf("error -- query failed: %v\n", err)
os.Exit(1)
}
defer rows.Close()

}
```

Please run your example with the race detector enabled. For example, `go run -race main.go` or `go test -race`.

**Expected behavior**
A clear and concise description of what you expected to happen.

**Actual behavior**
A clear and concise description of what actually happened.

**Version**
- Go: `$ go version` -> [e.g. go version go1.18.3 darwin/amd64] 1.22.5
- PostgreSQL: `$ psql --no-psqlrc --tuples-only -c 'select version()'` -> [e.g. PostgreSQL 14.4 on x86_64-apple-darwin21.5.0, compiled by Apple clang version 13.1.6 (clang-1316.0.21.2.5), 64-bit] pg 16.04
- pgx: `$ grep 'github.com/jackc/pgx/v[0-9]' go.mod` -> [e.g. v4.16.1]
github.com/jackc/pgx/v5 v5.4.1
**Additional context**
Add any other context about the problem here.

Contributor guide

Open the contributing guide

Research direction

Start with the pgx v5 con.Query entry point and the PostgreSQL examples using $1 for a table name. Check whether the reported behavior is a PostgreSQL parameter limitation or a pgx issue, then document the result and add a reproducible test or documentation clarification if the project supports one.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, postgresql
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.