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,14 @@
# name: test/sql/table_function/database_oid.test
# description: Issue #5836: Test database oid
# group: [table_function]
statement ok
CREATE TEMP TABLE x (x INT);
statement ok
CREATE TABLE x (x INT);
query I
SELECT COUNT(DISTINCT database_oid) FROM duckdb_tables();
----
2

View File

@@ -0,0 +1,92 @@
# name: test/sql/table_function/duckdb_columns.test
# description: Test duckdb_columns function
# group: [table_function]
statement ok
set storage_compatibility_version='v0.10.2'
statement ok
PRAGMA enable_verification
statement ok nosort duckdb_col
SELECT * FROM duckdb_columns();
statement ok nosort duckdb_col
SELECT * FROM duckdb_columns;
statement ok
CREATE TABLE integers(i INTEGER)
statement ok
CREATE TABLE test(i INTEGER NOT NULL, j DECIMAL(18, 3), k VARCHAR DEFAULT 'hello')
query IIIIIIII
SELECT tables.table_name, column_name, data_type, column_default, is_nullable, numeric_precision, numeric_precision_radix, numeric_scale
FROM duckdb_columns cols JOIN duckdb_tables tables USING (table_oid) ORDER BY 1, 2, 3;
----
integers i INTEGER NULL True 32 2 0
test i INTEGER NULL False 32 2 0
test j DECIMAL(18,3) NULL True 18 10 3
test k VARCHAR 'hello' True NULL NULL NULL
query I
SELECT DISTINCT(cols.database_name) = current_database()
FROM duckdb_columns cols JOIN duckdb_tables tables USING (table_oid);
----
True
statement ok
create view v1 as select * from test
query II
select table_name, column_name from duckdb_columns where table_name = 'v1'
----
v1 i
v1 j
v1 k
statement ok
alter table test rename column j to renamed
# Rename of the base table is not reflected in the view's info
query II
select table_name, column_name from duckdb_columns where table_name = 'v1'
----
v1 i
v1 j
v1 k
statement ok
alter table test rename column renamed to j
statement ok
create or replace view v1 (a, b) as select * from test;
query II
select table_name, column_name from duckdb_columns where table_name = 'v1'
----
v1 a
v1 b
v1 k
statement ok
alter table test rename column j to renamed
# The rename of 'j' is not reflected in the view's info because it was aliased to 'b'
query II
select table_name, column_name from duckdb_columns where table_name = 'v1'
----
v1 a
v1 b
v1 k
statement ok
alter table test rename column k to not_k
# The rename of 'k' is also not reflected in the view's info even though it was not aliased
query II
select table_name, column_name from duckdb_columns where table_name = 'v1'
----
v1 a
v1 b
v1 k

View File

@@ -0,0 +1,58 @@
# name: test/sql/table_function/duckdb_constraints.test
# description: Test duckdb_constraints function
# group: [table_function]
statement ok
create table integers(i int primary key, check (i < 10));
statement ok
create table test(i varchar unique, k varchar, check(len(i || k) < 10));
statement ok
create table fk_integers(j int, foreign key (j) references integers(i));
statement ok
create table fk_integers_2(k int, foreign key (k) references integers(i));
statement ok nosort duckdb_col
SELECT * FROM duckdb_constraints();
statement ok nosort duckdb_col
SELECT * FROM duckdb_constraints;
query IIII
SELECT table_name, constraint_index, constraint_type, UNNEST(constraint_column_names) col_name FROM duckdb_constraints ORDER BY table_name, constraint_index, col_name
----
fk_integers 0 FOREIGN KEY j
fk_integers_2 1 FOREIGN KEY k
integers 2 PRIMARY KEY i
integers 3 CHECK i
integers 4 NOT NULL i
test 5 UNIQUE i
test 6 CHECK i
test 6 CHECK k
query II
SELECT constraint_name, unique_constraint_name FROM information_schema.referential_constraints ORDER BY constraint_name
----
fk_integers_2_k_i_fkey integers_i_pkey
fk_integers_j_i_fkey integers_i_pkey
query IIII
SELECT column_name, constraint_name, table_name, position_in_unique_constraint FROM information_schema.key_column_usage ORDER BY constraint_name
----
k fk_integers_2_k_i_fkey fk_integers_2 1
j fk_integers_j_i_fkey fk_integers 1
i integers_i_pkey integers NULL
i test_i_key test NULL
query III
SELECT constraint_name, table_name, constraint_type FROM information_schema.table_constraints ORDER BY constraint_name;
----
fk_integers_2_k_i_fkey fk_integers_2 FOREIGN KEY
fk_integers_j_i_fkey fk_integers FOREIGN KEY
integers_i_check integers CHECK
integers_i_not_null integers CHECK
integers_i_pkey integers PRIMARY KEY
test_i_k_check test CHECK
test_i_key test UNIQUE

View File

@@ -0,0 +1,52 @@
# name: test/sql/table_function/duckdb_constraints_fk.test
# description: Test duckdb_constraints function
# group: [table_function]
statement ok
CREATE TABLE tf_1 (
a integer, "b c" integer, "d e" integer,
PRIMARY KEY (a),
UNIQUE ("b c"),
UNIQUE ("d e")
);
statement ok
CREATE TABLE tf_3 (
g integer, h integer,
PRIMARY KEY (g),
UNIQUE (h)
);
statement ok
CREATE TABLE tf_2 (
c integer, d integer, e integer, f integer, g integer,
PRIMARY KEY (c),
FOREIGN KEY (d) REFERENCES tf_1 (a),
FOREIGN KEY (e) REFERENCES tf_1 ("b c"),
FOREIGN KEY (f) REFERENCES tf_1 ("d e"),
FOREIGN KEY (g) REFERENCES tf_3 (g),
);
statement ok
CREATE TABLE tf_4 (
h integer,
FOREIGN KEY (h) REFERENCES tf_3 (h),
);
query IIIIIIIIII
SELECT * EXCLUDE (database_name, schema_oid, table_oid, database_oid, constraint_name) FROM duckdb_constraints();
----
main tf_1 0 PRIMARY KEY PRIMARY KEY(a) NULL [0] [a] NULL []
main tf_1 1 UNIQUE UNIQUE("b c") NULL [1] [b c] NULL []
main tf_1 2 UNIQUE UNIQUE("d e") NULL [2] [d e] NULL []
main tf_1 3 NOT NULL NOT NULL NULL [0] [a] NULL []
main tf_2 4 PRIMARY KEY PRIMARY KEY(c) NULL [0] [c] NULL []
main tf_2 5 FOREIGN KEY FOREIGN KEY (d) REFERENCES tf_1(a) NULL [1] [d] tf_1 [a]
main tf_2 6 FOREIGN KEY FOREIGN KEY (e) REFERENCES tf_1("b c") NULL [2] [e] tf_1 [b c]
main tf_2 7 FOREIGN KEY FOREIGN KEY (f) REFERENCES tf_1("d e") NULL [3] [f] tf_1 [d e]
main tf_2 8 FOREIGN KEY FOREIGN KEY (g) REFERENCES tf_3(g) NULL [4] [g] tf_3 [g]
main tf_2 9 NOT NULL NOT NULL NULL [0] [c] NULL []
main tf_3 10 PRIMARY KEY PRIMARY KEY(g) NULL [0] [g] NULL []
main tf_3 11 UNIQUE UNIQUE(h) NULL [1] [h] NULL []
main tf_3 12 NOT NULL NOT NULL NULL [0] [g] NULL []
main tf_4 13 FOREIGN KEY FOREIGN KEY (h) REFERENCES tf_3(h) NULL [0] [h] tf_3 [h]

View File

@@ -0,0 +1,46 @@
# name: test/sql/table_function/duckdb_constraints_issue11284.test
# description: Issue #11284 - duckdb_constraints() column CONSTRAINT_TEXT contains bad definition for PRIMARY KEY if there are foreign keys referencing it
# group: [table_function]
statement ok
pragma enable_verification
statement ok
create table t (i int primary key);
query I
select constraint_text from duckdb_constraints() where constraint_type = 'PRIMARY KEY';
----
PRIMARY KEY(i)
statement ok
create table u (i int references t);
query I
select constraint_text from duckdb_constraints() where constraint_type = 'PRIMARY KEY';
----
PRIMARY KEY(i)
statement ok
create table v (i int references t);
query I
select constraint_text from duckdb_constraints() where constraint_type = 'PRIMARY KEY';
----
PRIMARY KEY(i)
statement ok
drop table v;
query I
select constraint_text from duckdb_constraints() where constraint_type = 'PRIMARY KEY';
----
PRIMARY KEY(i)
statement ok
drop table u;
query I
select constraint_text from duckdb_constraints() where constraint_type = 'PRIMARY KEY';
----
PRIMARY KEY(i)

View File

@@ -0,0 +1,32 @@
# name: test/sql/table_function/duckdb_constraints_issue12863.test
# description: Issue #12863 - INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS doesn't list foreign keys when declaration case doesn't match reference case
# group: [table_function]
statement ok
pragma enable_verification
statement ok
CREATE TABLE a (ID int PRIMARY KEY);
statement ok
CREATE TABLE b (id int REFERENCES A);
query II
SELECT constraint_name, unique_constraint_name FROM information_schema.referential_constraints;
----
b_id_id_fkey a_id_pkey
# test multiple schemas with the same table names/references
statement ok
CREATE SCHEMA s1;
statement ok
CREATE TABLE s1.a (ID int PRIMARY KEY);
statement ok
CREATE TABLE s1.b (id int REFERENCES s1.A);
query I
SELECT COUNT(*) FROM information_schema.referential_constraints;
----
2

View File

@@ -0,0 +1,58 @@
# name: test/sql/table_function/duckdb_databases.test
# description: Test duckdb_databases function
# group: [table_function]
require noforcestorage
statement ok
PRAGMA enable_verification
statement ok
SELECT * FROM duckdb_databases();
query IIIII
SELECT database_name, internal, readonly, path, type FROM duckdb_databases() ORDER BY database_name;
----
memory false false NULL duckdb
system true false NULL duckdb
temp true false NULL duckdb
statement ok
ATTACH '__TEST_DIR__/duckdb_databases.db' AS new_duckdb_database
query IIII
SELECT database_name, internal, split(replace(path, '\', '/'), '/')[-1], type FROM duckdb_databases() WHERE path IS NOT NULL;
----
new_duckdb_database false duckdb_databases.db duckdb
query I
SELECT readonly FROM duckdb_databases WHERE database_name='new_duckdb_database';
----
false
query II nosort show_db
SELECT database_name FROM duckdb_databases ORDER BY database_name
----
query II nosort show_db
SHOW databases
----
query I
SELECT datname FROM pg_catalog.pg_database ORDER BY 1
----
memory
new_duckdb_database
system
temp
statement ok
DETACH new_duckdb_database;
statement ok
ATTACH '__TEST_DIR__/duckdb_databases.db' AS readonly_duckdb_database (READONLY 1);
query I
SELECT readonly FROM duckdb_databases WHERE database_name='readonly_duckdb_database';
----
true

View File

@@ -0,0 +1,17 @@
# name: test/sql/table_function/duckdb_dependencies.test
# description: Test duckdb_dependencies function
# group: [table_function]
# test the base dependencies
statement ok
SELECT * FROM duckdb_dependencies();
# add some new dependencies
statement ok
CREATE TABLE integers(i INTEGER);
statement ok
CREATE INDEX i_index ON integers(i)
statement ok
SELECT * FROM duckdb_dependencies();

View File

@@ -0,0 +1,21 @@
# name: test/sql/table_function/duckdb_extensions.test
# description: Test duckdb_extensions function
# group: [table_function]
statement ok
SELECT * FROM duckdb_extensions();
query I
SELECT aliases FROM duckdb_extensions() WHERE extension_name='postgres_scanner';
----
[postgres]
require tpch
statement ok
LOAD tpch;
query I
SELECT extension_name FROM duckdb_extensions() WHERE loaded AND extension_name='tpch';
----
tpch

View File

@@ -0,0 +1,48 @@
# name: test/sql/table_function/duckdb_functions.test_slow
# description: Test duckdb_functions function
# group: [table_function]
statement ok
PRAGMA enable_verification
statement ok
SELECT * FROM duckdb_functions();
query I
select function_name from duckdb_functions() where not internal order by 1;
----
statement ok
CREATE MACRO add_default1(a := 3, b := 5) AS a + b
statement ok
CREATE MACRO add_default2(a, b := 5) AS a + b
statement ok
SELECT * FROM duckdb_functions();
statement ok
SELECT * FROM duckdb_functions() WHERE function_type='table';
statement ok
SELECT sqrt(4)
query I
select distinct function_name from duckdb_functions() where function_name='sqrt';
----
sqrt
query I
select function_name from duckdb_functions() where not internal order by 1;
----
add_default1
add_default2
# table functions too
statement ok
create macro my_range(x) as table from range(x);
query I
select macro_definition from duckdb_functions() where function_name = 'my_range';
----
SELECT * FROM "range"(x)

View File

@@ -0,0 +1,20 @@
# name: test/sql/table_function/duckdb_indexes.test
# description: Test duckdb_indexes function
# group: [table_function]
statement ok
CREATE TABLE integers(i INTEGER, j INTEGER, k INTEGER)
statement ok
CREATE INDEX i_index ON integers((j + 1), k)
statement ok nosort duckdb_col
SELECT * FROM duckdb_indexes();
statement ok nosort duckdb_col
SELECT * FROM duckdb_indexes;
query I
select expressions from duckdb_indexes where table_name = 'integers';
----
['((j + 1))', k]

View File

@@ -0,0 +1,9 @@
# name: test/sql/table_function/duckdb_keywords.test
# description: Test duckdb_keywords function
# group: [table_function]
statement ok
PRAGMA enable_verification
statement ok
SELECT * FROM duckdb_keywords();

View File

@@ -0,0 +1,33 @@
# name: test/sql/table_function/duckdb_memory.test_slow
# group: [table_function]
require vector_size 2048
statement ok
set memory_limit='20mb';
statement ok
set max_temp_directory_size='150MiB';
loop i 0 5
statement ok
drop table if exists tmp1;
statement ok
create or replace temp table tmp1 as select * from range(15_000_000);
# i
endloop
# These should both report only 140mb is used
query I
select sum(temporary_storage_bytes) < 150_000_000 from duckdb_memory() where tag = 'IN_MEMORY_TABLE';
----
true
query I
select sum(size) < 150_000_000 FROM duckdb_temporary_files();
----
true

View File

@@ -0,0 +1,17 @@
# name: test/sql/table_function/duckdb_memory_convert_to_persistent.test
# group: [table_function]
load __TEST_DIR__/convert_to_persistent.duckdb
# create a persistent table
# this first allocates memory with the tag 'IN_MEMORY_TABLE'
# the memory is converted to persistent data after the query is done
# so all of the memory should be 'BASE_TABLE', no longer 'IN_MEMORY_TABLE'
statement ok
create table test as select range i from range(1_000_000);
# this is
query I
select memory_usage_bytes from duckdb_memory() where tag = 'IN_MEMORY_TABLE'
----
0

View File

@@ -0,0 +1,11 @@
# name: test/sql/table_function/duckdb_optimizers.test
# description: Test duckdb_optimizers function
# group: [table_function]
statement ok
SELECT * FROM duckdb_optimizers();
query I
SELECT name FROM duckdb_optimizers() WHERE name='join_order';
----
join_order

View File

@@ -0,0 +1,25 @@
# name: test/sql/table_function/duckdb_prepared_statements.test
# group: [table_function]
statement ok
prepare p1 as select 42;
statement ok
create table tbl(a varchar);
statement ok
prepare p2 as insert into tbl values ('test');
statement ok
prepare p3 as select 21, $1, $2
statement ok
prepare p4 as select $name, $other_name
query IIII
select * from duckdb_prepared_statements() order by name;
----
p1 SELECT 42 NULL [INTEGER]
p2 INSERT INTO tbl (VALUES ('test')) NULL [BIGINT]
p3 SELECT 21, $1, $2 [UNKNOWN, UNKNOWN] NULL
p4 SELECT $name, $other_name [UNKNOWN, UNKNOWN] NULL

View File

@@ -0,0 +1,21 @@
# name: test/sql/table_function/duckdb_schemas.test
# description: Test duckdb_schemas function
# group: [table_function]
query I
SELECT COUNT(*) FROM duckdb_schemas;
----
0
statement ok
CREATE SCHEMA scheme;
query I
SELECT COUNT(*) FROM duckdb_schemas() WHERE schema_name='scheme';
----
1
query I
SELECT COUNT(*) FROM duckdb_schemas WHERE schema_name='scheme';
----
1

View File

@@ -0,0 +1,28 @@
# name: test/sql/table_function/duckdb_sequences.test
# description: Test duckdb_sequences function
# group: [table_function]
query I
SELECT COUNT(*) FROM duckdb_sequences();
----
0
statement ok
CREATE SEQUENCE seq
statement ok
CREATE TEMPORARY SEQUENCE seq2 MINVALUE 3 MAXVALUE 5 START WITH 4 CYCLE;
query IIIIIIII
SELECT schema_name, sequence_name, temporary, start_value, min_value, max_value, increment_by, cycle
FROM duckdb_sequences() ORDER BY sequence_name;
----
main seq False 1 1 9223372036854775807 1 False
main seq2 True 4 3 5 1 True
query I
SELECT database_name = current_database() OR database_name = 'temp'
FROM duckdb_sequences();
----
True
True

View File

@@ -0,0 +1,22 @@
# name: test/sql/table_function/duckdb_settings.test
# description: Test duckdb_settings function
# group: [table_function]
statement ok
SET default_null_order='nulls_first';
statement ok
SELECT * FROM duckdb_settings();
query II
SELECT name, value FROM duckdb_settings() WHERE name='default_null_order';
----
default_null_order NULLS_FIRST
statement ok
SET default_null_order='nulls_last'
query II
SELECT name, value FROM duckdb_settings() WHERE name='default_null_order';
----
default_null_order NULLS_LAST

View File

@@ -0,0 +1,24 @@
# name: test/sql/table_function/duckdb_settings_extension.test
# description: Test duckdb_settings function with extensions
# group: [table_function]
statement ok
SET default_null_order='nulls_first';
require parquet
statement ok
SELECT * FROM duckdb_settings();
query II
SELECT name, value FROM duckdb_settings() WHERE name='default_null_order';
----
default_null_order NULLS_FIRST
statement ok
SET default_null_order='nulls_last'
query II
SELECT name, value FROM duckdb_settings() WHERE name='default_null_order';
----
default_null_order NULLS_LAST

View File

@@ -0,0 +1,49 @@
# name: test/sql/table_function/duckdb_tables.test
# description: Test duckdb_tables function
# group: [table_function]
query I
SELECT COUNT(*) FROM duckdb_tables();
----
0
statement ok
CREATE TABLE integers(i INTEGER)
statement ok
CREATE TABLE pk(i INTEGER PRIMARY KEY, j VARCHAR, CHECK(i<100))
statement ok
CREATE SCHEMA myschema;
statement ok
CREATE TABLE myschema.mytable(k DOUBLE)
statement ok
CREATE TEMPORARY TABLE mytemp(i INTEGER)
statement ok
CREATE VIEW v1 AS SELECT 42
query IIIIIIII
SELECT schema_name, table_name, temporary, has_primary_key, estimated_size, column_count, index_count, check_constraint_count
FROM duckdb_tables() ORDER BY table_name;
----
main integers False False 0 1 0 0
myschema mytable False False 0 1 0 0
main mytemp True False 0 1 0 0
main pk False True 0 2 1 1
query I
SELECT database_name = current_database() OR database_name = 'temp'
FROM duckdb_tables();
----
True
True
True
True
statement error
SELECT * FROM temp.duckdb_tables
----
main.duckdb_tables

View File

@@ -0,0 +1,9 @@
# name: test/sql/table_function/duckdb_types.test
# description: Test duckdb_types function
# group: [table_function]
statement ok nosort duckdb_col
SELECT * FROM duckdb_types();
statement ok nosort duckdb_col
SELECT * FROM duckdb_types;

View File

@@ -0,0 +1,52 @@
# name: test/sql/table_function/duckdb_views.test
# description: Test duckdb_views function
# group: [table_function]
query I
SELECT COUNT(*) FROM duckdb_views;
----
0
statement ok
CREATE VIEW v1 AS SELECT 42;
statement ok
CREATE TEMPORARY VIEW v2 AS SELECT 42;
statement ok
CREATE SCHEMA myschema;
statement ok
CREATE VIEW myschema.v2 AS SELECT 42;
query III
SELECT schema_name, view_name, temporary
FROM duckdb_views() WHERE NOT internal ORDER BY ALL;
----
main v1 False
main v2 True
myschema v2 False
query I
SELECT database_name = current_database() OR database_name = 'temp'
FROM duckdb_views() WHERE NOT internal ORDER BY view_name;
----
True
True
True
query III
SELECT schema_name, view_name, temporary
FROM duckdb_views ORDER BY ALL;
----
main v1 False
main v2 True
myschema v2 False
query I
SELECT database_name = current_database() OR database_name = 'temp'
FROM duckdb_views ORDER BY view_name;
----
True
True
True

Binary file not shown.

View File

@@ -0,0 +1 @@
Hello World!

View File

@@ -0,0 +1 @@
42

View File

@@ -0,0 +1 @@
Föö Bär

View File

@@ -0,0 +1,159 @@
# name: test/sql/table_function/icu_range_timestamptz.test
# description: Test range function with TIMESTAMPTZ
# group: [table_function]
require icu
statement ok
SET Calendar = 'gregorian';
statement ok
SET TimeZone = 'America/Los_Angeles';
query I
SELECT d FROM range(TIMESTAMPTZ '1992-01-01 00:00:00-08', TIMESTAMPTZ '1992-01-01 12:00:00-08', INTERVAL (1) HOUR) tbl(d)
----
1992-01-01 00:00:00-08
1992-01-01 01:00:00-08
1992-01-01 02:00:00-08
1992-01-01 03:00:00-08
1992-01-01 04:00:00-08
1992-01-01 05:00:00-08
1992-01-01 06:00:00-08
1992-01-01 07:00:00-08
1992-01-01 08:00:00-08
1992-01-01 09:00:00-08
1992-01-01 10:00:00-08
1992-01-01 11:00:00-08
# negative interval
query I
SELECT d FROM range(TIMESTAMPTZ '1992-01-01 00:00:00-08', TIMESTAMPTZ'1991-06-01 00:00:00-07', INTERVAL '1 MONTH ago') tbl(d)
----
1992-01-01 00:00:00-08
1991-12-01 00:00:00-08
1991-11-01 00:00:00-08
1991-10-01 00:00:00-07
1991-09-01 00:00:00-07
1991-08-01 00:00:00-07
1991-07-01 00:00:00-07
query I
SELECT d FROM generate_series(TIMESTAMPTZ '1992-01-01 00:00:00-08', TIMESTAMPTZ '1991-06-01 00:00:00-07', -INTERVAL '1 MONTH') tbl(d)
----
1992-01-01 00:00:00-08
1991-12-01 00:00:00-08
1991-11-01 00:00:00-08
1991-10-01 00:00:00-07
1991-09-01 00:00:00-07
1991-08-01 00:00:00-07
1991-07-01 00:00:00-07
1991-06-01 00:00:00-07
# composite interval
query I
SELECT d FROM range(TIMESTAMPTZ '1992-01-01 00:00:00-08', TIMESTAMPTZ '1992-12-31 12:00:00-08', INTERVAL '1 MONTH 1 DAY 1 HOUR') tbl(d)
----
1992-01-01 00:00:00-08
1992-02-02 01:00:00-08
1992-03-03 02:00:00-08
1992-04-04 03:00:00-08
1992-05-05 04:00:00-07
1992-06-06 05:00:00-07
1992-07-07 06:00:00-07
1992-08-08 07:00:00-07
1992-09-09 08:00:00-07
1992-10-10 09:00:00-07
1992-11-11 10:00:00-08
1992-12-12 11:00:00-08
# DST boundaries
query I
SELECT d FROM generate_series(TIMESTAMPTZ '1992-04-05 00:00:00-08', TIMESTAMPTZ '1992-04-05 12:00:00-07', INTERVAL '1 HOUR') tbl(d)
----
1992-04-05 00:00:00-08
1992-04-05 01:00:00-08
1992-04-05 03:00:00-07
1992-04-05 04:00:00-07
1992-04-05 05:00:00-07
1992-04-05 06:00:00-07
1992-04-05 07:00:00-07
1992-04-05 08:00:00-07
1992-04-05 09:00:00-07
1992-04-05 10:00:00-07
1992-04-05 11:00:00-07
1992-04-05 12:00:00-07
query I
SELECT d FROM generate_series(TIMESTAMPTZ '1992-10-25 00:00:00-07', TIMESTAMPTZ '1992-10-25 12:00:00-08', INTERVAL '1 HOUR') tbl(d)
----
1992-10-25 00:00:00-07
1992-10-25 01:00:00-07
1992-10-25 01:00:00-08
1992-10-25 02:00:00-08
1992-10-25 03:00:00-08
1992-10-25 04:00:00-08
1992-10-25 05:00:00-08
1992-10-25 06:00:00-08
1992-10-25 07:00:00-08
1992-10-25 08:00:00-08
1992-10-25 09:00:00-08
1992-10-25 10:00:00-08
1992-10-25 11:00:00-08
1992-10-25 12:00:00-08
# large result
query I
SELECT COUNT(*) FROM range(TIMESTAMPTZ '1992-01-01 00:00:00-08', TIMESTAMPTZ '2020-01-01 00:00:00-08', INTERVAL '1 DAY') tbl(d)
----
10227
query I
SELECT COUNT(*) FROM generate_series(TIMESTAMPTZ '1992-01-01 00:00:00-08', TIMESTAMPTZ '2020-01-01 00:00:00-08', INTERVAL '1 DAY') tbl(d)
----
10228
statement error
explain
from range('290309-12-22 (BC) 00:00:00'::TIMESTAMPTZ, '294247-01-10 04:00:54.775806'::TIMESTAMPTZ, interval '1 hour');
----
ICU date overflows timestamp range
# zero interval not supported
statement error
SELECT d FROM range(TIMESTAMPTZ '1992-01-01 00:00:00-08', TIMESTAMPTZ '1992-12-31 12:00:00-08', INTERVAL '0 MONTH') tbl(d)
----
# start is smaller than end but we have a negative interval
query I
SELECT d FROM range(TIMESTAMPTZ '1992-01-01 00:00:00-08', TIMESTAMPTZ '1992-12-31 12:00:00-08', INTERVAL '1 MONTH ago') tbl(d)
----
# start is bigger than end but we have a positive interval
query I
SELECT d FROM range(TIMESTAMPTZ '1993-01-01 00:00:00-08', TIMESTAMPTZ '1992-01-01 00:00:00-08', INTERVAL '1 MONTH') tbl(d)
----
# composite interval with negative types not supported
statement error
SELECT d FROM range(TIMESTAMPTZ '1992-01-01 00:00:00-08', TIMESTAMPTZ '1992-12-31 12:00:00-08', INTERVAL '1 MONTH' - INTERVAL '1 HOUR') tbl(d)
----
# Infinities will overflow or cause infinite loops (PG behaviour!) so we ban them
statement error
SELECT COUNT(*) FROM generate_series('294247-01-09'::TIMESTAMPTZ, 'infinity'::TIMESTAMPTZ, INTERVAL '1 DAY');
----
statement error
SELECT COUNT(*) FROM range('294247-01-09'::TIMESTAMPTZ, 'infinity'::TIMESTAMPTZ, INTERVAL '1 DAY');
----
statement error
SELECT COUNT(*) FROM generate_series('-infinity'::TIMESTAMPTZ, '290303-12-11 (BC) 00:00:00'::TIMESTAMPTZ, INTERVAL '1 DAY');
----
statement error
SELECT COUNT(*) FROM range('-infinity'::TIMESTAMPTZ, '290303-12-11 (BC) 00:00:00'::TIMESTAMPTZ, INTERVAL '1 DAY');
----

View File

@@ -0,0 +1,178 @@
# name: test/sql/table_function/information_schema.test
# description: Test information_schema functions
# group: [table_function]
statement ok
SELECT * FROM INFORMATION_SCHEMA.SCHEMATA;
statement ok
SELECT * FROM information_schema.schemata;
statement ok
CREATE SCHEMA scheme;
query I
SELECT COUNT(*) FROM information_schema.schemata WHERE schema_name='scheme'
----
1
statement ok
CREATE TABLE scheme.integers (i INTEGER);
query T
SELECT table_type FROM information_schema.tables WHERE table_schema='scheme' AND table_name='integers' AND table_catalog IS NOT NULL
----
BASE TABLE
query ITT
SELECT ordinal_position, column_name, data_type FROM information_schema.columns WHERE table_name='integers'
----
1 i INTEGER
query ITT
SELECT ordinal_position, column_name, data_type FROM information_schema.columns WHERE table_name='integers'
----
1 i INTEGER
statement ok
CREATE TEMPORARY TABLE reals (f FLOAT PRIMARY KEY, dec DECIMAL(16, 4), h HUGEINT, b BIGINT, t TINYINT, d DOUBLE NOT NULL)
query T
SELECT table_type FROM information_schema.tables WHERE table_catalog='temp' AND table_name='reals'
----
LOCAL TEMPORARY
query IIT
SELECT numeric_precision, numeric_scale, is_nullable FROM information_schema.columns WHERE table_name='reals' ORDER BY ordinal_position
----
24 0 NO
16 4 YES
128 0 YES
64 0 YES
8 0 YES
53 0 NO
statement ok
CREATE VIEW scheme.vintegers AS SELECT * FROM scheme.integers;
query T
SELECT table_type FROM information_schema.tables WHERE table_schema='scheme' AND table_name='vintegers'
----
VIEW
query T
SELECT table_type FROM information_schema.tables WHERE table_schema='scheme' AND table_name='vintegers'
----
VIEW
query ITT
SELECT ordinal_position, column_name, data_type FROM information_schema.columns WHERE table_schema='scheme' AND table_name='vintegers' AND table_catalog IS NOT NULL
----
1 i INTEGER
query IIII
SELECT character_set_name, character_repertoire, form_of_use, default_collate_name FROM information_schema.character_sets
----
UTF8 UCS UTF8 ucs_basic
statement ok
SELECT * FROM information_schema.referential_constraints
statement ok
SELECT * FROM information_schema.key_column_usage
statement ok
SELECT * FROM information_schema.table_constraints
statement ok
CREATE TABLE scheme.dept (dept_id INT PRIMARY KEY, dept_name VARCHAR(100) NOT NULL)
statement ok
CREATE TABLE scheme.emp (emp_id INT PRIMARY KEY, first_name VARCHAR(100) NOT NULL, last_name VARCHAR(100) NOT NULL, ssn INT NOT NULL UNIQUE, salary DECIMAL(10, 2) NOT NULL CHECK (salary > 0), dept_id INT REFERENCES scheme.dept(dept_id))
query IIIII
SELECT table_schema, table_name, column_name, constraint_schema, constraint_name
FROM information_schema.constraint_column_usage
WHERE table_schema = 'scheme' AND table_name = 'emp'
ORDER BY column_name ASC;
----
scheme emp dept_id scheme emp_dept_id_dept_id_fkey
scheme emp emp_id scheme emp_emp_id_pkey
scheme emp salary scheme emp_salary_check
scheme emp ssn scheme emp_ssn_key
query I
SELECT DISTINCT(table_catalog) = current_database()
FROM information_schema.constraint_column_usage
WHERE table_schema = 'scheme' AND table_name = 'emp'
ORDER BY column_name ASC;
----
True
query I
SELECT DISTINCT(constraint_catalog) = current_database()
FROM information_schema.constraint_column_usage
WHERE table_schema = 'scheme' AND table_name = 'emp'
ORDER BY column_name ASC;
----
True
query IIII
SELECT table_schema, table_name, constraint_schema, constraint_name
FROM information_schema.constraint_table_usage
WHERE table_schema = 'scheme' AND table_name = 'emp'
ORDER BY constraint_name ASC
----
scheme emp scheme emp_dept_id_dept_id_fkey
scheme emp scheme emp_emp_id_pkey
scheme emp scheme emp_salary_check
scheme emp scheme emp_ssn_key
query III
SELECT constraint_schema, constraint_name, check_clause
FROM information_schema.check_constraints
WHERE constraint_schema = 'scheme' AND check_clause LIKE 'CHECK%'
----
scheme emp_salary_check CHECK((salary > 0))
query I
SELECT DISTINCT(constraint_catalog) = current_database()
FROM information_schema.check_constraints
WHERE constraint_schema = 'scheme' AND check_clause LIKE 'CHECK%'
----
True
statement ok
CREATE OR REPLACE VIEW scheme.emp_dept_view AS SELECT emp.*, dept.dept_name FROM scheme.emp JOIN scheme.dept ON emp.dept_id = dept.dept_id;
query IIIIIIIII
SELECT table_schema, table_name, SUBSTR (view_definition, 1, 32) AS view_definition_substr, check_option, is_updatable, is_insertable_into, is_trigger_updatable, is_trigger_deletable, is_trigger_insertable_into
FROM information_schema.views
WHERE table_schema = 'scheme' AND table_name = 'emp_dept_view';
----
scheme emp_dept_view CREATE VIEW scheme.emp_dept_view NONE NO NO NO NO NO
query I
SELECT DISTINCT(table_catalog) = current_database()
FROM information_schema.views
WHERE table_schema = 'scheme' AND table_name = 'emp_dept_view';
----
True
statement ok
DROP SCHEMA scheme CASCADE;
query I
SELECT COUNT(*) FROM information_schema.schemata WHERE schema_name='scheme'
----
0
query I
SELECT COUNT(*) FROM information_schema.tables WHERE table_schema='scheme'
----
0
query I
SELECT COUNT(*) FROM information_schema.columns WHERE table_schema='scheme'
----
0

View File

@@ -0,0 +1,95 @@
# name: test/sql/table_function/information_schema_fkey_constraint_names.test
# description: Test foreign key constraint names in information_schema
# group: [table_function]
statement ok
create table t (i int primary key);
statement ok
create table u (i int references t);
query I
select constraint_name
from information_schema.table_constraints
where constraint_type like '%KEY'
order by 1
----
t_i_pkey
u_i_i_fkey
query I
select constraint_name
from information_schema.key_column_usage
order by 1
----
t_i_pkey
u_i_i_fkey
query II
select constraint_name, unique_constraint_name
from information_schema.referential_constraints;
----
u_i_i_fkey t_i_pkey
statement ok
drop table u
statement ok
drop table t
statement ok
create table target_tbl (target_col int primary key);
statement ok
create table source_tbl(source_col int references target_tbl(target_col));
query I
select constraint_name
from information_schema.table_constraints
where constraint_type like '%KEY'
order by 1
----
source_tbl_source_col_target_col_fkey
target_tbl_target_col_pkey
query I
select constraint_name
from information_schema.key_column_usage
order by 1
----
source_tbl_source_col_target_col_fkey
target_tbl_target_col_pkey
query II
select constraint_name, unique_constraint_name
from information_schema.referential_constraints;
----
source_tbl_source_col_target_col_fkey target_tbl_target_col_pkey
# multiple constraints
statement ok
DROP TABLE source_tbl;
statement ok
DROP TABLE target_tbl;
statement ok
CREATE TABLE a (
a1 INT, a2 INT, a3 INT,
UNIQUE (a1, a2), UNIQUE (a2, a3)
);
statement ok
CREATE TABLE b (
a1 INT, a2 INT, a3 INT,
FOREIGN KEY (a1, a2) REFERENCES a (a1, a2),
FOREIGN KEY (a2, a3) REFERENCES a (a2, a3)
);
query II
SELECT constraint_name, constraint_type FROM information_schema.table_constraints ORDER BY ALL
----
a_a1_a2_key UNIQUE
a_a2_a3_key UNIQUE
b_a1_a2_a1_a2_fkey FOREIGN KEY
b_a2_a3_a2_a3_fkey FOREIGN KEY

View File

@@ -0,0 +1,17 @@
# name: test/sql/table_function/information_schema_issue12867.test
# description: Issue #12867: INFORMATION_SCHEMA.KEY_COLUMN_USAGE only lists first column of composite keys
# group: [table_function]
statement ok
CREATE TABLE a (a1 int, a2 int, PRIMARY KEY (a1, a2));
statement ok
CREATE TABLE b (a1 int, a2 int, FOREIGN KEY (a1, a2) REFERENCES a);
query III
SELECT table_name, column_name, ordinal_position FROM information_schema.key_column_usage ORDER BY table_name, ordinal_position;
----
a a1 1
a a2 2
b a1 1
b a2 2

View File

@@ -0,0 +1,16 @@
# name: test/sql/table_function/information_schema_types.test
# description: Issue #11281: duckdb_columns() produces NULL value as DATA_TYPE for certain INFORMATION_SCHEMA columns
# group: [table_function]
# Verify all columns in the information_schema have explicitly defined types
statement ok
pragma enable_verification
query II
select table_name, column_name
from duckdb_columns()
where database_name = 'system'
and schema_name = 'information_schema'
and data_type = 'NULL'
----

View File

@@ -0,0 +1,17 @@
# name: test/sql/table_function/lateral_table_function.test
# description: Test lateral join table function parameters for functions that do not support it
# group: [table_function]
statement ok
pragma enable_verification
statement error
SELECT * FROM read_csv(thisishopefullyanonexistentfile)
----
No files found that match the pattern
# lateral join parameter
statement error
SELECT * FROM (SELECT 'myfile.csv' AS thisishopefullyanonexistentfile), read_csv(thisishopefullyanonexistentfile)
----
does not support lateral join column parameters

View File

@@ -0,0 +1,68 @@
# name: test/sql/table_function/range_function_different_iterators.test
# description: Issue #2584: select * from range(4,15,6) miss one value 10
# group: [table_function]
query I
select * from range(4,15,6);
----
4
10
query I
select * from range(-4,-15,-6);
----
-4
-10
query I
select * from range(4,15);
----
4
5
6
7
8
9
10
11
12
13
14
query I
select * from range(4,15,3)a;
----
4
7
10
13
query I
select * from range(-4,-15,-3)a;
----
-4
-7
-10
-13
query I
select * from range(4,15,5)a;
----
4
9
14
query I
select * from range(4,19,5)a;
----
4
9
14
query I
select * from generate_series(4,19,5)a;
----
4
9
14
19

View File

@@ -0,0 +1,134 @@
# name: test/sql/table_function/range_function_lateral.test
# description: Test range functions with lateral functions
# group: [table_function]
statement ok
PRAGMA enable_verification
query I
SELECT * FROM range(1, NULL, 1);
----
query II
SELECT * FROM (SELECT NULL a), range(a);
----
query II
SELECT * FROM (SELECT NULL a), range(timestamp '2010-01-01', a, null);
----
query II
SELECT * FROM range(3) t(i), range(i) t2(j) ORDER BY i, j;
----
1 0
2 0
2 1
query III
SELECT * FROM range(4) t(i), range(i) t2(j), range(j) t3(k) ORDER BY i, j, k;
----
2 1 0
3 1 0
3 2 0
3 2 1
query III
SELECT * FROM generate_series(0,2) t(i), generate_series(0,i) t2(j), generate_series(0,j) t3(k) ORDER BY i, j, k;
----
0 0 0
1 0 0
1 1 0
1 1 1
2 0 0
2 1 0
2 1 1
2 2 0
2 2 1
2 2 2
query IIII
SELECT i, j, l, str FROM (SELECT ARRAY['null'], NULL, 'null' UNION ALL SELECT ARRAY['five'], 5, 'five' UNION ALL SELECT ARRAY['two'], 2, 'two') t(l, i, str), generate_series(0,i-1) t2(j) order by i, j
----
2 0 [two] two
2 1 [two] two
5 0 [five] five
5 1 [five] five
5 2 [five] five
5 3 [five] five
5 4 [five] five
query II
SELECT * FROM (SELECT 42 WHERE 42>84) t(i), range(i) t2(j)
----
statement error
SELECT * FROM (SELECT '5'::VARCHAR) t(str), range(str) t2(j)
----
No function matches the given name and argument types
statement ok
PREPARE v1 AS SELECT * FROM range(?);
query I
EXECUTE v1(5)
----
0
1
2
3
4
query IIII
SELECT * FROM (SELECT 3, 1, -1 UNION ALL SELECT 1, 3, 2) t(s, e, increment), range(s, e, increment) t2(j) ORDER BY s, j
----
1 3 2 1
3 1 -1 2
3 1 -1 3
query IIII
SELECT * FROM (SELECT DATE '2000-01-01', DATE '2000-10-1', INTERVAL '3' MONTHS) t(s, e, increment), range(s, e, increment) t2(j) ORDER BY s, j
----
2000-01-01 2000-10-01 3 months 2000-01-01 00:00:00
2000-01-01 2000-10-01 3 months 2000-04-01 00:00:00
2000-01-01 2000-10-01 3 months 2000-07-01 00:00:00
query IIII
SELECT * FROM (SELECT DATE '2000-01-01', DATE '2000-10-1', INTERVAL '3' MONTHS) t(s, e, increment), generate_series(s, e, increment) t2(j) ORDER BY s, j
----
2000-01-01 2000-10-01 3 months 2000-01-01 00:00:00
2000-01-01 2000-10-01 3 months 2000-04-01 00:00:00
2000-01-01 2000-10-01 3 months 2000-07-01 00:00:00
2000-01-01 2000-10-01 3 months 2000-10-01 00:00:00
query IIII
SELECT * FROM (SELECT DATE '2000-01-01', DATE '2000-10-1', NULL) t(s, e, increment), generate_series(s, e, increment) t2(j) ORDER BY s, j
----
# many rows
query I
select count(*) from (values (1), (10), (100), (1000), (10000)) t(a), range(a);
----
11111
require icu
statement ok
SET TimeZone='UTC'
query IIII
SELECT * FROM (SELECT TIMESTAMPTZ '2000-01-01', TIMESTAMPTZ '2000-10-1', INTERVAL '3' MONTHS) t(s, e, increment), range(s, e, increment) t2(j) ORDER BY s, j
----
2000-01-01 00:00:00+00 2000-10-01 00:00:00+00 3 months 2000-01-01 00:00:00+00
2000-01-01 00:00:00+00 2000-10-01 00:00:00+00 3 months 2000-04-01 00:00:00+00
2000-01-01 00:00:00+00 2000-10-01 00:00:00+00 3 months 2000-07-01 00:00:00+00
query IIII
SELECT * FROM (SELECT TIMESTAMPTZ '2000-01-01', TIMESTAMPTZ '2000-10-1', NULL) t(s, e, increment), range(s, e, increment) t2(j) ORDER BY s, j
----
query IIII
SELECT * FROM (SELECT TIMESTAMPTZ '2000-01-01', TIMESTAMPTZ '2000-10-1', NULL UNION ALL SELECT TIMESTAMPTZ '2000-10-01', TIMESTAMPTZ '2000-01-1', INTERVAL '-3 months') t(s, e, increment), range(s, e, increment) t2(j) ORDER BY s, j
----
2000-10-01 00:00:00+00 2000-01-01 00:00:00+00 -3 months 2000-04-01 00:00:00+00
2000-10-01 00:00:00+00 2000-01-01 00:00:00+00 -3 months 2000-07-01 00:00:00+00
2000-10-01 00:00:00+00 2000-01-01 00:00:00+00 -3 months 2000-10-01 00:00:00+00

View File

@@ -0,0 +1,36 @@
# name: test/sql/table_function/range_non_foldable.test
# description: Issue #5546: non-foldable constant parameters to table function
# group: [table_function]
require no_extension_autoloading "FIXME: Unimplemented type for cast (TIMESTAMP WITH TIME ZONE -> DATE)"
require icu
statement ok
PRAGMA enable_verification
query I
SELECT COUNT(*)
FROM range(
current_date,
current_date + interval '7' days,
interval '1 day'
)
----
7
statement ok
SELECT to_timestamp(range) as entry
FROM range(
epoch(date_trunc('month', current_date))::BIGINT,
epoch(date_trunc('month', current_date) + interval '1 month' - interval '1 day')::BIGINT,
epoch(interval '1 day')::BIGINT
)
statement ok
SELECT to_timestamp(range) as entry
FROM range(
epoch(date_trunc('month', current_date))::BIGINT,
epoch(date_trunc('month', current_date) + interval '1 month' - interval '1 day')::BIGINT,
epoch(interval '1 day')::BIGINT
)

View File

@@ -0,0 +1,169 @@
# name: test/sql/table_function/range_timestamp.test
# description: Test range function with DATE/TIMESTAMP
# group: [table_function]
# date
query I
SELECT d::DATE FROM range(DATE '1992-01-01', DATE '1992-10-01', INTERVAL (1) MONTH) tbl(d)
----
1992-01-01
1992-02-01
1992-03-01
1992-04-01
1992-05-01
1992-06-01
1992-07-01
1992-08-01
1992-09-01
# range is exclusive
query I
SELECT * FROM range(date '1992-01-01', date '1992-01-01', interval '1' month);
----
# generate_series is inclusive
query I
SELECT d::DATE FROM generate_series(DATE '1992-01-01', DATE '1992-10-01', INTERVAL (1) MONTH) tbl(d)
----
1992-01-01
1992-02-01
1992-03-01
1992-04-01
1992-05-01
1992-06-01
1992-07-01
1992-08-01
1992-09-01
1992-10-01
# timestamp
query I
SELECT d FROM range(TIMESTAMP '1992-01-01 00:00:00', TIMESTAMP '1992-01-01 12:00:00', INTERVAL (1) HOUR) tbl(d)
----
1992-01-01 00:00:00
1992-01-01 01:00:00
1992-01-01 02:00:00
1992-01-01 03:00:00
1992-01-01 04:00:00
1992-01-01 05:00:00
1992-01-01 06:00:00
1992-01-01 07:00:00
1992-01-01 08:00:00
1992-01-01 09:00:00
1992-01-01 10:00:00
1992-01-01 11:00:00
# range is exclusive
query I
SELECT * FROM range(timestamp '1992-01-01 00:00:00', timestamp '1992-01-01 00:00:00', interval '1' month);
----
query I
SELECT * FROM range(timestamp '1992-01-01 00:00:00', timestamp '1992-01-01 00:00:01', interval '1' month);
----
1992-01-01 00:00:00
# negative interval
query I
SELECT d FROM range(TIMESTAMP '1992-01-01 00:00:00', TIMESTAMP '1991-06-01 00:00:00', INTERVAL '1 MONTH ago') tbl(d)
----
1992-01-01 00:00:00
1991-12-01 00:00:00
1991-11-01 00:00:00
1991-10-01 00:00:00
1991-09-01 00:00:00
1991-08-01 00:00:00
1991-07-01 00:00:00
query I
SELECT d FROM generate_series(TIMESTAMP '1992-01-01 00:00:00', TIMESTAMP '1991-06-01 00:00:00', -INTERVAL '1 MONTH') tbl(d)
----
1992-01-01 00:00:00
1991-12-01 00:00:00
1991-11-01 00:00:00
1991-10-01 00:00:00
1991-09-01 00:00:00
1991-08-01 00:00:00
1991-07-01 00:00:00
1991-06-01 00:00:00
# composite interval
query I
SELECT d FROM range(TIMESTAMP '1992-01-01 00:00:00', TIMESTAMP '1992-12-31 12:00:00', INTERVAL '1 MONTH 1 DAY 1 HOUR') tbl(d)
----
1992-01-01 00:00:00
1992-02-02 01:00:00
1992-03-03 02:00:00
1992-04-04 03:00:00
1992-05-05 04:00:00
1992-06-06 05:00:00
1992-07-07 06:00:00
1992-08-08 07:00:00
1992-09-09 08:00:00
1992-10-10 09:00:00
1992-11-11 10:00:00
1992-12-12 11:00:00
# large result
query I
SELECT COUNT(*) FROM range(TIMESTAMP '1992-01-01 00:00:00', TIMESTAMP '2020-01-01 00:00:00', INTERVAL '1 DAY') tbl(d)
----
10227
query I
SELECT COUNT(*) FROM generate_series(TIMESTAMP '1992-01-01 00:00:00', TIMESTAMP '2020-01-01 00:00:00', INTERVAL '1 DAY') tbl(d)
----
10228
# null values result in no rows
query I
SELECT COUNT(*) FROM range(NULL, TIMESTAMP '1992-12-31 12:00:00', INTERVAL '1 MONTH') tbl(d)
----
0
query I
SELECT COUNT(*) FROM generate_series(NULL, TIMESTAMP '1992-12-31 12:00:00', INTERVAL '1 MONTH') tbl(d)
----
0
# Extreme ranges should not overflow in the binder.
statement ok
explain
from range('290309-12-22 (BC) 00:00:00'::TIMESTAMP, '294247-01-10 04:00:54.775806'::TIMESTAMP, interval '1 hour');
# zero interval not supported
statement error
SELECT d FROM range(TIMESTAMP '1992-01-01 00:00:00', TIMESTAMP '1992-12-31 12:00:00', INTERVAL '0 MONTH') tbl(d)
----
# start is smaller than end but we have a negative interval
query I
SELECT d FROM range(TIMESTAMP '1992-01-01 00:00:00', TIMESTAMP '1992-12-31 12:00:00', INTERVAL '1 MONTH ago') tbl(d)
----
# start is bigger than end but we have a positive interval
query I
SELECT d FROM range(TIMESTAMP '1993-01-01 00:00:00', TIMESTAMP '1992-01-01 00:00:00', INTERVAL '1 MONTH') tbl(d)
----
# composite interval with negative types not supported
statement error
SELECT d FROM range(TIMESTAMP '1992-01-01 00:00:00', TIMESTAMP '1992-12-31 12:00:00', INTERVAL '1 MONTH' - INTERVAL '1 HOUR') tbl(d)
----
# Infinities will overflow or cause infinite loops (PG behaviour!) so we ban them
statement error
SELECT COUNT(*) FROM generate_series('294247-01-10'::TIMESTAMP, 'infinity'::TIMESTAMP, INTERVAL '1 DAY');
----
statement error
SELECT COUNT(*) FROM range('294247-01-10'::TIMESTAMP, 'infinity'::TIMESTAMP, INTERVAL '1 DAY');
----
statement error
SELECT COUNT(*) FROM generate_series('-infinity'::TIMESTAMP, '290309-12-22 (BC) 00:00:00'::TIMESTAMP, INTERVAL '1 DAY');
----
statement error
SELECT COUNT(*) FROM range('-infinity'::TIMESTAMP, '290309-12-22 (BC) 00:00:00'::TIMESTAMP, INTERVAL '1 DAY');
----

View File

@@ -0,0 +1,66 @@
# name: test/sql/table_function/read_text_and_blob.test
# description: Test read_files function
# group: [table_function]
query I
SELECT COUNT(*) FROM read_text('test/sql/table_function/files/*.txt');
----
3
query I
SELECT COUNT(*) FROM read_blob('test/sql/table_function/files/*');
----
4
query IIII
SELECT * FROM read_text('test/sql/table_function/files/nonexistentfile.txt') ORDER BY ALL;
----
query I
SELECT parse_path(filename) FROM read_text('test/sql/table_function/files/nonexistentfile.txt') ORDER BY ALL;
----
query I
SELECT parse_path(filename) FROM read_text(['test/sql/table_function/files/one.txt', 'test/sql/table_function/files/two.txt']) ORDER BY ALL;
----
[test, sql, table_function, files, one.txt]
[test, sql, table_function, files, two.txt]
query III
SELECT parse_path(filename), size, content FROM read_blob('test/sql/table_function/files/four.blob');
----
[test, sql, table_function, files, four.blob] 178 PK\x03\x04\x0A\x00\x00\x00\x00\x00\xACi=X\x14t\xCE\xC7\x0A\x00\x00\x00\x0A\x00\x00\x00\x09\x00\x1C\x00four.blobUT\x09\x00\x03c\x96\xB7ee\x96\xB7eux\x0B\x00\x01\x04\xF5\x01\x00\x00\x04\x14\x00\x00\x00F\xC3\xB6\xC3\xB6 B\xC3\xA4rPK\x01\x02\x1E\x03\x0A\x00\x00\x00\x00\x00\xACi=X\x14t\xCE\xC7\x0A\x00\x00\x00\x0A\x00\x00\x00\x09\x00\x18\x00\x00\x00\x00\x00\x01\x00\x00\x00\xA4\x81\x00\x00\x00\x00four.blobUT\x05\x00\x03c\x96\xB7eux\x0B\x00\x01\x04\xF5\x01\x00\x00\x04\x14\x00\x00\x00PK\x05\x06\x00\x00\x00\x00\x01\x00\x01\x00O\x00\x00\x00M\x00\x00\x00\x00\x00
statement error
SELECT parse_path(filename), size, content FROM read_text('test/sql/table_function/files/four.blob');
----
Invalid Input Error: read_text: could not read content of file 'test/sql/table_function/files/four.blob' as valid UTF-8 encoded text. You may want to use read_blob instead.
query III
SELECT size, parse_path(filename), content FROM read_text('test/sql/table_function/files/*.txt') ORDER BY filename, size;
----
12 [test, sql, table_function, files, one.txt] Hello World!
2 [test, sql, table_function, files, three.txt] 42
10 [test, sql, table_function, files, two.txt] Föö Bär
# Test that the last_modified timestamp is reasonably correct
query I
SELECT last_modified > '2024-01-01' AND last_modified < '2500-01-01' FROM read_blob('test/sql/table_function/files/*');
----
true
true
true
true
# test parsing hive partitioning scheme
query IIII
select parse_path(filename), size, part, date from read_blob('data/parquet-testing/hive-partitioning/simple/*/*/test.parquet') order by filename
----
[data, parquet-testing, hive-partitioning, simple, 'part=a', 'date=2012-01-01', test.parquet] 266 a 2012-01-01
[data, parquet-testing, hive-partitioning, simple, 'part=b', 'date=2013-01-01', test.parquet] 266 b 2013-01-01
query IIII
select parse_path(filename), size, part, date from read_text('data/parquet-testing/hive-partitioning/simple/*/*/test.parquet') order by filename
----
[data, parquet-testing, hive-partitioning, simple, 'part=a', 'date=2012-01-01', test.parquet] 266 a 2012-01-01
[data, parquet-testing, hive-partitioning, simple, 'part=b', 'date=2013-01-01', test.parquet] 266 b 2013-01-01

View File

@@ -0,0 +1,63 @@
# name: test/sql/table_function/sqlite_master.test
# description: Test sqlite_master function
# group: [table_function]
statement ok
CREATE TABLE integers(i INTEGER);
query IIIII
SELECT * FROM sqlite_master;
----
table integers integers 0 CREATE TABLE integers(i INTEGER);
query I
SELECT EXISTS(SELECT * FROM sqlite_master)
----
1
query I
SELECT EXISTS(SELECT * FROM sqlite_master OFFSET 1)
----
0
query I
SELECT COUNT(*) FROM sqlite_master WHERE name='test'
----
0
query I
SELECT COUNT(*) FROM sqlite_master WHERE name='integers'
----
1
statement ok
create table tconstraint1(i integer primary key default(3), j blob not null);
query IIIII
SELECT * FROM sqlite_master WHERE name='tconstraint1';
----
table tconstraint1 tconstraint1 0 CREATE TABLE tconstraint1(i INTEGER DEFAULT(3) PRIMARY KEY, j BLOB NOT NULL);
statement ok
create table tconstraint2(i integer, j integer, k integer, l integer unique, primary key(i, j, k));
query IIIII
SELECT * FROM sqlite_master WHERE name='tconstraint2';
----
table tconstraint2 tconstraint2 0 CREATE TABLE tconstraint2(i INTEGER, j INTEGER, k INTEGER, l INTEGER UNIQUE, PRIMARY KEY(i, j, k));
statement ok
CREATE INDEX i_index ON integers(i);
query IIIII
SELECT * REPLACE (trim(sql, chr(10)) as sql) FROM sqlite_master WHERE name='i_index';
----
index i_index integers 0 CREATE INDEX i_index ON integers(i);
statement ok
CREATE VIEW v1 AS SELECT 42
query IIII
SELECT "type", "name", "tbl_name", rootpage FROM sqlite_master WHERE name='v1';
----
view v1 v1 0

View File

@@ -0,0 +1,29 @@
# name: test/sql/table_function/sqlite_master_connections.test
# description: Use the internal sqlite_master view from different tables
# group: [table_function]
statement ok con1
BEGIN TRANSACTION
statement ok con2
BEGIN TRANSACTION
statement ok con1
SELECT * FROM sqlite_master;
statement ok con2
SELECT * FROM sqlite_master;
statement ok con1
ROLLBACK
statement ok con2
ROLLBACK
statement ok
SELECT * FROM sqlite_master;
statement error
DROP VIEW sqlite_master
----
<REGEX>:.*Catalog Error.*Cannot drop internal catalog entry.*

View File

@@ -0,0 +1,48 @@
# name: test/sql/table_function/sqlite_master_quotes.test
# description: Test correct quotes in sqlite_master
# group: [table_function]
# simple quotes
statement ok
CREATE TABLE "a b c"("d e" INTEGER, f INTEGER);
query IIIII
SELECT * FROM sqlite_master;
----
table a b c a b c 0 CREATE TABLE "a b c"("d e" INTEGER, f INTEGER);
statement ok
DROP TABLE "a b c";
# quoted quotes
statement ok
CREATE TABLE "inte""gers"(i INTEGER);
query IIIII
SELECT * FROM sqlite_master;
----
table inte"gers inte"gers 0 CREATE TABLE "inte""gers"(i INTEGER);
statement ok
DROP TABLE "inte""gers"
# multi-column primary key constraint
statement ok
CREATE TABLE integers("a b" INTEGER, "c d" INTEGER, PRIMARY KEY("a b", "c d"))
query IIIII
SELECT * FROM sqlite_master;
----
table integers integers 0 CREATE TABLE integers("a b" INTEGER, "c d" INTEGER, PRIMARY KEY("a b", "c d"));
statement ok
DROP TABLE integers
# quote with numbers
statement ok
CREATE TABLE "1a"(a1 INTEGER, a2 INTEGER);
query IIIII
SELECT * FROM sqlite_master;
----
table 1a 1a 0 CREATE TABLE "1a"(a1 INTEGER, a2 INTEGER);

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,231 @@
# name: test/sql/table_function/test_range_function.test
# description: Test range functions
# group: [table_function]
query I
SELECT * FROM range(0, 10, 1)
----
0
1
2
3
4
5
6
7
8
9
query I
CALL range(10)
----
0
1
2
3
4
5
6
7
8
9
# generate_series is similar to range, but has inclusive bounds (for postgres compatibility)
query I
SELECT * FROM generate_series(0, 10, 1)
----
0
1
2
3
4
5
6
7
8
9
10
query I
SELECT * FROM range(10, 0, -1) ORDER BY 1 ASC
----
1
2
3
4
5
6
7
8
9
10
query I
SELECT * FROM generate_series(10, 0, -1) ORDER BY 1 ASC
----
0
1
2
3
4
5
6
7
8
9
10
query I
SELECT * FROM range(0, -5, -1)
----
0
-1
-2
-3
-4
statement error
SELECT * FROM range(0, 10, 0)
----
query I
SELECT * FROM range(0, 10, -1)
----
query I
SELECT * FROM range(10, 0, 1)
----
# overloads
# only one parameter defaults to start=0, interval=1
query I
SELECT * FROM range(10)
----
0
1
2
3
4
5
6
7
8
9
# two parameters defaults to interval=1
query I
SELECT * FROM range(0, 10)
----
0
1
2
3
4
5
6
7
8
9
query I
SELECT EXISTS(SELECT * FROM range(10))
----
1
query I
SELECT EXISTS(SELECT * FROM range(0))
----
0
query I
SELECT * FROM range(10) t1(j) WHERE j=3
----
3
statement error
SELECT * FROM range('hello')
----
statement error
SELECT * FROM range(10, 'hello')
----
statement error
SELECT * FROM range(10, 10, 'hello')
----
# range with big numbers
query I
select * from generate_series(-2305843009213693951, 2305843009213693951, 2305843009213693951)
----
-2305843009213693951
0
2305843009213693951
query I
select * from generate_series(2305843009213693951, -2305843009213693951, -2305843009213693951)
----
2305843009213693951
0
-2305843009213693951
query I
select * from generate_series(0, 10, 9223372036854775807);
----
0
query I
select * from generate_series(0, 9223372036854775807, 9223372036854775807);
----
0
9223372036854775807
query I
select * from generate_series(0, -9223372036854775807, -9223372036854775807);
----
0
-9223372036854775807
query I
select * from generate_series(-9223372036854775808, 9223372036854775807, 9223372036854775807);
----
-9223372036854775808
-1
9223372036854775806
query I
select * from generate_series(-9223372036854775807, -9223372036854775808, -1);
----
-9223372036854775807
-9223372036854775808
query I
select * from generate_series(-9223372036854775808, 9223372036854775807, 9223372036854775807);
----
-9223372036854775808
-1
9223372036854775806
query I
select * from generate_series(0, -9223372036854775808, -9223372036854775808);
----
0
-9223372036854775808
query I
select * from generate_series(0, 9223372036854775807, 9223372036854775807);
----
0
9223372036854775807
query I
select * from generate_series(0, 10, 9223372036854775807);
----
0
query II rowsort
select * FROM generate_series(1, 3, 1) AS _(x), generate_series(x, 2, 1) AS __(y);
----
1 1
1 2
2 2

View File

@@ -0,0 +1,64 @@
# name: test/sql/table_function/test_repeat_function.test
# description: Test repeat functions
# group: [table_function]
# test basic repeat usage
query I
SELECT * FROM repeat(0, 3)
----
0
0
0
# NULL
query I
SELECT * FROM repeat(NULL, 2)
----
NULL
NULL
# varchar
query I
SELECT * FROM repeat('hello', 2)
----
hello
hello
# long varchar
query I
SELECT * FROM repeat('thisisalongstring', 2)
----
thisisalongstring
thisisalongstring
# blob
query I
SELECT * FROM repeat(blob '\x00\x00hello', 2)
----
\x00\x00hello
\x00\x00hello
# many values
query I
SELECT * FROM repeat(1, 10000)
----
10000 values hashing to 532e2dcdbf025eccc86cb25898ca8e7a
# date
query I
SELECT * FROM repeat(DATE '1992-01-01', 2)
----
1992-01-01
1992-01-01
# interval
query I
SELECT * FROM repeat(INTERVAL '30 days', 2)
----
30 days
30 days
statement error
SELECT * FROM repeat(INTERVAL '30 days', NULL)
----
Binder Error: Repeat second parameter cannot be NULL

View File

@@ -0,0 +1,49 @@
# name: test/sql/table_function/test_table_function.test
# description: Table functions
# group: [table_function]
statement ok
PRAGMA enable_verification
statement ok
CREATE TABLE integers(i INTEGER, j INTEGER);
# SELECT * from table function
query ITTTTT
SELECT * FROM pragma_table_info('integers');
----
0 i INTEGER 0 NULL 0
1 j INTEGER 0 NULL 0
# project single column
query T
SELECT name FROM pragma_table_info('integers');
----
i
j
# project column that is not in function return
statement error
SELECT blablabla FROM pragma_table_info('integers');
----
# join with table function
statement ok
CREATE TABLE join_table(name VARCHAR, value INTEGER);
statement ok
INSERT INTO join_table VALUES ('i', 33), ('j', 44)
query TII
SELECT a.name, cid, value FROM pragma_table_info('integers') AS a INNER JOIN join_table ON a.name=join_table.name ORDER BY a.name;
----
i 0 33
j 1 44
# table function in subquery
query IT
SELECT cid, name FROM (SELECT * FROM pragma_table_info('integers')) AS a
----
0 i
1 j