On Wed, Jun 9, 2010 at 6:32 AM, Mike Fowler <m...@mlfowler.com> wrote: > I've been working to improve the syntax of the XMLEXISTS function that I put > a patch forward for and have been attempting to get my head around how you > modify the grammar. I admit I'm not getting much anywhere probably as I > don't know bison but I'm starting to wonder if it's worth the pain given > recent comments on this list about not changing the grammar for JSON > support.
I think we're willing to change the parser to comply with the SQL standard, but not for add-on datatypes. > At this point I can see a way of implementing the following > abridged syntax (abridged as I'm not doing full XQuery support at this > stage) in a conventional plain function call by handling the > PG_FUNCTION_ARGS approriately, but would this acceptable? > > XMLEXISTS > ( > xpath_expression > [ > PASSING BY REF xml_expression [BY REF] > ] > ) I don't see how you're going to make this work without parser changes, and even if you can I think it would be too ugly to consider. > In case it isn't, and indeed to help me with the XML schema validation work > I'm doing, I would still like some help on how the grammar works. From what > I've greped and seen in the comments you need to modify the following files: > > - src/backend/parser/gram.y > - src/backend/parser/parse_expr.c > - src/backend/utils/ruleutils.c > - src/include/parser/kwlist.h > > From what I can tell, you add the keywords to the lists in gram.y and > kwlist.h. At the appropriate place in gram.y you define the syntax and pull > out what you need and stuff it into a node (in my case using the > makeXmlExpr). You then modify parse_expr.c and ruleutils.c to handle the new > values in the fields of the XmlExpr node. Assuming I'm right so far, the > step I'm failing to figure out is where the actual c function that > implements the function gets called/associated within the grammar. What am I > missing? Look at how the POSITION() pseudofunction is defined around gram.y line 9651. Essentially any special syntax of this type gets converted to a regular function call internally. So in your case I think there will be some function that gets called something ike this: xmlexists(xpath_expression, xml_expression) ...but the grammar can be modified to allow a different syntax for that function call. -- Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise Postgres Company -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers