Re: inevitability of to_date() when convertingrepresentations which don't represent whole timestamps - Mailing list pgsql-general

From David G. Johnston
Subject Re: inevitability of to_date() when convertingrepresentations which don't represent whole timestamps
Date
Msg-id CAKFQuwboSTceFLyhfyvzpcFuuG=gQJdjDrrKyTOtY7mvSh6Q+g@mail.gmail.com
Whole thread Raw
In response to inevitability of to_date() when converting representations whichdon't represent whole timestamps  (Shaun Cutts <shauncutts@factfiber.com>)
List pgsql-general
On Thu, Mar 30, 2017 at 8:21 AM, Shaun Cutts <shauncutts@factfiber.com> wrote:

My use case is to convert the name of a day to a day of the week number — now testing in English, but ultimately locale insensitive, so relying on to_date() to recognize the day in whatever the database locale is.


​Patches are welcome but I'd suggest that you not attempt to incorporate this behavior into to_date.  That function returns a date and what you want is a normalized integer (or, in reverse, a locale-specific string).

Both locale-specific so stable, not immutable:
day_of_week(text) : integer
day_of_week(integer) : text

Given that "select to_char(now(), 'Day')" works there should be few, if any, technical barriers to overcome.

You'd need to decide whether to support only the  "ISO 8601" numbering scheme (1-7) or to add additional arguments and/or function to number Sunday as 0 instead of 7.

David J.

pgsql-general by date:

Previous
From: harpagornis
Date:
Subject: Re: Tablespace Default Behavior
Next
From: Adrian Klaver
Date:
Subject: Re: Tablespace Default Behavior