diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-03-09 17:40:06 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-03-09 17:40:06 -0500 |
commit | a0de45185bf510fca9e237d9191e89391d118591 (patch) | |
tree | 889eb10d656581848ae3bc978b44d90634348808 /lib/sqlalchemy/dialects/postgresql/base.py | |
parent | c8a80e21301791fd4e1caf29ed8cadd40f617765 (diff) | |
download | sqlalchemy-a0de45185bf510fca9e237d9191e89391d118591.tar.gz |
Added support for Postgresql's traditional SUBSTRING
function syntax, renders as "SUBSTRING(x FROM y FOR z)"
when regular ``func.substring()`` is used.
Also in 0.7.11. Courtesy Gunnlaugur Por Briem.
[ticket:2676]
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/base.py')
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/base.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index a7a9e65ce..c59caff8d 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -1030,6 +1030,15 @@ class PGCompiler(compiler.SQLCompiler): field, self.process(expr)) + def visit_substring_func(self, func, **kw): + s = self.process(func.clauses.clauses[0], **kw) + start = self.process(func.clauses.clauses[1], **kw) + if len(func.clauses.clauses) > 2: + length = self.process(func.clauses.clauses[2], **kw) + return "SUBSTRING(%s FROM %s FOR %s)" % (s, start, length) + else: + return "SUBSTRING(%s FROM %s)" % (s, start) + class PGDDLCompiler(compiler.DDLCompiler): def get_column_specification(self, column, **kwargs): colspec = self.preparer.format_column(column) @@ -1042,8 +1051,7 @@ class PGDDLCompiler(compiler.DDLCompiler): ( isinstance(column.default, schema.Sequence) and column.default.optional - ) - ): + )): if isinstance(impl_type, sqltypes.BigInteger): colspec += " BIGSERIAL" else: |