Re: Normalize INTERVAL ouput format in a db driver

From: Sebastien FLAESCH <sf(at)4js(dot)com>
To: Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Normalize INTERVAL ouput format in a db driver
Date: 2009-07-07 13:04:13
Message-ID: 4A5347CD.7010008@4js.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Albe Laurenz wrote:
> Sebastien FLAESCH wrote:
>> According to the doc, INTERVAL output format is controlled by
>> SET intervalstyle.
>>
>> I am writing an interface/driver and need a solution to
>> fetch/convert interval
>> values independently from the current format settings...
>>
>> I could force my driver to implicitly set the intervalstyle
>> to iso_8601, but I
>> would prefer to leave this in the hands of the programmer...
>>
>> Imagine you have to write and ODBC interface/driver with
>> libpq that must support
>> the SQLINTERVAL C structure, how would you deal with
>> PostgreSQL intervals?
>>
>> Is it possible to query the current intervalstyle?
>
> You can use "SHOW intervalstyle" to get the current setting.
>
> Would it be an option to use the to_char(interval, text)
> function to convert the interval value to a string you can
> understand? That would make you independent of server parameters.
>
> Another way to go is to retrieve the interval values
> in binary format. That would make you dependent on the
> setting of "integer_datetimes", but it might still be easier.
>
> Yours,
> Laurenz Albe

Thanks for the tip, I found SHOW after sending my initial mail.

I will however go by forcing a given intervalstyle in a first
time, this is not critical (I cannot use the internal binary
format).

My main concern now is to describe properly the type of interval
which is used in a SELECT list, with the PQfmod() and PQfsize()
libpq functions, I need some doc/spec here...

Thanks a lot!
Seb

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andreas Wenk 2009-07-07 13:54:55 Re: Sugestion a db modele like mysql workbrench
Previous Message Ivan Sergio Borgonovo 2009-07-07 12:28:29 Re: Feistel cipher, shorter string and hex to int