inevitability of to_date() when converting representations which don't represent whole timestamps

From: Shaun Cutts <shauncutts(at)factfiber(dot)com>
To: pgsql-general(at)postgresql(dot)org
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Subject: inevitability of to_date() when converting representations which don't represent whole timestamps
Date: 2017-03-30 01:19:56
Message-ID: 5EEA4EE4-7D98-4C9D-9DAB-8D8F563DA5C6@factfiber.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

When being asked to convert a day of the week, the to_date() function returns the same day ('0001-01-01 BC’) no matter which day is converted:

# select to_date(‘Monday’, ‘Day’)
'0001-01-01 BC’

# select to_date(‘Tuesday’, ‘Day’)
'0001-01-01 BC’

However, if it were to return a date that was that day of the week, it could be inverted:

# select extract(dow from '0001-01-01 BC'::date); — this date should be the result of to_date(‘Sunday’, ‘Day’)
6

# select extract(dow from '0001-01-02 BC'::date); — this date should be the result of to_date(‘Monday’, ‘Day’)
0

….

David tells this is not a bug, but it still seems like a reasonable requirement on to_date() to me. Is there some reason why this isn’t possible?

Responses

Browse pgsql-general by date

  From Date Subject
Next Message harpagornis 2017-03-30 02:52:58 Re: Tablespace Default Behavior
Previous Message harpagornis 2017-03-30 01:11:54 Tablespace Default Behavior