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-16T18:51:34Z
Lists: pgsql-hackers
On Thu, Jan 16, 2020 at 1:37 PM David Steele <david@pgmasters.net> wrote: > I was starting to wonder if it wouldn't be simpler to go back to the > Postgres JSON parser and see if we can adapt it. I'm not sure that it > *is* simpler, but it would almost certainly be more acceptable. That is my feeling also. > So the idea here is that json.c will have the JSON SQL functions, > jsonb.c the JSONB SQL functions, and jsonapi.c the parser, and > jsonfuncs.c the utility functions? Uh, I think roughly that, yes. Although I can't claim to fully understand everything that's here. > This seems like a good first step. I wonder if the remainder of the SQL > json/jsonb functions should be moved to json.c/jsonb.c respectively? > > That does represent a lot of code churn though, so perhaps not worth it. I don't have an opinion on this right now. > Well, with the caveat that it doesn't work, it's less than I expected. > > Obviously ereport() is a pretty big deal and I agree with Michael > downthread that we should port this to the frontend code. Another possibly-attractive option would be to defer throwing the error: i.e. set some flags in the lex or parse state or something, and then just return. The caller notices the flags and has enough information to throw an error or whatever it wants to do. The reason I think this might be attractive is that it dodges the whole question of what exactly throwing an error is supposed to do in a world without transactions, memory contexts, resource owners, etc. However, it has some pitfalls of its own, like maybe being too much code churn or hurting performance in non-error cases. > It would also be nice to unify functions like PQmblen() and pg_mblen() > if possible. I don't see how to do that at the moment, but I agree that it would be nice if we can figure it out. > The next question in my mind is given the caveat that the error handing > is questionable in the front end, can we at least render/parse valid > JSON with the code? That's a real good question. Thanks for offering to test it; I think that would be very helpful. -- 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