[PATCH] Re: Adding XMLEXISTS to the grammar

Mike Fowler <mike@mlfowler.com>

From: Mike Fowler <mike@mlfowler.com>
To: Robert Haas <robertmhaas@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2010-06-27T16:04:47Z
Lists: pgsql-hackers

Attachments

>> and finally in pg_proc.h I have:
>>
>> DATA(insert OID = 3037 (  xmlexists     PGNSP PGUID 12 1 0 0 f f f t f i 3 0
>> 16 "25 142" _null_ _null_ _null_ _null_ xml_exists _null_ _null_ _null_ ));
>> DESCR("evaluate XPath expression in a boolean context");
>>     
> It looks like the pg_proc entry is creating an SQL function called
> xmlexists referencing a C function called xml_exists, and the gram.y
> changes want there to be an SQL function called xml_exists.  I think
> you should rip out all the catalog and parser changes for starters,
> and just try to get it working as a regular old function.  Once you
> have that working, you can add the syntax support back in.  I'd
> suggest making the C and SQL function names the same as each other,
> but different from the keyword you're planning to use (xmlexists).
>   
Thanks again for your help Robert, turns out the fault was in the 
pg_proc entry (the 3 up there should've been a two!). Once I took the 
grammar out it was quickly obvious where I'd gone wrong.

Attached is a patch with the revised XMLEXISTS function, complete with 
grammar support and regression tests. The implemented grammar is:

XMLEXISTS ( xpath_expression PASSING BY REF xml_value [BY REF] )

Though the full grammar makes everything after the xpath_expression 
optional, I've left it has mandatory simply to avoid lots of rework of 
the function (would need new null checks, memory handling would need 
reworking).

-- 
Mike Fowler
Registered Linux user: 379787