Re: Extended query protocol and exact types matches.

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Dmitriy Igrishin <dmitigr(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Extended query protocol and exact types matches.
Date: 2010-12-10 17:22:23
Message-ID: AANLkTi=xtXSO1TJ07L=KUjoNoj1f+qjZP8pB5iXdFerb@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers pgsql-sql

On Thu, Dec 9, 2010 at 1:24 PM, Dmitriy Igrishin <dmitigr(at)gmail(dot)com> wrote:
> Hey general@,
>
> To be assured and just for calmness.
>
> Problem:
>
> 1. CREATE TABLE test_tab (id integer, dat varchar(64));
>
> 2. INSERT INTO test_tab VALUES($1, $2) via PQexecParams,
>  where paramTypes[0] == OID of bigint,
>            paramTypes[1] == OID of text.
>
> Questions:
>
> Whether this case falls to
> http://www.postgresql.org/docs/9.0/static/typeconv-query.html ?
>
> Is such cases safe or it is recommended (best) to specify a
> OIDs which are exact matches ?

Anyways, here's the deal:

The oid vector passed to the database in these functions is for
describing the data you are passing. If left NULL, you leave it up to
the database to try and guess what you are sending based on the
context of the query. This has pros and cons. With the text
protocol, it's somewhat ok to leave off the oid vector: this isn't
much different from sending uncasted unknown strings into psql. It's
basically there to protect you from sending bogus data to the server
and reduce chance of type confusion. If you are using binary
protocol, the oid vector is absolutely essential -- it's insane to
have the server 'guess' what you are passing in since a wrong guess
could be interpreted improperly vs a formatting error that text
casting raises. If you are wrapping libpq with a higher level
library, sending the correct oids always would be a pretty good idea.
Meaning, you should try and coerce your application/language types
into a type the database understands and pass a corresponding oid.

merlin

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2010-12-10 17:31:33 Re: A cronjob for copying a table from Oracle
Previous Message Scott Mead 2010-12-10 17:21:26 Re: monitoring warm standby lag in 8.4?

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2010-12-10 17:30:00 Re: Extensions, patch v16
Previous Message Dmitriy Igrishin 2010-12-10 16:59:46 Re: Fwd: Extended query protocol and exact types matches.

Browse pgsql-sql by date

  From Date Subject
Next Message Dmitriy Igrishin 2010-12-10 17:40:01 Re: Extended query protocol and exact types matches.
Previous Message Dmitriy Igrishin 2010-12-10 16:46:44 Re: Fwd: Extended query protocol and exact types matches.