How to control parsing of date string in PostgreSQL XMLTABLE COLUMNS

32 views Asked by At

Is there a way to parse the value '2024-01-17-05:00' as a date in the COLUMNS section of a XMLTABLE?

My code is otherwise working and looks like this (leaving out surrounding code and some details):

with data as (
    SELECT xml_file_name, xml_file_content as xml_content
    FROM xml_text
)
SELECT * from data , 
      XMLTABLE(XMLNAMESPACES( ... ),
                 xpath_value
                    PASSING (xml_content)
                    COLUMNS cn_issue_date date path 'IssueDate',

it fails when parsing the value '2024-01-17-05:00' and gives the error: "invalid input syntax for type date: "2024-01-17-05:00"

Among other ideas, I tried this:

 cn_issue_date date to_date((path 'cbc:IssueDate'), 'YYYY-MM-DD'),

but it fails with " unrecognized column option "to_date""

I hope that I can use the XML functions of PostgreSQL to handle the parsing, so I don't have to write a program to find, check and convert all date values in the XML file before loading it into the database.

0

There are 0 answers