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

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: Pg Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Amit Langote <amitlangote09(at)gmail(dot)com>
Subject: SQLJSON: errmsg(" .. should ...") -> must
Date: 2025-01-13 18:19:34
Message-ID: 202501131819.26ors7oouafu@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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)

Attachment Content-Type Size
0001-error-messages-must-use-must-rather-than-should.patch text/x-diff 6.8 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message vignesh C 2025-01-13 18:21:47 Re: Pgoutput not capturing the generated columns
Previous Message Dean Rasheed 2025-01-13 18:15:15 Re: Virtual generated columns