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 18:05:44
Message-ID: AANLkTikhyj1ax=NznonepNN5vnFa2JttZapBtnUgboh9@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers pgsql-sql

On Fri, Dec 10, 2010 at 12:40 PM, Dmitriy Igrishin <dmitigr(at)gmail(dot)com> wrote:
> Hey Merlin,
>
> Thank you for explanation !
>
> Yes, I understand that specifying NULL instead real OID will provoke
> the parser attempts to infer the data types in the same way as it would
> do for untyped literal string constants.
> But there are three string types: text, varchar(n) and character(n) which
> has a different OIDs but they are all in the same type category. So, is it
> worth it to implement some Varchar and Character types (which actually
> wraps Text) at the library level or specifying the OID of text for contexts
> where these parameters actually varchar or char (i.e. types of same
> category) are safe?

not really, at the end of the day, you are coming in from C char*, so
just send TEXTOID and let the server worry about what to do if say you
are passing into varchar or (more rarely char(n)). libpqtypes, the
library you are pretending doesn't exist, does this
(http://libpqtypes.esilo.com/man3/pqt-specs.html). PGtext is
typedef'd char* and the only format string for character types is
%text.

IMNSHO, If you wanted to attack this problem in an actually novel and
useful way in C++ style, I would consider taking the libpqtypes
library, rip out all the format string stuff, and rig variadic
templates so you could leverage variadic queries. Maybe this could be
integrated into libpqxx, not sure.

printf : cout :: : PQexecf : query

query(conn, "select $1 + $2", 3, 7);

'query' is hypothetical function that uses template type inference,
mapping/marshaling data and building the data structure that
PQexecParams points to (in libpqtypes, the PGparam). Parsing the type
format string is expensive enough that we had to implement a client
side prepare to reduce the cost of searching type handlers over and
over. Of course, cout is not really faster than printf, but that's
another topic :-).

merlin

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alexander Farber 2010-12-10 18:13:02 Re: A cronjob for copying a table from Oracle
Previous Message Dmitriy Igrishin 2010-12-10 18:03:25 Re: A cronjob for copying a table from Oracle

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2010-12-10 18:06:59 Re: Why percent_rank is so slower than rank?
Previous Message Andrew Dunstan 2010-12-10 18:03:21 Re: initdb failure with Postgres 8.4.4

Browse pgsql-sql by date

  From Date Subject
Next Message Dmitriy Igrishin 2010-12-10 18:26:11 Re: Extended query protocol and exact types matches.
Previous Message Dmitriy Igrishin 2010-12-10 17:58:12 Re: Fwd: Extended query protocol and exact types matches.