should be it
This commit is contained in:
60
external/duckdb/test/sql/generated_columns/virtual/ambiguity.test
vendored
Normal file
60
external/duckdb/test/sql/generated_columns/virtual/ambiguity.test
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
# name: test/sql/generated_columns/virtual/ambiguity.test
|
||||
# description: Test if the columnrefs in a generated-column expression can result in ambiguity
|
||||
# group: [virtual]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement ok
|
||||
CREATE TABLE unit (
|
||||
price INTEGER,
|
||||
amount_sold INTEGER,
|
||||
total_profit AS (price * amount_sold)
|
||||
);
|
||||
|
||||
# Not allowed to have qualified (tbl.name) column references
|
||||
statement error
|
||||
CREATE TABLE unit2 (
|
||||
price INTEGER,
|
||||
amount_sold INTEGER,
|
||||
total_profit AS (price / amount_sold),
|
||||
profit_total AS (unit2.price * unit2.amount_sold)
|
||||
);
|
||||
----
|
||||
|
||||
statement ok
|
||||
CREATE TABLE unit2 (
|
||||
price INTEGER,
|
||||
amount_sold INTEGER,
|
||||
total_profit AS (price / amount_sold),
|
||||
profit_total AS (price * amount_sold)
|
||||
);
|
||||
|
||||
statement ok
|
||||
INSERT INTO unit VALUES (5,4)
|
||||
|
||||
# Ambiguous, both have 'total_profit'
|
||||
statement error
|
||||
SELECT total_profit FROM unit, unit2
|
||||
----
|
||||
|
||||
statement ok
|
||||
INSERT INTO unit2 VALUES (100, 4)
|
||||
|
||||
# When using the table name, we avoid ambiguity
|
||||
statement ok
|
||||
SELECT unit.total_profit FROM unit, unit2
|
||||
|
||||
# When using aliases for tables, this should still work
|
||||
query I
|
||||
SELECT unit.total_profit FROM unit AS unit2, unit2 AS unit
|
||||
----
|
||||
25
|
||||
|
||||
# No ambiguity here
|
||||
statement ok
|
||||
SELECT profit_total FROM unit2
|
||||
|
||||
# Aliasing the table name shouldn't break the generated expression
|
||||
statement ok
|
||||
SELECT profit_total FROM unit2 as unit
|
||||
Reference in New Issue
Block a user