Re: making the backend's json parser work in frontend code
Robert Haas <robertmhaas@gmail.com>
From: Robert Haas <robertmhaas@gmail.com>
To: David Steele <david@pgmasters.net>
Cc: "pgsql-hackers@postgresql.org" <pgsql-hackers@postgresql.org>
Date: 2020-01-22T18:53:08Z
Lists: pgsql-hackers
Attachments
- v3-0001-Adjust-src-include-utils-jsonapi.h-so-it-s-not-ba.patch (application/octet-stream) patch v3-0001
- v3-0002-Split-JSON-lexer-parser-from-json-data-type-suppo.patch (application/octet-stream) patch v3-0002
- v3-0005-Move-some-code-from-jsonapi.c-to-jsonfuncs.c.patch (application/octet-stream) patch v3-0005
- v3-0004-Adjust-pg_parse_error-so-that-it-does-not-depend-.patch (application/octet-stream) patch v3-0004
- v3-0003-Remove-jsonapi.c-s-lex_accept.patch (application/octet-stream) patch v3-0003
On Tue, Jan 21, 2020 at 7:23 PM Robert Haas <robertmhaas@gmail.com> wrote: > On Tue, Jan 21, 2020 at 5:34 PM David Steele <david@pgmasters.net> wrote: > > Though, throw_a_json_error() is not my favorite name. Perhaps > > json_ereport()? > > That name was deliberately chosen to be dumb, with the thought that > readers would understand it was to be replaced at some point before > this was final. It sounds like it wasn't quite dumb enough to make > that totally clear. Here is a new version that is, I think, much closer what I would consider a final form. 0001 through 0003 are as before, and unless somebody says pretty soon that they see a problem with those or want more time to review them, I'm going to commit them; David Steele has endorsed all three, and they seem like independently sensible cleanups. 0004 is a substantially cleaned up version of the patch to make the JSON parser return a result code rather than throwing errors. Names have been fixed, interfaces have been tidied up, and the thing is better integrated with the surrounding code. I would really like comments, if anyone has them, on whether this approach is acceptable. 0005 builds on 0004 by moving three functions from jsonapi.c to jsonfuncs.c. With that done, jsonapi.c has minimal remaining dependencies on the backend environment. It would still need a substitute for elog(ERROR, "some internal thing is broken"); I'm thinking of using pg_log_fatal() for that case. It would also need a fix for the problem that pg_mblen() is not available in the front-end environment. I don't know what to do about that yet exactly, but it doesn't seem unsolvable. The frontend environment just needs to know which encoding to use, and needs a way to call PQmblen() rather than pg_mblen(). One problem with this whole thing that I just realized is that the backup manifest file needs to store filenames, and we don't know that the filenames we get from the filesystem are going to be valid in UTF-8 (or, for that matter, any other encoding we might want to choose). So, just deciding that the backup manifest is always UTF-8 doesn't seem like an option, unless we stick another level of escaping in there somehow. Strictly as a theoretical matter, someone might consider this a reason why using JSON for the backup manifest is not necessarily the best fit, but since other arguments to that effect have gotten me nowhere until now, I will instead request that someone suggest to me how I ought to handle that problem. Thanks, -- Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company
Commits
-
Add jsonapi.c to Mkvcbuild.pm's @pgcommonallfiles.
- 006b9dcad419 13.0 landed
-
Move jsonapi.c and jsonapi.h to src/common.
- beb4699091e9 13.0 landed
-
Move some code from jsonapi.c to jsonfuncs.c.
- 73ce2a03f30b 13.0 landed
-
Adjust pg_parse_json() so that it does not directly ereport().
- 1f3a021730be 13.0 landed
-
Remove jsonapi.c's lex_accept().
- 530609aa4263 13.0 landed
-
Split JSON lexer/parser from 'json' data type support.
- 11b5e3e35d39 13.0 landed
-
Rationalize code placement between wchar.c, encnames.c, and mbutils.c.
- 5afaa2e42655 13.0 landed
-
Move wchar.c and encnames.c to src/common/.
- e6afa8918c46 13.0 landed
-
Update header comments for wchar.c and encnames.c.
- 3d4cb5d6c180 13.0 landed
-
Make StringInfo available to frontend code.
- 26aaf97b683d 13.0 cited
-
Use SASLprep to normalize passwords for SCRAM authentication.
- 60f11b87a234 10.0 cited