SQLJSON: errmsg(" .. should ...") -> must

Started by Alvaro Herreraover 1 year ago3 messageshackers
Jump to latest
#1Alvaro Herrera
alvherre@2ndquadrant.com

Hi

There's a few recent SQL/JSON error messages in which we say something
"should" be something else. We avoid this, so I think we shouldn't use
it here either. (There's also wparser_def.c which uses "should" in that
way, and I think it's there just because it's a dark unvisited corner
that's been wrong for awhile.)

While at it, I wasn't sure about the following:

errmsg("JSON path expression in JSON_QUERY must return single item without wrapper")

It seems a strange phrasing: I read it as meaning that the code is
expecting that the path expression returns a single item and no wrapper
around it. But what it really means is that if the user specifies that
no wrapping is required, then a single item must be returned (so the
"without wrapper" applies to the JSON_QUERY, not to the single item).
I find this confusing, so I'd change it like this:

errmsg("JSON path expression in JSON_QUERY must return single item when no wrapper is requested")

which I think is clearer.

Patch attached, for branch master. This applies to 17 cleanly, so I
lean towards backpatching it all there. (The wparser_def.c changes go
much longer back, but I see little point in backpatching those any
further.)

--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
"Postgres is bloatware by design: it was built to house
PhD theses." (Joey Hellerstein, SIGMOD annual conference 2002)

Attachments:

0001-error-messages-must-use-must-rather-than-should.patchtext/x-diff; charset=utf-8Download+15-16
#2Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Alvaro Herrera (#1)
Re: SQLJSON: errmsg(" .. should ...") -> must

On 2025-Jan-13, Alvaro Herrera wrote:

There's a few recent SQL/JSON error messages in which we say something
"should" be something else. We avoid this, so I think we shouldn't use
it here either.

Pushed.

--
Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/

#3Amit Langote
Langote_Amit_f8@lab.ntt.co.jp
In reply to: Alvaro Herrera (#2)
Re: SQLJSON: errmsg(" .. should ...") -> must

On Tue, Jan 21, 2025 at 11:42 PM Alvaro Herrera <alvherre@alvh.no-ip.org> wrote:

On 2025-Jan-13, Alvaro Herrera wrote:

There's a few recent SQL/JSON error messages in which we say something
"should" be something else. We avoid this, so I think we shouldn't use
it here either.

Pushed.

Sorry Alvaro for not noticing sooner.

I looked at db19a5061ce and it all looks fine to me.

--
Thanks, Amit Langote