Re: INTERVAL data type and libpq - what format?

From: Sebastien FLAESCH <sf(at)4js(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: INTERVAL data type and libpq - what format?
Date: 2009-05-19 16:27:33
Message-ID: 4A12DDF5.1050406@4js.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Tom Lane wrote:
> Sam Mason <sam(at)samason(dot)me(dot)uk> writes:
>> I don't really know 8.4, but I believe you're saying here that you
>> explicitly want the values to be of basic INTERVAL type here, i.e. not
>> INTERVAL DAY TO HOUR for parameter 3.
>
> Right, you can get the equivalent behavior from psql thus:
>
> regression=# select '-12345'::interval::interval year;
> interval
> ----------
> 00:00:00
> (1 row)
>
> regression=# select '12 11'::interval::interval year;
> ERROR: invalid input syntax for type interval: "12 11"
> LINE 1: select '12 11'::interval::interval year;
> ^
>
> There is not any way to bind a more specific type to a parameter at the
> protocol level.
>
>> I think PG may do the right thing if you
>> don't specify the types when preparing the query, but haven't tested.
>
> Yeah, that should work (though I haven't verified it either). Another
> common trick is to specify the type in the text of the query by casting
> the parameter symbol:
>
> PQprepare( ... $2::INTERVAL YEAR ... );
>
> I'd say this is better style than hard-wiring numeric type OIDs into
> your code.

Remember we are implementing a database driver with equivalent features
and an ODBC driver for PostgreSQL, executing queries with ? parameter
placeholders in the SQL text...

Since SQL Parameter types are not known at (4gl language-level) PREPARE
time, we wait for the (4gl) EXECUTE time to do the real PQprepare() with
paramTypes[]... (this is a pity by the way since we can't get any SQL
error at PREPARE time).

It's not that easy for us to add the ::<type> clauses because the conversion
of the ? placeholders to $n is done at PREPARE time, when types are not yet
yet... so this means major rewriting...

But this is all internal stuff you are not interested in, the main question
I would like to ask is:

What versions of PostgreSQL are 100% sure supporting the $n::<type> clauses?

We have to support all PostgreSQL versions, starting from 8.0 ...

Thanks
Seb

In response to

Browse pgsql-general by date

  From Date Subject
Next Message aravind chandu 2009-05-19 16:37:32 Error while including PQXX library
Previous Message hubert depesz lubaczewski 2009-05-19 15:57:46 Re: Get block of N numbers from sequence

Browse pgsql-hackers by date

  From Date Subject
Next Message decibel 2009-05-19 16:30:42 Re: Show method of index
Previous Message Robert Haas 2009-05-19 15:52:25 Re: Show method of index