Re: INTERVAL data type and libpq - what format?

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Sam Mason <sam(at)samason(dot)me(dot)uk>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: INTERVAL data type and libpq - what format?
Date: 2009-05-19 14:38:10
Message-ID: b42b73150905190738w43249b0bt127e8d72676100bd@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

On Tue, May 19, 2009 at 10:12 AM, Sam Mason <sam(at)samason(dot)me(dot)uk> wrote:
> On Tue, May 19, 2009 at 02:17:20PM +0200, Sebastien FLAESCH wrote:
>> As you can do with ODBC's SQLBindParameter(), where you specify the C type,
>> SQL type, precision/scale or length ...
>> I believe this is important when it comes to data type conversion (for ex,
>> when you want to insert a numeric/date/time into a char or the other way).
>> => sort of cast, actually...
>
> Tom sent a message, but it seems to have got lost somewhere.  The
> suggestion was to leave the paramTypes empty and just write the prepared
> statement as:
>
>  INSERT INTO tbl (k,i1,i2) VALUES ($1::INT,$2::INTERVAL YEAR,$3::INTERVAL);
>
> or similar.  That way PG will be able to infer that $1 will be a literal
> of integer type, $2 will be of INTERVAL YEAR and so on.  In fact for
> queries such as this I don't think you even need to put those casts in
> there as PG will be able to figure out what you mean automatically (i.e.
> it does a limited form of type inference).
>
>> I known libpq functions like PQexecParams() or PQexecPrepared() have a
>> paramFormats[] parameter to specify if the buffer will hold a string
>> or the binary representation of the value... but that would not help
>> much (I don't want to deal with internal structures!).
>
> Yes, stay away from binary types if at all possible!
>

For the record, I disagree with this sentiment strongly. I would
rather see the client side library be buffed up so you have an
opportunity to deal with the data structures the way the server sees
them. The more complex the type is (like date time types), the
bigger the win both in terms of performance and feature exposure. I
understand though that cross database support is impossible though.

merlin

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bayless Kirtley 2009-05-19 14:40:08 Re: Daylight saving time question
Previous Message Merlin Moncure 2009-05-19 14:30:26 Re: INTERVAL data type and libpq - what format?

Browse pgsql-hackers by date

  From Date Subject
Next Message Sebastien FLAESCH 2009-05-19 15:25:32 Re: INTERVAL data type and libpq - what format?
Previous Message Merlin Moncure 2009-05-19 14:30:26 Re: INTERVAL data type and libpq - what format?