Re: Remove inconsistent quotes from date_part error - Mailing list pgsql-hackers

From Michael Paquier
Subject Re: Remove inconsistent quotes from date_part error
Date
Msg-id YdKxEISD6nB7Kvq/@paquier.xyz
Whole thread Raw
In response to Remove inconsistent quotes from date_part error  (Nikhil Benesch <nikhil.benesch@gmail.com>)
Responses Re: Remove inconsistent quotes from date_part error
List pgsql-hackers
On Sun, Jan 02, 2022 at 11:47:32PM -0500, Nikhil Benesch wrote:
> The attached patch corrects a very minor typographical inconsistency
> when date_part is invoked with invalid units on time/timetz data vs
> timestamp/timestamptz/interval data.

Hmm, you are right that this is inconsistent, but I don't think that
what you are doing is completely correct either.  First, from what I
can see from the core code, we don't apply quotes to types in error
messages.  So your patch is going in the right direction.

However, there is a specific routine called format_type_be() aimed at
formatting type names for error strings.  If you switch to that, my
guess is that this makes the error messages of time/timetz and
timestamp/timestamptz/interval more consistent, while reducing the
effort of translation because we'd finish with the same base error
string, as of "%s units \"%s\" not recognized".

If we rework this part, we could even rework this error message more.
One suggestion I have would be "units of type %s not recognized", for
example.

> (If stuff like this is too minor to bother with, let me know and I'll
> hold off in the future... but since this was pointed out to me I can't
> unsee it.)

This usually comes down to a case-by-case analysis.  Now, in this
case, your suggestion looks right to me.
--
Michael

Attachment

pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: Use MaxLockMode in lock methods initialization
Next
From: Michael Paquier
Date:
Subject: Re: An obsolete comment of pg_stat_statements