to_char() and date_part() oddities...

From: "Denis A(dot) Doroshenko" <d(dot)doroshenko(at)omnitel(dot)net>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: to_char() and date_part() oddities...
Date: 2000-12-21 09:01:15
Message-ID: 20001221110115.I32258@comrade.omnitel.lan
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

hello,

yesterday evening i discoverd weird functionality of to_char() and
date_part()... may be it's a known issue, and even corrected in 7.1+,
then my pardon :-)

so, psql session input/output prepended with '| ':

| $ psql template1
| Welcome to psql, the PostgreSQL interactive terminal.
|
| Type: \copyright for distribution terms
| \h for help with SQL commands
| \? for help on internal slash commands
| \g or terminate with semicolon to execute query
| \q to quit

first of all:

| sms=> select version();
| version
| ---------------------------------------------------------------------
| PostgreSQL 7.0.3 on i386-unknown-openbsd2.6, compiled by gcc 2.95.1
| (1 row)

now:

| sms=> select to_char('now'::timestamp, 'CC');
| to_char
| ---------
| 21
| (1 row)

wow, not yet!

| sms=> select to_char('1999-01-01'::timestamp, 'CC');
| to_char
| ---------
| 20
| (1 row)

well, that's ok...

| sms=> select to_char('1900-01-01'::timestamp, 'CC');
| to_char
| ---------
| 20
| (1 row)

huh, that's wrong again! it's the last year of XIX...

date_part() is ... different with these things:

| sms=> select date_part('century', '2000-01-01'::timestamp);
| date_part
| -----------
| 20
| (1 row)

uhm, that's ok! and the following:

| sms=> select date_part('century', '1900-01-01'::timestamp);
| date_part
| -----------
| 19
| (1 row)

well, but, hold on... here comes big 'wow':

| sms=> select date_part('century', '1999-01-01'::timestamp);
| date_part
| -----------
| 19
| (1 row)

we've been living in XIX for so long? :-)

the same problems with millennium number...

| sms=> select date_part('millennium', '0999-01-01'::timestamp);
| date_part
| -----------
| 0
| (1 row)
|
| sms=> select date_part('millennium', '1500-01-01'::timestamp);
| date_part
| -----------
| 1
| (1 row)
|
| sms=> select date_part('millennium', '2222-01-01'::timestamp);
| date_part
| -----------
| 2
| (1 row)

huh?..

yeah, how about roman numbers... why to_char(3000, 'RN') gives 'MMM'
as expected and it works for number up to 3999, but with 4000 i get
'###############' (may be it's legal roman number ;-) like "infinity")?
for 4000 it's only four 'M'... what can be the reason for it to fail
and give me funny output (may be it would be better to get NULL in
such cases)?

thanks!..

--
Denis A. Doroshenko -- VAS/IN group engineer .-. _|_ |
[Omnitel Ltd., T.Sevcenkos st. 25, Vilnius, Lithuania] | | _ _ _ .| _ |
[Phone: +370 9863207 E-mail: d(dot)doroshenko(at)omnitel(dot)net] |_|| | || |||(/_|_

Browse pgsql-general by date

  From Date Subject
Next Message Stefano Bargioni 2000-12-21 09:09:50 Very slow select
Previous Message Alex Pilosov 2000-12-21 06:03:34 Re: pgsql/jdbc schema viewer needed