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

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Shaun Cutts <shauncutts(at)factfiber(dot)com>
Cc: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: inevitability of to_date() when converting representations which don't represent whole timestamps
Date: 2017-03-30 15:55:55
Message-ID: CAKFQuwboSTceFLyhfyvzpcFuuG=gQJdjDrrKyTOtY7mvSh6Q+g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Mar 30, 2017 at 8:21 AM, Shaun Cutts <shauncutts(at)factfiber(dot)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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2017-03-30 16:04:39 Re: Tablespace Default Behavior
Previous Message harpagornis 2017-03-30 15:36:05 Re: Tablespace Default Behavior