[PATCH] Add support to table_to_xmlschema regex when timestamp has time zone
Hello,I added a patch to fix table_to_xmlschema, could you point me how to add a unit test to that?
Attachments:
0001-fix-table_to_xmlschema-regex-for-timestamp-with-time.patchtext/x-patch; name=0001-fix-table_to_xmlschema-regex-for-timestamp-with-time.patchDownload
From 24768b689638fc35edcdb378735ae2505315a151 Mon Sep 17 00:00:00 2001
From: Renan Lopes <renan.lopes@datarisk.io>
Date: Fri, 18 Feb 2022 14:36:30 -0300
Subject: [PATCH] fix: table_to_xmlschema regex for timestamp with time zone
---
src/backend/utils/adt/xml.c | 4 ++--
src/test/regress/sql/xmlmap.sql | 7 +++++++
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c
index 51773db..801ad8f 100644
--- a/src/backend/utils/adt/xml.c
+++ b/src/backend/utils/adt/xml.c
@@ -3659,7 +3659,7 @@ map_sql_type_to_xmlschema_type(Oid typeoid, int typmod)
case TIMEOID:
case TIMETZOID:
{
- const char *tz = (typeoid == TIMETZOID ? "(+|-)\\p{Nd}{2}:\\p{Nd}{2}" : "");
+ const char *tz = (typeoid == TIMETZOID ? "(\\+|-)\\p{Nd}{2}:\\p{Nd}{2}" : "");
if (typmod == -1)
appendStringInfo(&result,
@@ -3682,7 +3682,7 @@ map_sql_type_to_xmlschema_type(Oid typeoid, int typmod)
case TIMESTAMPOID:
case TIMESTAMPTZOID:
{
- const char *tz = (typeoid == TIMESTAMPTZOID ? "(+|-)\\p{Nd}{2}:\\p{Nd}{2}" : "");
+ const char *tz = (typeoid == TIMESTAMPTZOID ? "(\\+|-)\\p{Nd}{2}:\\p{Nd}{2}" : "");
if (typmod == -1)
appendStringInfo(&result,
diff --git a/src/test/regress/sql/xmlmap.sql b/src/test/regress/sql/xmlmap.sql
index fde1b9e..13407ee 100644
--- a/src/test/regress/sql/xmlmap.sql
+++ b/src/test/regress/sql/xmlmap.sql
@@ -55,3 +55,10 @@ CREATE TABLE testxmlschema.test3
SELECT xmlforest(c1, c2, c3, c4) FROM testxmlschema.test3;
SELECT table_to_xml('testxmlschema.test3', true, true, '');
+
+
+-- test datetime with time zone
+
+CREATE TABLE testxmlschema.test4 (a timestamp with time zone default current_timestamp);
+SELECT table_to_xmlschema('testxmlschema.test4', true, true, '');
+
--
2.35.1
On Fri, Feb 18, 2022, at 2:47 PM, Renan Soares Lopes wrote:
Hello,
I added a patch to fix table_to_xmlschema, could you point me how to add a unit test to that?
You should edit src/test/regress/expected/xmlmap.out. In this case, you should
also modify src/test/regress/expected/xmlmap_1.out that the output from this
test when you build without libxml support. Run 'make check' to test your fix
after building with/without libxml support.
Regarding this fix, it looks good to me. FWIW, character class escape is
defined here [1]https://www.w3.org/TR/xmlschema11-2/#cces.
[1]: https://www.w3.org/TR/xmlschema11-2/#cces
--
Euler Taveira
EDB https://www.enterprisedb.com/
"Euler Taveira" <euler@eulerto.com> writes:
On Fri, Feb 18, 2022, at 2:47 PM, Renan Soares Lopes wrote:
I added a patch to fix table_to_xmlschema, could you point me how to add a unit test to that?
You should edit src/test/regress/expected/xmlmap.out. In this case, you should
also modify src/test/regress/expected/xmlmap_1.out that the output from this
test when you build without libxml support. Run 'make check' to test your fix
after building with/without libxml support.
Regarding this fix, it looks good to me. FWIW, character class escape is
defined here [1].
LGTM too. Pushed after rethinking the test case a bit.
regards, tom lane