should be it

This commit is contained in:
2025-10-24 19:21:19 -05:00
parent a4b23fc57c
commit f09560c7b1
14047 changed files with 3161551 additions and 1 deletions

View File

@@ -0,0 +1,190 @@
# name: test/sql/select/test_multi_column_reference.test
# description: Test multi column reference
# group: [select]
statement ok
PRAGMA enable_verification
# column names can have an arbitrary amount of dots
# here is how the resolution works:
# no dots (i.e. "part1")
# -> part1 refers to a column
# one dot (i.e. "part1.part2")
# EITHER:
# -> part1 is a table, part2 is a column
# -> part1 is a column, part2 is a property of that column (i.e. struct_extract)
# two or more dots (i.e. "part1.part2.part3.part4...")
# -> part1 is a schema, part2 is a table, part3 is a column name, part4 and beyond are struct fields
# -> part1 is a table, part2 is a column name, part3 and beyond are struct fields
# -> part1 is a column, part2 and beyond are struct fields
# we always prefer the most top-level view
# i.e. in case of multiple resolution options, we resolve in order:
# -> 1. resolve "part1" as a schema
# -> 2. resolve "part1" as a table
# -> 3. resolve "part1" as a column
# schema -> table -> column reference
statement ok
CREATE SCHEMA test
statement ok
CREATE TABLE test.tbl(col INTEGER);
statement ok
INSERT INTO test.tbl VALUES (1), (2), (3);
query I
SELECT test.tbl.col FROM test.tbl;
----
1
2
3
# schema name with alias does not work
statement error
SELECT test.t.col FROM test.tbl t;
----
<REGEX>:.*Binder Error.*table.*not found.*
statement error
SELECT test.tbl.col FROM test.tbl t;
----
<REGEX>:.*Binder Error.*table.*not found.*
# check how ties are resolved
# we create a table called "t" in a schema called "t" with a column called "t" that has a field called "t"
statement ok
CREATE SCHEMA t
statement ok
CREATE TABLE t.t(t ROW(t INTEGER));
statement ok
INSERT INTO t.t VALUES ({'t': 42});
# "t" selects the column
query I
SELECT t FROM t.t;
----
{'t': 42}
# "t.t" also selects the column
query I
SELECT t.t FROM t.t;
----
{'t': 42}
# t.t.t also selects the column
query I
SELECT t.t.t FROM t.t;
----
{'t': 42}
# t.t.t.t selects the field
query I
SELECT t.t.t.t FROM t.t;
----
42
statement ok
DROP SCHEMA t CASCADE;
# test long nested struct
statement ok
CREATE SCHEMA t
statement ok
CREATE TABLE t.t AS SELECT {'t': {'t': {'t': {'t': {'t': 42}}}}} t
query I
SELECT t.t.t.t.t.t.t.t FROM t.t;
----
42
query I
SELECT t.t.t.t.t.t.t FROM t.t;
----
{'t': 42}
query I
SELECT t.t.t.t.t.t FROM t.t;
----
{'t': {'t': 42}}
query I
SELECT t.t.t.t.t FROM t.t;
----
{'t': {'t': {'t': 42}}}
query I
SELECT t.t.t.t FROM t.t;
----
{'t': {'t': {'t': {'t': 42}}}}
query I
SELECT t.t.t FROM t.t;
----
{'t': {'t': {'t': {'t': {'t': 42}}}}}
query I
SELECT t.t FROM t.t;
----
{'t': {'t': {'t': {'t': {'t': 42}}}}}
query I
SELECT t FROM t.t;
----
{'t': {'t': {'t': {'t': {'t': 42}}}}}
statement ok
DROP SCHEMA t CASCADE
# test multiple tables with the same name but a different schema
statement ok
CREATE SCHEMA s1
statement ok
CREATE SCHEMA s2
statement ok
CREATE TABLE s1.t1 AS SELECT 42 t
statement ok
CREATE TABLE s2.t1 AS SELECT 84 t
query I
SELECT s1.t1.t FROM s1.t1, s2.t1
----
42
query I
SELECT * EXCLUDE (s1.t1.t) FROM s1.t1, s2.t1
----
84
query I
SELECT * EXCLUDE (S1.T1.T) FROM s1.t1, s2.t1
----
84
query I
SELECT s2.t1.t FROM s1.t1, s2.t1
----
84
# test various failures
statement error
SELECT testX.tbl.col FROM test.tbl;
----
<REGEX>:.*Binder Error.*table.*not found.*
statement error
SELECT test.tblX.col FROM test.tbl;
----
<REGEX>:.*Binder Error.*table.*not found.*
statement error
SELECT test.tbl.colX FROM test.tbl;
----
<REGEX>:.*Binder Error.*does not have a column.*

View File

@@ -0,0 +1,53 @@
# name: test/sql/select/test_positional_reference.test
# description: Positional reference
# group: [select]
statement ok
PRAGMA enable_verification
query I
SELECT #1 FROM range(1)
----
0
# multiple tables
query I
SELECT #1+#2 FROM range(1) tbl, range(1) tbl2
----
0
# subqueries
query I
SELECT #1 FROM (SELECT * FROM range(1)) tbl
----
0
# positional references only consider the inner-most table
statement error
select (select #1) from range(1);
----
<REGEX>:.*Binder Error.*out of range.*
# out of range
statement error
SELECT #2 FROM range(1)
----
<REGEX>:.*Binder Error.*out of range.*
# no from clause
statement error
SELECT #1
----
<REGEX>:.*Binder Error.*out of range.*
# zero always fails
statement error
SELECT #0 FROM range(1)
----
<REGEX>:.*Parser Error.*Positional reference node needs.*
# as do negative numbers
statement error
SELECT #-1 FROM range(1)
----
<REGEX>:.*Parser Error.*syntax error.*

View File

@@ -0,0 +1,61 @@
# name: test/sql/select/test_projection_names.test
# description: Test projection lists
# group: [select]
statement ok
CREATE TABLE integers("COL1" INTEGER, "COL2" INTEGER)
# *
statement ok
CREATE TABLE tbl AS SELECT * FROM integers
query I
SELECT name FROM pragma_table_info('tbl') ORDER BY name
----
COL1
COL2
statement ok
DROP TABLE tbl
# col1, col2
statement ok
CREATE TABLE tbl AS SELECT COL1, COL2 FROM integers
query I
SELECT name FROM pragma_table_info('tbl') ORDER BY name
----
COL1
COL2
statement ok
DROP TABLE tbl
# explicit table reference
statement ok
CREATE TABLE tbl AS SELECT integers.COL1, integers.COL2 FROM integers
query I
SELECT name FROM pragma_table_info('tbl') ORDER BY name
----
COL1
COL2
statement ok
DROP TABLE tbl
# explicit schema reference
statement ok
CREATE SCHEMA s1;
statement ok
CREATE TABLE s1.integers("COL1" INTEGER, "COL2" INTEGER)
statement ok
CREATE TABLE tbl AS SELECT s1.integers.COL1, s1.integers.COL2 FROM s1.integers
query I
SELECT name FROM pragma_table_info('tbl') ORDER BY name
----
COL1
COL2

View File

@@ -0,0 +1,28 @@
# name: test/sql/select/test_schema_reference.test
# description: Test schema reference in column reference
# group: [select]
statement ok
PRAGMA enable_verification
statement ok
CREATE SCHEMA s1;
statement ok
CREATE TABLE s1.tbl(i INTEGER)
# standard schema reference
statement ok
SELECT s1.tbl.i FROM s1.tbl;
# schema mismatch
statement error
SELECT s2.tbl.i FROM s1.tbl;
----
<REGEX>:.*Binder Error.*table.*not found.*
# no schema present
statement error
SELECT a.tbl.i FROM range(10) tbl(i)
----
<REGEX>:.*Binder Error.*table.*not found.*

View File

@@ -0,0 +1,114 @@
# name: test/sql/select/test_select_alias_prefix_colon.test
# description: Test selecting a view through a qualified reference
# group: [select]
statement ok
PRAGMA enable_verification
query I
SELECT j : 42;
----
42
query I
select column_name from (describe SELECT j : 42)
----
j
query I
SELECT "j" : 42;
----
42
statement error
SELECT 'j': 42
----
Parser Error
query I
SELECT "hel lo" : 42;
----
42
query I
select column_name from (describe SELECT "hel lo" : 42)
----
hel lo
query III
SELECT j1 : 42, 42 AS j2, 42 j3;
----
42 42 42
statement ok
CREATE TABLE a (i INTEGER);
statement ok
INSERT INTO a VALUES (42);
query I
SELECT j : i FROM a
----
42
query I
SELECT "j" : "i" FROM a
----
42
query I
SELECT * FROM b : a
----
42
query I
SELECT * FROM "b" : a
----
42
query I
SELECT i FROM b : a
----
42
query I
SELECT b.i FROM b : a
----
42
statement error
SELECT a.i FROM b : a
----
Binder Error: Referenced table "a" not found!
Candidate tables: "b"
statement error
SELECT a : 42 AS b
----
syntax error
query I
from my_wonderful_values : (values(42))
----
42
query I
from 'my_wonderful_values' : (values(42))
----
42
query I
from "my_wonderful_values" : (values(42))
----
42
query I
from r : range(1)
----
0
query I
from "r" : range(1)
----
0

View File

@@ -0,0 +1,10 @@
# name: test/sql/select/test_select_empty_table.test
# description: Test select empty table
# group: [select]
statement ok
CREATE TABLE integers(i INTEGER)
query I
SELECT * FROM integers
----

View File

@@ -0,0 +1,15 @@
# name: test/sql/select/test_select_into.test
# description: Select INTO
# group: [select]
statement ok
CREATE TABLE t (t TEXT);
statement ok
INSERT INTO t VALUES ('foo'), ('bar'), ('baz');
# unsupported
statement error
SELECT * INTO t2 FROM t WHERE t LIKE 'b%';
----
<REGEX>:.*Parser Error.*SELECT INTO not supported.*

View File

@@ -0,0 +1,30 @@
# name: test/sql/select/test_select_locking.test
# description: Select locking
# group: [select]
statement ok
CREATE TABLE t (t TEXT);
# unsupported
statement error
SELECT * FROM t FOR UPDATE;
----
<REGEX>:.*Parser Error.*SELECT locking clause is not supported.*
# unsupported
statement error
SELECT * FROM t FOR NO KEY UPDATE;
----
<REGEX>:.*Parser Error.*SELECT locking clause is not supported.*
# unsupported
statement error
SELECT * FROM t FOR SHARE;
----
<REGEX>:.*Parser Error.*SELECT locking clause is not supported.*
# unsupported
statement error
SELECT * FROM t KEY SHARE;
----
<REGEX>:.*Parser Error.*syntax error.*

View File

@@ -0,0 +1,21 @@
# name: test/sql/select/test_select_qualified_view.test
# description: Test selecting a view through a qualified reference
# group: [select]
statement ok
PRAGMA enable_verification
statement ok
CREATE SCHEMA s;
statement ok
create table s.a as select 'hello' as col1;
statement ok
create view s.b as select * from s.a;
statement ok
select s.b.col1 from s.b;
statement ok
select b.col1 from s.b;