summaryrefslogtreecommitdiff
path: root/test/sql/test_compiler.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-08-20 17:04:25 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2012-08-20 17:04:25 -0400
commitaef0c7a903464f4e05496c69ff4e78d41239c220 (patch)
tree716afd20faf81a90ca734b946be619549f8d4384 /test/sql/test_compiler.py
parentce1b80ad08f58ea18914a93805754a5e19a85abb (diff)
downloadsqlalchemy-aef0c7a903464f4e05496c69ff4e78d41239c220.tar.gz
- [feature] The Core oeprator system now includes
the `getitem` operator, i.e. the bracket operator in Python. This is used at first to provide index and slice behavior to the Postgresql ARRAY type, and also provides a hook for end-user definition of custom __getitem__ schemes which can be applied at the type level as well as within ORM-level custom operator schemes. Note that this change has the effect that descriptor-based __getitem__ schemes used by the ORM in conjunction with synonym() or other "descriptor-wrapped" schemes will need to start using a custom comparator in order to maintain this behavior. - [feature] postgresql.ARRAY now supports indexing and slicing. The Python [] operator is available on all SQL expressions that are of type ARRAY; integer or simple slices can be passed. The slices can also be used on the assignment side in the SET clause of an UPDATE statement by passing them into Update.values(); see the docs for examples. - [feature] Added new "array literal" construct postgresql.array(). Basically a "tuple" that renders as ARRAY[1,2,3].
Diffstat (limited to 'test/sql/test_compiler.py')
-rw-r--r--test/sql/test_compiler.py78
1 files changed, 15 insertions, 63 deletions
diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py
index 70ff5740a..7ad14f283 100644
--- a/test/sql/test_compiler.py
+++ b/test/sql/test_compiler.py
@@ -2402,69 +2402,6 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL):
checkparams={'date_1':datetime.date(2006,6,1),
'date_2':datetime.date(2006,6,5)})
- def test_operator_precedence(self):
- table = Table('op', metadata,
- Column('field', Integer))
- self.assert_compile(table.select((table.c.field == 5) == None),
- "SELECT op.field FROM op WHERE (op.field = :field_1) IS NULL")
- self.assert_compile(table.select((table.c.field + 5) == table.c.field),
- "SELECT op.field FROM op WHERE op.field + :field_1 = op.field")
- self.assert_compile(table.select((table.c.field + 5) * 6),
- "SELECT op.field FROM op WHERE (op.field + :field_1) * :param_1")
- self.assert_compile(table.select((table.c.field * 5) + 6),
- "SELECT op.field FROM op WHERE op.field * :field_1 + :param_1")
- self.assert_compile(table.select(5 + table.c.field.in_([5,6])),
- "SELECT op.field FROM op WHERE :param_1 + (op.field IN (:field_1, :field_2))")
- self.assert_compile(table.select((5 + table.c.field).in_([5,6])),
- "SELECT op.field FROM op WHERE :field_1 + op.field IN (:param_1, :param_2)")
- self.assert_compile(table.select(not_(and_(table.c.field == 5, table.c.field == 7))),
- "SELECT op.field FROM op WHERE NOT (op.field = :field_1 AND op.field = :field_2)")
- self.assert_compile(table.select(not_(table.c.field == 5)),
- "SELECT op.field FROM op WHERE op.field != :field_1")
- self.assert_compile(table.select(not_(table.c.field.between(5, 6))),
- "SELECT op.field FROM op WHERE NOT (op.field BETWEEN :field_1 AND :field_2)")
- self.assert_compile(table.select(not_(table.c.field) == 5),
- "SELECT op.field FROM op WHERE (NOT op.field) = :param_1")
- self.assert_compile(table.select((table.c.field == table.c.field).between(False, True)),
- "SELECT op.field FROM op WHERE (op.field = op.field) BETWEEN :param_1 AND :param_2")
- self.assert_compile(table.select(between((table.c.field == table.c.field), False, True)),
- "SELECT op.field FROM op WHERE (op.field = op.field) BETWEEN :param_1 AND :param_2")
-
- def test_associativity(self):
- f = column('f')
- self.assert_compile( f - f, "f - f" )
- self.assert_compile( f - f - f, "(f - f) - f" )
-
- self.assert_compile( (f - f) - f, "(f - f) - f" )
- self.assert_compile( (f - f).label('foo') - f, "(f - f) - f" )
-
- self.assert_compile( f - (f - f), "f - (f - f)" )
- self.assert_compile( f - (f - f).label('foo'), "f - (f - f)" )
-
- # because - less precedent than /
- self.assert_compile( f / (f - f), "f / (f - f)" )
- self.assert_compile( f / (f - f).label('foo'), "f / (f - f)" )
-
- self.assert_compile( f / f - f, "f / f - f" )
- self.assert_compile( (f / f) - f, "f / f - f" )
- self.assert_compile( (f / f).label('foo') - f, "f / f - f" )
-
- # because / more precedent than -
- self.assert_compile( f - (f / f), "f - f / f" )
- self.assert_compile( f - (f / f).label('foo'), "f - f / f" )
- self.assert_compile( f - f / f, "f - f / f" )
- self.assert_compile( (f - f) / f, "(f - f) / f" )
-
- self.assert_compile( ((f - f) / f) - f, "(f - f) / f - f")
- self.assert_compile( (f - f) / (f - f), "(f - f) / (f - f)")
-
- # higher precedence
- self.assert_compile( (f / f) - (f / f), "f / f - f / f")
-
- self.assert_compile( (f / f) - (f - f), "f / f - (f - f)")
- self.assert_compile( (f / f) / (f - f), "(f / f) / (f - f)")
- self.assert_compile( f / (f / (f - f)), "f / (f / (f - f))")
-
def test_delayed_col_naming(self):
my_str = Column(String)
@@ -2838,6 +2775,21 @@ class CRUDTest(fixtures.TestBase, AssertsCompiledSQL):
"mytable WHERE mytable.myid = :myid_1",
params = {table1.c.name:'fred'})
+ def test_update_to_expression(self):
+ """test update from an expression.
+
+ this logic is triggered currently by a left side that doesn't
+ have a key. The current supported use case is updating the index
+ of a Postgresql ARRAY type.
+
+ """
+ expr = func.foo(table1.c.myid)
+ assert not hasattr(expr, "key")
+ self.assert_compile(
+ table1.update().values({expr: 'bar'}),
+ "UPDATE mytable SET foo(myid)=:param_1"
+ )
+
def test_correlated_update(self):
# test against a straight text subquery
u = update(table1, values = {