On 2023-Oct-06, Andres Freund wrote: > > +json_query_behavior: > > + ERROR_P { $$ = > > makeJsonBehavior(JSON_BEHAVIOR_ERROR, NULL, @1); } > > + | NULL_P { $$ = > > makeJsonBehavior(JSON_BEHAVIOR_NULL, NULL, @1); } > > + | DEFAULT a_expr { $$ = > > makeJsonBehavior(JSON_BEHAVIOR_DEFAULT, $2, @1); } > > + | EMPTY_P ARRAY { $$ = > > makeJsonBehavior(JSON_BEHAVIOR_EMPTY_ARRAY, NULL, @1); } > > + | EMPTY_P OBJECT_P { $$ = > > makeJsonBehavior(JSON_BEHAVIOR_EMPTY_OBJECT, NULL, @1); } > > + /* non-standard, for Oracle compatibility only */ > > + | EMPTY_P { $$ = > > makeJsonBehavior(JSON_BEHAVIOR_EMPTY_ARRAY, NULL, @1); } > > + ; > > > +json_exists_behavior: > > + ERROR_P { $$ = > > makeJsonBehavior(JSON_BEHAVIOR_ERROR, NULL, @1); } > > + | TRUE_P { $$ = > > makeJsonBehavior(JSON_BEHAVIOR_TRUE, NULL, @1); } > > + | FALSE_P { $$ = > > makeJsonBehavior(JSON_BEHAVIOR_FALSE, NULL, @1); } > > + | UNKNOWN { $$ = > > makeJsonBehavior(JSON_BEHAVIOR_UNKNOWN, NULL, @1); } > > + ; > > + > > +json_value_behavior: > > + NULL_P { $$ = > > makeJsonBehavior(JSON_BEHAVIOR_NULL, NULL, @1); } > > + | ERROR_P { $$ = > > makeJsonBehavior(JSON_BEHAVIOR_ERROR, NULL, @1); } > > + | DEFAULT a_expr { $$ = > > makeJsonBehavior(JSON_BEHAVIOR_DEFAULT, $2, @1); } > > + ; > > This also seems like it could use some dedup.
Yeah, I was looking at this the other day and thinking that we should just have a single json_behavior that's used by all these productions; at runtime we can check whether a value has been used that's improper for that particular node, and error out with a syntax error or some such. Other parts of the grammar definitely needs more work, too. It appears to me that they were written by looking at what the standard says, more or less literally. -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/ "Someone said that it is at least an order of magnitude more work to do production software than a prototype. I think he is wrong by at least an order of magnitude." (Brian Kernighan)