"upsert.quantity FROM upsert))",
)
+ eq_(insert.compile().isinsert, True)
+
def test_anon_update_cte(self):
orders = table("orders", column("region"))
stmt = (
"SELECT anon_1.region FROM anon_1",
)
+ eq_(stmt.select().compile().isupdate, False)
+
def test_anon_insert_cte(self):
orders = table("orders", column("region"))
stmt = (
"VALUES (:region) RETURNING orders.region) "
"SELECT anon_1.region FROM anon_1",
)
+ eq_(stmt.select().compile().isinsert, False)
def test_pg_example_one(self):
products = table("products", column("id"), column("date"))
"INSERT INTO products_log (id, date) "
"SELECT moved_rows.id, moved_rows.date FROM moved_rows",
)
+ eq_(stmt.compile().isinsert, True)
+ eq_(stmt.compile().isdelete, False)
+
+ def test_pg_example_one_select_only(self):
+ products = table("products", column("id"), column("date"))
+
+ moved_rows = (
+ products.delete()
+ .where(
+ and_(products.c.date >= "dateone", products.c.date < "datetwo")
+ )
+ .returning(*products.c)
+ .cte("moved_rows")
+ )
+
+ stmt = moved_rows.select()
+
+ self.assert_compile(
+ stmt,
+ "WITH moved_rows AS "
+ "(DELETE FROM products WHERE products.date >= :date_1 "
+ "AND products.date < :date_2 "
+ "RETURNING products.id, products.date) "
+ "SELECT moved_rows.id, moved_rows.date FROM moved_rows",
+ )
+
+ eq_(stmt.compile().isdelete, False)
def test_pg_example_two(self):
products = table("products", column("id"), column("price"))
"SELECT t.id, t.price "
"FROM t",
)
+ eq_(stmt.compile().isupdate, False)
def test_pg_example_three(self):
"SELECT pd.id, pd.price "
"FROM pd",
)
+ eq_(stmt.compile().isinsert, False)
def test_update_pulls_from_cte(self):
products = table("products", column("id"), column("price"))
"UPDATE products SET id=:id, price=:price FROM pd "
"WHERE products.price = pd.price",
)
+ eq_(stmt.compile().isupdate, True)
def test_standalone_function(self):
a = table("a", column("x"))