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,48 @@
# name: test/sql/function/nested/array_extract_unnamed_struct.test
# description: Test array extract on unnamed structs
# group: [nested]
statement error
SELECT (ROW(42, 84))['element']
----
cannot be used on an unnamed struct
query I
SELECT (ROW(42, 84))[1]
----
42
query I
SELECT (ROW(42, 84))[2]
----
84
query II
SELECT UNNEST(ROW(42, 84))
----
42 84
statement error
SELECT (ROW(42, 84))[0]
----
out of range
statement error
SELECT (ROW(42, 84))[9999]
----
out of range
statement error
SELECT (ROW(42, 84))[-1]
----
out of range
statement error
SELECT (ROW(42, 84))[9223372036854775807]
----
out of range
statement error
SELECT (ROW(42, 84))[(-9223372036854775808)::BIGINT]
----
out of range

View File

@@ -0,0 +1,10 @@
# name: test/sql/function/nested/test_issue_5437.test
# description: Issue #5437: Python crashes with struct_insert
# group: [nested]
statement ok
with data as (
select * from (VALUES ('Amsterdam', {'x': 1, 'y': 2, 'z': 3}), ('London', {'x': 4, 'y': 5, 'z': 6})) Cities(Name, Id)
)
select *, struct_insert(Id, d := 4)
from data

View File

@@ -0,0 +1,65 @@
# name: test/sql/function/nested/test_struct_insert.test
# description: Test the struct_insert function.
# group: [nested]
# Test basic insertion into a STRUCT.
query T
SELECT struct_insert ({a: 1, b: 2}, c := 3);
----
{'a': 1, 'b': 2, 'c': 3}
# Insertion into a STRUCT generated by a row of data.
query T
WITH data AS (SELECT 1 AS a, 2 AS b, 3 AS c)
SELECT struct_insert (data, d := 4) FROM data;
----
{'a': 1, 'b': 2, 'c': 3, 'd': 4}
# Insertion of a nested STRUCT into an existing STRUCT.
query T
SELECT struct_insert({'a': 1, 'b': 'abc', 'c': true}, d := {'a': 'new stuff'});
----
{'a': 1, 'b': abc, 'c': true, 'd': {'a': new stuff}}
# Test incorrect usage.
statement error
SELECT struct_insert();
----
<REGEX>:Invalid Input Error.*Missing required arguments for struct_insert function.*
statement error
SELECT struct_insert({a: 1, b: 2});
----
<REGEX>:Invalid Input Error.*insert nothing into a STRUCT.*
statement error
SELECT struct_insert(123, a := 1);
----
<REGEX>:Invalid Input Error.*The first argument to struct_insert must be a STRUCT.*
statement error
SELECT struct_insert({a: 1, b: 2}, a := 2);
----
<REGEX>:Binder Error.*Duplicate struct entry name.*
# Test inserting NULL as the default value.
statement ok
CREATE TABLE tbl (col STRUCT(i INT));
statement ok
INSERT INTO tbl SELECT {'i': range} FROM range(3);
query I
SELECT struct_insert(col, a := col.i + 1, b := NULL::VARCHAR) FROM tbl ORDER BY ALL;
----
{'i': 0, 'a': 1, 'b': NULL}
{'i': 1, 'a': 2, 'b': NULL}
{'i': 2, 'a': 3, 'b': NULL}
query I
SELECT struct_insert(col, a := NULL, b := NULL::VARCHAR, c := [NULL]) FROM tbl ORDER BY ALL;
----
{'i': 0, 'a': NULL, 'b': NULL, 'c': [NULL]}
{'i': 1, 'a': NULL, 'b': NULL, 'c': [NULL]}
{'i': 2, 'a': NULL, 'b': NULL, 'c': [NULL]}

View File

@@ -0,0 +1,134 @@
# name: test/sql/function/nested/test_struct_update.test
# description: Test the struct_update function.
# group: [nested]
statement ok
pragma enable_verification
# Test basic insertion into a STRUCT.
query T
SELECT struct_update ({a: 1, b: 2}, c := 3);
----
{'a': 1, 'b': 2, 'c': 3}
# Insertion into a STRUCT generated by a row of data.
query T
WITH data AS (SELECT 1 AS a, 2 AS b, 3 AS c)
SELECT struct_update (data, d := 4) FROM data;
----
{'a': 1, 'b': 2, 'c': 3, 'd': 4}
# Insertion of a nested STRUCT into an existing STRUCT.
query T
SELECT struct_update({'a': 1, 'b': 'abc', 'c': true}, d := {'a': 'new stuff'});
----
{'a': 1, 'b': abc, 'c': true, 'd': {'a': new stuff}}
# Test incorrect usage.
statement error
SELECT struct_update();
----
<REGEX>:Invalid Input Error.*Missing required arguments for struct_update function.*
statement error
SELECT struct_update({a: 1, b: 2});
----
<REGEX>:Invalid Input Error.*update nothing into a STRUCT.*
statement error
SELECT struct_update(123, a := 1);
----
<REGEX>:Invalid Input Error.*The first argument to struct_update must be a STRUCT.*
statement error
SELECT struct_update({a: 1, b: 2}, a := 2, a := 3);
----
<REGEX>:Invalid Input Error.*Duplicate named argument .*
# Test changing a value in a STRUCT field
query T
SELECT struct_update({a: 1, b: 2}, a := 3);
----
{'a': 3, 'b': 2}
# Test changing the type and value of a STRUCT field
query T
SELECT struct_update({a: 1, b: 2}, a := 'c');
----
{'a': c, 'b': 2}
# Test updating and adding a field to a STRUCT
query T
SELECT struct_update({a: 1, b: 2}, a := 'c', d := 3);
----
{'a': c, 'b': 2, 'd': 3}
# Test adding a field to a STRUCT and updating out of order
query T
SELECT struct_update({a: 1, b: 2}, d := 3, a := 'c');
----
{'a': c, 'b': 2, 'd': 3}
# Test using in a table
statement ok
CREATE TABLE tbl (col STRUCT(i INT));
statement ok
INSERT INTO tbl SELECT {'i': range} FROM range(3);
query I
SELECT struct_update(col, i:=10) FROM tbl;
----
{'i': 10}
{'i': 10}
{'i': 10}
query I
SELECT struct_update(col, i:=col.i+1) FROM tbl;
----
{'i': 1}
{'i': 2}
{'i': 3}
query I
SELECT struct_update(col, i:='i='||col.i) FROM tbl;
----
{'i': 'i=0'}
{'i': 'i=1'}
{'i': 'i=2'}
# Test inserting NULL as the default value.
query I
SELECT struct_update(col, a := NULL::VARCHAR) FROM tbl ORDER BY ALL;
----
{'i': 0, 'a': NULL}
{'i': 1, 'a': NULL}
{'i': 2, 'a': NULL}
query I
SELECT struct_update(col, a := NULL::VARCHAR) FROM tbl ORDER BY ALL;
----
{'i': 0, 'a': NULL}
{'i': 1, 'a': NULL}
{'i': 2, 'a': NULL}
query I
SELECT struct_update(col, a := NULL, b := NULL::VARCHAR, c := [NULL]) FROM tbl ORDER BY ALL;
----
{'i': 0, 'a': NULL, 'b': NULL, 'c': [NULL]}
{'i': 1, 'a': NULL, 'b': NULL, 'c': [NULL]}
{'i': 2, 'a': NULL, 'b': NULL, 'c': [NULL]}
query I
SELECT struct_update(col, i := 10, a := NULL, b := NULL::VARCHAR, c := [NULL]) FROM tbl ORDER BY ALL;
----
{'i': 10, 'a': NULL, 'b': NULL, 'c': [NULL]}
{'i': 10, 'a': NULL, 'b': NULL, 'c': [NULL]}
{'i': 10, 'a': NULL, 'b': NULL, 'c': [NULL]}
query I
SELECT struct_update(col, i := col.i+10, a := NULL, b := NULL::VARCHAR, c := [NULL]) FROM tbl ORDER BY ALL;
----
{'i': 10, 'a': NULL, 'b': NULL, 'c': [NULL]}
{'i': 11, 'a': NULL, 'b': NULL, 'c': [NULL]}
{'i': 12, 'a': NULL, 'b': NULL, 'c': [NULL]}