"postgres_where" names still work with a
deprecation warning.
+ - "postgresql_where" now accepts SQL expressions which
+ can also include literals, which will be quoted as needed.
+
- The psycopg2 dialect now uses psycopg2's "unicode extension"
on all new connections, which allows all String/Text/etc.
types to skip the need to post-process bytestrings into
visitors.traverse(clause, {}, {'column':cols.add})
return cols
+def _quote_ddl_expr(element):
+ if isinstance(element, basestring):
+ element = element.replace("'", "''")
+ return "'%s'" % element
+ else:
+ return repr(element)
+
def expression_as_ddl(clause):
"""Given a SQL expression, convert for usage in DDL, such as
CREATE INDEX and CHECK CONSTRAINT.
"""
def repl(element):
if isinstance(element, expression._BindParamClause):
- return expression.literal_column(repr(element.value))
+ return expression.literal_column(_quote_ddl_expr(element.value))
elif isinstance(element, expression.ColumnClause) and \
element.table is not None:
return expression.column(element.name)
m = MetaData()
tbl = Table('testtbl', m, Column('data',Integer))
idx = Index('test_idx1', tbl.c.data, postgresql_where=and_(tbl.c.data > 5, tbl.c.data < 10))
+ idx = Index('test_idx1', tbl.c.data, postgresql_where=and_(tbl.c.data > 5, tbl.c.data < 10))
+
+ # test quoting and all that
+ idx2 = Index('test_idx2', tbl.c.data, postgresql_where=and_(tbl.c.data > 'a', tbl.c.data < "b's"))
self.assert_compile(schema.CreateIndex(idx),
"CREATE INDEX test_idx1 ON testtbl (data) WHERE data > 5 AND data < 10", dialect=postgresql.dialect())
+
+ self.assert_compile(schema.CreateIndex(idx2),
+ "CREATE INDEX test_idx2 ON testtbl (data) WHERE data > 'a' AND data < 'b''s'", dialect=postgresql.dialect())
@testing.uses_deprecated(r".*'postgres_where' argument has been renamed.*")
def test_old_create_partial_index(self):