Skip to content

Exectuing pq.CopyIn fails with one of two errors depending on usage #1154

@bqback

Description

@bqback

Query is

  • defined as query := pq.CopyIn("public.foo", "col_foo", "col_bar")
  • prints as COPY "public.foo" ("col_foo", "col_bar") FROM STDIN.

Executing the prepared statement

  • prepared via tx.Prepare(query)
  • tx being defined as tx, err := db.Begin()
  • db is of type sqlx.DB, a connection established via sqlx.Connect if that matters

via _, err := statement.Exec("foo", "bar") returns either

  • sql: expected 0 arguments, got 2
    • This occurs when I use "pgx" as the driver when establishing the connection.
  • pq: relation "public.foo" does not exist when preparing
    • This occurs when I use "postgres" (pq) as the driver when establishing the connection. and is infinitely more puzzling, because not only does the relation exist when checked manually (SELECT * FROM public.foo; works fine in Postgres shell), but the application also contains a SELECT statement that leftjoins on public.foo, which works fine and returns no errors.

I don't really see a reason for why this would happen, no relevant issues for either of the two points. I'd prefer to use pq, because pgx's CopyFrom straight up does not support usage from transactions for whatever reason and requires a direct access to connection.

Let me know if I can provide anything else to elaborate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions