Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inconsistent types deduced #2233

Open
aeon3k opened this issue Jan 16, 2025 · 1 comment
Open

inconsistent types deduced #2233

aeon3k opened this issue Jan 16, 2025 · 1 comment
Labels

Comments

@aeon3k
Copy link

aeon3k commented Jan 16, 2025

Describe the bug
I try to use twice the $4 argument but it doesn't work in this specific case

`
INSERT INTO public.users (username, email, provider, client_uid, client_id)
VALUES ($1, $2, $3, $4, (select public.clients.id from public.clients where public.clients.uid = $4 limit 1))
RETURNING id, uid`

err := r.pool.QueryRow(context.Background(), q, username, email, "own", "7Rp9WhF3PdrkhY1uZbXj8").Scan(&RetID, &RetUID)

In the DB schema public.clients.uid and client_uid are of the same type : character varying

Expected behavior
I expect to have the same type inference both times (varchar I presume)

Actual behavior
ERROR: inconsistent types deduced for parameter $4 at character 119 (SQLSTATE 42P08)
DETAIL: text versus character varying

Version
PostgreSQL 14.15 (Postgres.app) on aarch64-apple-darwin20.6.0, compiled by Apple clang version 12.0.5 (clang-1205.0.22.9), 64-bit
github.com/jackc/pgx/v5 v5.7.2
go version go1.23.3 darwin/amd64

Additional context

I've tried with a prepared statement in PG Admin and the same query works fine.

I found 2 solutions :

  • If I use WHERE uid = $5 LIMIT 1)) it works fine (I double the same argument)
  • If I use WHERE uid = $4::varchar LIMIT 1)) it works fine

In another similar insert query where I use twice the same $ argument it works fine. In this case it's an int64 (bigint in DB).

Thanks in advance for your help.
Cheers

@aeon3k aeon3k added the bug label Jan 16, 2025
@jackc
Copy link
Owner

jackc commented Jan 25, 2025

I've tried with a prepared statement in PG Admin and the same query works fine.

I'm not sure what PgAdmin does, but can you try it directly in psql?

e.g.

prepare s as insert into ...

That's basically all pgx is doing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants