Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/41.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added PostgreSQL support for core SQL/XML standard expressions, including XML construction, serialization, aggregation, and query/table expression capability declarations.
84 changes: 83 additions & 1 deletion src/rhosocial/activerecord/backend/impl/postgres/dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from rhosocial.activerecord.backend.dialect.base import SQLDialectBase
from rhosocial.activerecord.backend.dialect.mixins import (
SQLXMLMixin,
CollationMixin,
CTEMixin,
FilterClauseMixin,
Expand Down Expand Up @@ -43,6 +44,12 @@
ConstraintMixin,
)
from rhosocial.activerecord.backend.dialect.protocols import (
SQLXMLSupport,
SQLXMLParsingSupport,
SQLXMLSerializationSupport,
SQLXMLConstructionSupport,
SQLXMLAggregationSupport,
SQLXMLQueryingSupport,
CollationSupport,
CTESupport,
FilterClauseSupport,
Expand Down Expand Up @@ -226,6 +233,7 @@

class PostgresDialect(
SQLDialectBase,
SQLXMLMixin,
CollationMixin,
SetOperationMixin,
TruncateMixin,
Expand Down Expand Up @@ -316,6 +324,12 @@ class PostgresDialect(
PostgresStoredProcedureMixin,
PostgresAdvisoryLockMixin,
# Protocol supports
SQLXMLSupport,
SQLXMLParsingSupport,
SQLXMLSerializationSupport,
SQLXMLConstructionSupport,
SQLXMLAggregationSupport,
SQLXMLQueryingSupport,
CollationSupport,
SetOperationSupport,
TruncateSupport,
Expand Down Expand Up @@ -471,6 +485,58 @@ def get_server_version(self) -> Tuple[int, int, int]:
"""Return the PostgreSQL version this dialect is configured for."""
return self.version

def supports_xmlparse(self) -> bool:
"""XMLPARSE is supported since PostgreSQL 8.3."""
return self.version >= (8, 3, 0)

def supports_xmlserialize(self) -> bool:
"""XMLSERIALIZE is supported since PostgreSQL 8.3."""
return self.version >= (8, 3, 0)

def supports_xmlelement(self) -> bool:
"""XMLELEMENT is supported since PostgreSQL 8.3."""
return self.version >= (8, 3, 0)

def supports_xmlattributes(self) -> bool:
"""XMLATTRIBUTES is supported since PostgreSQL 8.3."""
return self.version >= (8, 3, 0)

def supports_xmlforest(self) -> bool:
"""XMLFOREST is supported since PostgreSQL 8.3."""
return self.version >= (8, 3, 0)

def supports_xmlconcat(self) -> bool:
"""XMLCONCAT is supported since PostgreSQL 8.3."""
return self.version >= (8, 3, 0)

def supports_xmlcomment(self) -> bool:
"""XMLCOMMENT is supported since PostgreSQL 8.3."""
return self.version >= (8, 3, 0)

def supports_xmlpi(self) -> bool:
"""XMLPI is supported since PostgreSQL 8.3."""
return self.version >= (8, 3, 0)

def supports_xmlroot(self) -> bool:
"""XMLROOT is supported since PostgreSQL 8.3."""
return self.version >= (8, 3, 0)

def supports_xmlagg(self) -> bool:
"""XMLAGG is supported since PostgreSQL 8.3."""
return self.version >= (8, 3, 0)

def supports_xmlquery(self) -> bool:
"""PostgreSQL does not implement standard SQL/XML XMLQUERY."""
return False

def supports_xmlexists(self) -> bool:
"""XMLEXISTS is supported since PostgreSQL 8.4."""
return self.version >= (8, 4, 0)

def supports_xmltable(self) -> bool:
"""XMLTABLE is supported since PostgreSQL 10."""
return self.version >= (10, 0, 0)

def supports_collate_expression(self) -> bool:
"""PostgreSQL supports expression-level COLLATE."""
return True
Expand Down Expand Up @@ -1637,9 +1703,25 @@ def supports_functions(self) -> Dict[str, "FunctionSupportInfo"]:
)
from rhosocial.activerecord.backend.impl.postgres import functions as postgres_functions

expression_constructors = {
"xmlagg",
"xmlattributes",
"xmlcomment",
"xmlconcat",
"xmlelement",
"xmlexists",
"xmlforest",
"xmlparse",
"xmlpi",
"xmlquery",
"xmlroot",
"xmlserialize",
"xmltable",
}
result: Dict[str, FunctionSupportInfo] = {}
for func_name in core_functions:
result[func_name] = self._check_function_support(func_name)
if func_name not in expression_constructors:
result[func_name] = self._check_function_support(func_name)

postgres_funcs = getattr(postgres_functions, "__all__", [])
for func_name in postgres_funcs:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""SQL/XML expression examples for PostgreSQL."""
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<item id="1">alpha</item>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<item id="2">beta</item>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<root>
<item id="1">alpha</item>
<item id="2">beta</item>
</root>
Loading
Loading