summaryrefslogtreecommitdiff
path: root/test/sql
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2022-09-20 02:34:31 +0000
committerGerrit Code Review <gerrit@ci3.zzzcomputing.com>2022-09-20 02:34:31 +0000
commit214d1ad7c38deebec6547da22b99c0a4804bf820 (patch)
tree730b18fefc3dfd0ca4c39ef20c14c0e9fec0eb68 /test/sql
parentaab6005dda456c8647192cd62064c67e6a5558ff (diff)
parentc9af2ebf5e5d288aea3a3a26bdf950e08ac4f927 (diff)
downloadsqlalchemy-214d1ad7c38deebec6547da22b99c0a4804bf820.tar.gz
Merge "break out text() from TextualSelect for col matching" into main
Diffstat (limited to 'test/sql')
-rw-r--r--test/sql/test_resultset.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/test/sql/test_resultset.py b/test/sql/test_resultset.py
index 5df5c8a73..42cf31bf5 100644
--- a/test/sql/test_resultset.py
+++ b/test/sql/test_resultset.py
@@ -1158,6 +1158,50 @@ class CursorResultTest(fixtures.TablesTest):
set([True]),
)
+ @testing.combinations(
+ (("name_label", "*"), False),
+ (("*", "name_label"), False),
+ (("user_id", "name_label", "user_name"), False),
+ (("user_id", "name_label", "*", "user_name"), True),
+ argnames="cols,other_cols_are_ambiguous",
+ )
+ @testing.requires.select_star_mixed
+ def test_label_against_star(
+ self, connection, cols, other_cols_are_ambiguous
+ ):
+ """test #8536"""
+ users = self.tables.users
+
+ connection.execute(users.insert(), dict(user_id=1, user_name="john"))
+
+ stmt = select(
+ *[
+ text("*")
+ if colname == "*"
+ else users.c.user_name.label("name_label")
+ if colname == "name_label"
+ else users.c[colname]
+ for colname in cols
+ ]
+ )
+
+ row = connection.execute(stmt).first()
+
+ eq_(row._mapping["name_label"], "john")
+
+ if other_cols_are_ambiguous:
+ with expect_raises_message(
+ exc.InvalidRequestError, "Ambiguous column name"
+ ):
+ row._mapping["user_id"]
+ with expect_raises_message(
+ exc.InvalidRequestError, "Ambiguous column name"
+ ):
+ row._mapping["user_name"]
+ else:
+ eq_(row._mapping["user_id"], 1)
+ eq_(row._mapping["user_name"], "john")
+
def test_loose_matching_one(self, connection):
users = self.tables.users
addresses = self.tables.addresses