[Libpqxx-general] Prepared statements parameters inconsistency

Jeroen T. Vermeulen jtv at xs4all.nl
Tue Jul 14 14:49:38 UTC 2009


On Tue, July 14, 2009 14:55, Trigve Siver wrote:

> I've trouble executing "UPDATE" prepare statement with parameters. I've
> simple query like "UPDATE customer SET id = $1, id_sub = $2 WHERE (id = $1
> AND id_sub = $2)", where "id", "id_sub" are varchars. I prepare statement
> with 2 parameters as "decl("varchar", pqxx::prepare::treat_string)". When
> executing this statement I've got error saying:
>
> ERROR:  inconsistent types deduced for parameter $1
> DETAIL:  text versus character varying
>
> I've search if someone has encountered this behaviour but had found
> nothing. Also note when using the same parameters but with "SELECT" query
> no error is thrown, only with "UPDATE" I have a problem. Please, anyone
> know where the problem could be?

It must be something about how postgres guesses what the parameters are. 
On up-to-date libpq and backends at least, libpqxx relies entirely on that
guess and ignores the parameter types you declare.

We could change that, but it's probably going to uncover a whole load of
bugs in client programs.  We might even need a "second-guess" approach
where both are tried...


Jeroen



More information about the Libpqxx-general mailing list