.. changelog::
:version: 0.7.11
+ .. change::
+ :tags: feature, postgresql
+ :tickets: 2676
+
+ Added support for Postgresql's traditional SUBSTRING
+ function syntax, renders as "SUBSTRING(x FROM y FOR z)"
+ when regular ``func.substring()`` is used.
+ Courtesy Gunnlaugur Þór Briem.
+
.. change::
:tags: bug, tests
:tickets: 2669
* :ref:`correlation_context_specific`
+ .. change::
+ :tags: feature, postgresql
+ :tickets: 2676
+
+ 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 Þór Briem.
+
.. change::
:tags: feature, orm
:tickets: 2675
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)
(
isinstance(column.default, schema.Sequence) and
column.default.optional
- )
- ):
+ )):
if isinstance(impl_type, sqltypes.BigInteger):
colspec += " BIGSERIAL"
else:
'USING hash (data)',
dialect=postgresql.dialect())
+ def test_substring(self):
+ self.assert_compile(func.substring('abc', 1, 2),
+ 'SUBSTRING(%(substring_1)s FROM %(substring_2)s '
+ 'FOR %(substring_3)s)')
+ self.assert_compile(func.substring('abc', 1),
+ 'SUBSTRING(%(substring_1)s FROM %(substring_2)s)')
+
+
def test_extract(self):
t = table('t', column('col1', DateTime), column('col2', Date),