- edited description
ExcludeConstraint fails to quote column names when necessary.
Given this model:
class MyModel(Base):
__tablename__ = 'my_model'
id = Column(Integer, primary_key=True)
period = Column(TSRANGE())
group = Column(String)
__table_args__ = [ExcludeConstraint(('period', '&&'), ('group', '='))]
create_all
will barf with a syntax error at or near "group"
Comments (9)
-
reporter -
reporter - edited description
-
repo owner why string name? why not (also fixed the args format):
class MyModel(Base): __tablename__ = 'my_model' id = Column(Integer, primary_key=True) period = Column(TSRANGE()) group = Column(String) # __table_args__ = (ExcludeConstraint(('period', '&&'), ('group', '=')), ) __table_args__ = (ExcludeConstraint((period, '&&'), (group, '=')), )
if you put a string here I don't know that this is giving SQLAlchemy enough context to know this is a single column name that is quotable.
-
repo owner OK, it says in the docstring for elements, "column name", fine, let me confirm that
-
repo owner derp, nope, our docstring is wrong, that string can be any SQL expression:
"The EXCLUDE clause defines an exclusion constraint, which guarantees that if any two rows are compared on the specified column(s) or expression(s) using the specified operator(s),"
and this is accepted:
class MyModel(Base): __tablename__ = 'my_model' id = Column(Integer, primary_key=True) period = Column(TSRANGE()) group = Column(String) __table_args__ = (ExcludeConstraint((period, '&&'), (func.lower(group), '=')), )
-
repo owner e.g.
CREATE TABLE my_model ( id SERIAL NOT NULL, period TSRANGE, "group" VARCHAR, PRIMARY KEY (id), EXCLUDE USING gist (period WITH &&, lower("group") WITH =) )
fails for me for "gist" reasons but not syntactically.
-
repo owner - changed status to resolved
- document that "column" and "where" are arbitrary SQL expressions
for ExcludeConstraint, if string is used then quoting must
be applied manually. fixes
#3899
Change-Id: I5885c90179e4056b84fc4776464bba7c8c70a80a
→ <<cset a24801ae8de4>>
-
repo owner - document that "column" and "where" are arbitrary SQL expressions
for ExcludeConstraint, if string is used then quoting must
be applied manually. fixes
#3899
Change-Id: I5885c90179e4056b84fc4776464bba7c8c70a80a (cherry picked from commit a24801ae8de469f1e78bdb0c02b28de263c2310e)
→ <<cset 00f2e31f210e>>
- document that "column" and "where" are arbitrary SQL expressions
for ExcludeConstraint, if string is used then quoting must
be applied manually. fixes
-
repo owner see
#3454where we actually allowed non-col expressions to be supported. - Log in to comment