agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
Determining the DATE format with libpq
5+ messages / 2 participants
[nested] [flat]

* Determining the DATE format with libpq
@ 2017-08-24 15:21  Sebastien FLAESCH <sf@4js.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Sebastien FLAESCH @ 2017-08-24 15:21 UTC (permalink / raw)
  To: pgsql-sql

Hi all,

The date format can be defined with SET DateStyle.

When fetching result set values using the libpq C API, we get plain text from PQgetvalue(), representing a date in the current format.

We need to extract date parts (year/month/day) to fill our own DATE type structure...

Is there a way to know the current date format used in the SQL session?

Ideally, we expect a libpq API.

We cannot do a "SHOW DateStyle" each time we executing a SELECT!

Other DB client C APIs provide a C structure to hold DATE values so it's easy to get year/month/day parts.

Seb


-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Determining the DATE format with libpq
@ 2017-08-24 15:26  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Sebastien FLAESCH <sf@4js.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Tom Lane @ 2017-08-24 15:26 UTC (permalink / raw)
  To: Sebastien FLAESCH <sf@4js.com>; +Cc: pgsql-sql

Sebastien FLAESCH <sf@4js.com> writes:
> Is there a way to know the current date format used in the SQL session?
> Ideally, we expect a libpq API.

Use PQparameterStatus().

> We cannot do a "SHOW DateStyle" each time we executing a SELECT!

You don't have to --- the server automatically reports changes in the
value of that parameter.

			regards, tom lane


-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Determining the DATE format with libpq
@ 2017-08-24 15:44  Sebastien FLAESCH <sf@4js.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 2 replies; 5+ messages in thread

From: Sebastien FLAESCH @ 2017-08-24 15:44 UTC (permalink / raw)
  To: pgsql-sql

Whoooooo that's perfect!!!

I hope it has not a big cost?

Can I use this each time I fetch a result set?

Even row by row with a server cursor?

Seb

On 08/24/2017 05:26 PM, Tom Lane wrote:
> Sebastien FLAESCH <sf@4js.com> writes:
>> Is there a way to know the current date format used in the SQL session?
>> Ideally, we expect a libpq API.
>
> Use PQparameterStatus().
>
>> We cannot do a "SHOW DateStyle" each time we executing a SELECT!
>
> You don't have to --- the server automatically reports changes in the
> value of that parameter.
>
> 			regards, tom lane
>
>



-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Determining the DATE format with libpq
@ 2017-08-25 08:13  Sebastien FLAESCH <sf@4js.com>
  parent: Sebastien FLAESCH <sf@4js.com>
  1 sibling, 0 replies; 5+ messages in thread

From: Sebastien FLAESCH @ 2017-08-25 08:13 UTC (permalink / raw)
  To: pgsql-sql

I appologize for my poor English...
I was just wondering about the overhead of a call to PQparameterStatus().
After some tests, it appears to be minor.
Anyway, thanks for your help!
Seb

On 08/24/2017 05:44 PM, Sebastien FLAESCH wrote:
> Whoooooo that's perfect!!!
>
> I hope it has not a big cost?
>
> Can I use this each time I fetch a result set?
>
> Even row by row with a server cursor?
>
> Seb
>
> On 08/24/2017 05:26 PM, Tom Lane wrote:
>> Sebastien FLAESCH <sf@4js.com> writes:
>>> Is there a way to know the current date format used in the SQL session?
>>> Ideally, we expect a libpq API.
>>
>> Use PQparameterStatus().
>>
>>> We cannot do a "SHOW DateStyle" each time we executing a SELECT!
>>
>> You don't have to --- the server automatically reports changes in the
>> value of that parameter.
>>
>>             regards, tom lane
>>
>>
>
>
>



-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Determining the DATE format with libpq
@ 2017-08-25 10:09  Sebastien FLAESCH <sf@4js.com>
  parent: Sebastien FLAESCH <sf@4js.com>
  1 sibling, 0 replies; 5+ messages in thread

From: Sebastien FLAESCH @ 2017-08-25 10:09 UTC (permalink / raw)
  To: pgsql-sql

Seems that even if one can change the date style while fetching rows from a
server cursor, the date format returned by PQgetvalue() does not change in
the middle of a result set processing, which is obviously better.

So we just need to inspect the date format when opening the cursor and
stuck to that format for result set values processing.

Seb


-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql



^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2017-08-25 10:09 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-08-24 15:21 Determining the DATE format with libpq Sebastien FLAESCH <sf@4js.com>
2017-08-24 15:26 ` Tom Lane <tgl@sss.pgh.pa.us>
2017-08-24 15:44   ` Sebastien FLAESCH <sf@4js.com>
2017-08-25 08:13     ` Sebastien FLAESCH <sf@4js.com>
2017-08-25 10:09     ` Sebastien FLAESCH <sf@4js.com>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox