summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/postgresql/base.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/base.py')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/base.py59
1 files changed, 58 insertions, 1 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py
index 22c66dbbb..0793ca3ab 100644
--- a/lib/sqlalchemy/dialects/postgresql/base.py
+++ b/lib/sqlalchemy/dialects/postgresql/base.py
@@ -598,6 +598,51 @@ class OID(sqltypes.TypeEngine):
__visit_name__ = "OID"
+class LTREE(sqltypes.TypeEngine):
+
+ """Postgresql LTREE type.
+ """
+
+ class Comparator(sqltypes.Concatenable.Comparator):
+
+ def ancestor_of(self, other):
+ if isinstance(other, list):
+ return self.expr.op('@>')(expression.cast(other, ARRAY(LTREE)))
+ else:
+ return self.expr.op('@>')(other)
+
+ def descendant_of(self, other):
+ if isinstance(other, list):
+ return self.expr.op('<@')(expression.cast(other, ARRAY(LTREE)))
+ else:
+ return self.expr.op('<@')(other)
+
+ def lquery(self, other):
+ if isinstance(other, list):
+ return self.expr.op('?')(expression.cast(other, ARRAY(LQUERY)))
+ else:
+ return self.expr.op('~')(other)
+
+ def ltxtquery(self, other):
+ return self.expr.op('@')(other)
+
+ comparator_factory = Comparator
+
+ __visit_name__ = 'LTREE'
+
+PGLTree = LTREE
+
+
+class LQUERY(sqltypes.TypeEngine):
+ __visit_name__ = 'LQUERY'
+PGLQuery = LQUERY
+
+
+class LTXTQUERY(sqltypes.TypeEngine):
+ __visit_name__ = 'LTXTQUERY'
+PGLTxtQuery = LTXTQUERY
+
+
class TIMESTAMP(sqltypes.TIMESTAMP):
def __init__(self, timezone=False, precision=None):
@@ -1360,7 +1405,10 @@ ischema_names = {
'interval': INTERVAL,
'interval year to month': INTERVAL,
'interval day to second': INTERVAL,
- 'tsvector': TSVECTOR
+ 'tsvector': TSVECTOR,
+ 'ltree': LTREE,
+ 'lquery': LQUERY,
+ 'ltxtquery': LTXTQUERY
}
@@ -1782,6 +1830,15 @@ class PGTypeCompiler(compiler.GenericTypeCompiler):
if type_.dimensions
is not None else 1))
+ def visit_LTREE(self, type_, **kw):
+ return 'LTREE'
+
+ def visit_LQUERY(self, type_, **kw):
+ return 'LQUERY'
+
+ def visit_LTXTQUERY(self, type_, **kw):
+ return 'LTXTQUERY'
+
class PGIdentifierPreparer(compiler.IdentifierPreparer):