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,64 @@
# name: test/sql/create/big_create_table_as.test_slow
# description: Test large CREATE TABLE AS statements
# group: [create]
statement ok
PRAGMA enable_verification
query I
CREATE TABLE integers AS SELECT * FROM range(1000000) tbl(i);
----
1000000
query I
CREATE TABLE integers2 AS SELECT * FROM integers;
----
1000000
query II
SELECT COUNT(*), SUM(i) FROM integers2
----
1000000 499999500000
query I
SELECT * FROM integers2 LIMIT 5
----
0
1
2
3
4
query I
SELECT * FROM integers2 LIMIT 5 OFFSET 77777
----
77777
77778
77779
77780
77781
# batch insert
query I
INSERT INTO integers2 SELECT i + 1000000 FROM integers;
----
1000000
query I
SELECT * FROM integers2 LIMIT 5 OFFSET 1000000
----
1000000
1000001
1000002
1000003
1000004
query I
SELECT * FROM integers2 LIMIT 5 OFFSET 1077777
----
1077777
1077778
1077779
1077780
1077781

View File

@@ -0,0 +1,64 @@
# name: test/sql/create/big_create_table_as_varchar.test_slow
# description: Test large CREATE TABLE AS with varchar columns
# group: [create]
statement ok
PRAGMA enable_verification
query I
CREATE TABLE varchars AS SELECT i, concat('thisisalongstring', i) AS v FROM range(1000000) tbl(i);
----
1000000
query I
CREATE TABLE varchars2 AS SELECT * FROM varchars;
----
1000000
query II
SELECT COUNT(*), SUM(REPLACE(v, 'thisisalongstring', '')::INT) FROM varchars2
----
1000000 499999500000
query II
SELECT * FROM varchars2 LIMIT 5
----
0 thisisalongstring0
1 thisisalongstring1
2 thisisalongstring2
3 thisisalongstring3
4 thisisalongstring4
query II
SELECT * FROM varchars2 LIMIT 5 OFFSET 77777
----
77777 thisisalongstring77777
77778 thisisalongstring77778
77779 thisisalongstring77779
77780 thisisalongstring77780
77781 thisisalongstring77781
# batch insert
query I
INSERT INTO varchars2 SELECT i + 1000000, concat('thisisalongstring', i + 1000000) AS v FROM varchars;
----
1000000
query II
SELECT * FROM varchars2 LIMIT 5 OFFSET 1000000
----
1000000 thisisalongstring1000000
1000001 thisisalongstring1000001
1000002 thisisalongstring1000002
1000003 thisisalongstring1000003
1000004 thisisalongstring1000004
query II
SELECT * FROM varchars2 LIMIT 5 OFFSET 1077777
----
1077777 thisisalongstring1077777
1077778 thisisalongstring1077778
1077779 thisisalongstring1077779
1077780 thisisalongstring1077780
1077781 thisisalongstring1077781

View File

@@ -0,0 +1,135 @@
# name: test/sql/create/create_as.test
# description: Test CREATE TABLE AS SELECT (CTAS) statements
# group: [create]
statement ok
PRAGMA enable_verification
statement ok
CREATE TABLE tbl1 AS SELECT 1;
query I
SELECT * FROM tbl1;
----
1
statement ok
CREATE TABLE tbl2 AS SELECT 2 AS f;
query I
SELECT * FROM tbl2;
----
2
statement ok
CREATE OR REPLACE TABLE tbl3 AS SELECT 3;
query I
SELECT * FROM tbl3;
----
3
statement error
CREATE TABLE tbl1 AS SELECT 3;
----
statement ok
CREATE OR REPLACE TABLE tbl1 AS SELECT 4;
query I
SELECT * FROM tbl1;
----
4
statement ok
CREATE OR REPLACE TABLE tbl1 AS SELECT 'hello' UNION ALL SELECT 'world';
query I
SELECT * FROM tbl1;
----
hello
world
statement ok
CREATE OR REPLACE TABLE tbl1 AS SELECT 5 WHERE false;
query I
SELECT * FROM tbl1;
----
statement error
CREATE TABLE tbl4 IF NOT EXISTS AS SELECT 4;
----
Parser Error: syntax error at or near "IF"
statement error
CREATE OR REPLACE TABLE tbl4 IF NOT EXISTS AS SELECT 4;
----
Parser Error: syntax error at or near "IF"
### CREATE TABLE t(col1, col2) AS SELECT ...
statement ok
CREATE TABLE tbl4(col1, col2) AS SELECT 1, 'hello';
query II
SELECT * FROM tbl4;
----
1 hello
statement ok
CREATE OR REPLACE TABLE tbl4(col1, col2) AS SELECT 2, 'duck';
query II
SELECT * FROM tbl4;
----
2 duck
statement ok
CREATE TABLE IF NOT EXISTS tbl5(col1, col2) AS SELECT 3, 'database';
query II
SELECT * FROM tbl5;
----
3 database
# define a column name need quote
statement ok
CREATE OR REPLACE TABLE tbl5(col1, "col need ' quote") AS SELECT 3.5, 'quote';
query II
SELECT * FROM tbl5;
----
3.5 quote
#colname and query mismatch
statement ok
CREATE TABLE tbl6(col1) AS SELECT 4 ,'mismatch';
query II
SELECT * FROM tbl6;
----
4 mismatch
statement error
CREATE TABLE tbl7(col1, col2) AS SELECT 5;
----
Binder Error: Target table has more colum names than query result.
# WITH NO DATA / WITH DATA
statement ok
CREATE TABLE tbl8 AS SELECT 42 WITH NO DATA
query I
SELECT COUNT(*) FROM tbl8;
----
0
statement ok
CREATE TABLE tbl9 AS SELECT 42 WITH DATA
query I
SELECT COUNT(*) FROM tbl9;
----
1

View File

@@ -0,0 +1,16 @@
# name: test/sql/create/create_as_issue_11968.test
# group: [create]
load __TEST_DIR__/temp_create_as.db
statement ok
CREATE TABLE test (x INTEGER[]);
statement ok
INSERT INTO test SELECT CASE WHEN x <= 520 THEN [0, 0] ELSE [0] END FROM generate_series(1, 2048) s(x);
statement ok
CHECKPOINT;
statement ok
CREATE TABLE test2 AS SELECT x FROM test;

View File

@@ -0,0 +1,18 @@
# name: test/sql/create/create_database.test
# description: The binder error from the feature not yet being supported in DuckDB
# group: [create]
statement error
CREATE DATABASE mydb;
----
syntax error at or near "DATABASE"
statement error
CREATE DATABASE mydb FROM './path';
----
syntax error at or near "DATABASE"
statement error
DROP DATABASE mydb
----
syntax error at or near "DATABASE"

View File

@@ -0,0 +1,21 @@
# name: test/sql/create/create_index_on_issue_13643.test
# description: Issue #13643 - USE not affecting tables referenced after the ON keyword in CREATE INDEX
# group: [create]
statement ok
CREATE SCHEMA db0;
statement ok
USE db0;
statement ok
CREATE TABLE t0 (a BIGINT PRIMARY KEY, b INT, c INT);
statement ok
CREATE INDEX t0_idx ON t0 (b);
statement ok
CREATE UNIQUE INDEX t0_uidx ON t0 (c);
statement ok
CREATE UNIQUE INDEX t0_uidx2 ON db0.t0 (c);

View File

@@ -0,0 +1,47 @@
# name: test/sql/create/create_objects_readonly.test
# description: Test that creating objects fails on readonly database
# group: [create]
# load the DB from disk and make some test data
load __TEST_DIR__/create_objects_readonly.db
statement ok
create table t1 as select 'c1' as c1
load __TEST_DIR__/create_objects_readonly.db readonly
# cannot create a schema - database is opened in read-only mode
statement error
CREATE schema s2;
----
read-only
# cannot create a table - database is opened in read-only mode
statement error
CREATE TABLE test AS SELECT * FROM range(10) t(i);
----
read-only
# cannot create a view - database is opened in read-only mode
statement error
CREATE view v1 AS SELECT * FROM range(10) t(i);
----
read-only
# cannot create a macro - database is opened in read-only mode
statement error
CREATE macro add(a, b) AS a + b;
----
read-only
# cannot create a type - database is opened in read-only mode
statement error
CREATE TYPE mood AS ENUM ('happy', 'sad', 'curious');
----
read-only
# cannot create a sequence - database is opened in read-only mode
statement error
CREATE SEQUENCE serial START 101;
----
read-only

View File

@@ -0,0 +1,31 @@
# name: test/sql/create/create_or_replace.test
# description: Test CREATE OR REPLACE TABLE
# group: [create]
statement ok
PRAGMA enable_verification
statement ok
CREATE TABLE integers(i INTEGER)
statement ok
CREATE OR REPLACE TABLE integers(i INTEGER, j INTEGER)
statement ok
CREATE VIEW integers2 AS SELECT 42
statement error
CREATE OR REPLACE TABLE integers2(i INTEGER)
----
<REGEX>:.*Catalog Error.*is of type View.*
statement ok
CREATE TABLE IF NOT EXISTS integers(i INTEGER)
statement ok
INSERT INTO integers VALUES (1, 2);
statement error
CREATE OR REPLACE TABLE IF NOT EXISTS integers(i INTEGER)
----
<REGEX>:.*Parser Error: syntax error.*

View File

@@ -0,0 +1,99 @@
# name: test/sql/create/create_table_as_duplicate_names.test
# description: Test CREATE TABLE AS with duplicate column names
# group: [create]
statement ok
PRAGMA enable_verification
query II rowsort
SELECT * FROM range(5) tbl1(i) JOIN range(5) tbl2(i) ON tbl1.i=tbl2.i;
----
0 0
1 1
2 2
3 3
4 4
query II
SELECT i, i FROM range(5) tbl(i)
----
0 0
1 1
2 2
3 3
4 4
query II
SELECT * FROM (SELECT i, i FROM range(5) tbl(i)) tbl;
----
0 0
1 1
2 2
3 3
4 4
query IIII
SELECT * FROM (SELECT i, i, i, i FROM range(5) tbl(i)) tbl;
----
0 0 0 0
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
statement ok
CREATE TABLE t1 AS SELECT i, i FROM range(5) tbl(i)
query II
SELECT * FROM t1;
----
0 0
1 1
2 2
3 3
4 4
statement ok
CREATE TABLE t2 AS SELECT i, i, i, i FROM range(5) tbl(i)
query IIII
SELECT * FROM (SELECT i, i, i, i FROM range(5) tbl(i)) tbl;
----
0 0 0 0
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
query II rowsort
SELECT * FROM (SELECT * FROM range(5) tbl1(i) JOIN range(5) tbl2(i) ON tbl1.i=tbl2.i) tbl;
----
0 0
1 1
2 2
3 3
4 4
statement ok
CREATE TABLE t3 AS SELECT tbl1.i, tbl2.i FROM range(5) tbl1(i) JOIN range(5) tbl2(i) ON tbl1.i=tbl2.i;
query II rowsort
SELECT * FROM t3
----
0 0
1 1
2 2
3 3
4 4
statement ok
CREATE TABLE t4 AS SELECT * FROM range(5) tbl1(i) JOIN range(5) tbl2(i) ON tbl1.i=tbl2.i;
query II rowsort
SELECT * FROM t4
----
0 0
1 1
2 2
3 3
4 4

View File

@@ -0,0 +1,11 @@
# name: test/sql/create/create_table_as_error.test
# description: Test incorrect usage of CREATE TABLE AS
# group: [create]
statement ok
PRAGMA enable_verification
statement error
CREATE TABLE tbl AS EXECUTE tbl;
----
<REGEX>:.*Parser Error.*requires a SELECT clause.*

View File

@@ -0,0 +1,188 @@
# name: test/sql/create/create_table_compression.test
# description: Test CREATE TABLE using compression options
# group: [create]
# This test defaults to another compression function for smaller block sizes,
# because the bitpacking groups no longer fit the blocks.
require block_size 262144
require skip_reload
statement ok
PRAGMA enable_verification
statement ok
CREATE TABLE T (a INTEGER USING COMPRESSION RLE)
statement ok
DROP TABLE T
statement error
CREATE TABLE T (a INTEGER USING COMPRESSION 'bla')
----
statement error
CREATE TABLE T (a INTEGER USING COMPRESSION )
----
Parser Error: syntax error at or near ")"
statement error
CREATE TABLE T (a INTEGER NOT NULL USING COMPRESSION )
----
Parser Error: syntax error at or near ")"
statement error
CREATE TABLE T (a INTEGER USING COMPRESSION bla)
----
Parser Error: Unrecognized option for column compression, expected none, uncompressed, rle, dictionary, pfor, bitpacking, fsst, chimp, patas, zstd, alp, alprd or roaring
statement ok
CREATE TABLE T (a INTEGER NOT NULL USING COMPRESSION RLE)
statement ok
DROP TABLE T
statement ok
CREATE TABLE T (a INTEGER USING COMPRESSION RLE, b VARCHAR )
statement ok
DROP TABLE T
load __TEST_DIR__/test_compression_hint.db
statement ok
CREATE TABLE T (a INTEGER USING COMPRESSION RLE, b INTEGER USING COMPRESSION BITPACKING, C INTEGER USING COMPRESSION UNCOMPRESSED)
statement ok
INSERT INTO T VALUES (1,1,1), (1,1,1), (1,1,1), (2,2,2), (2,2,2), (3,3,3)
query III
SELECT * FROM T
----
1 1 1
1 1 1
1 1 1
2 2 2
2 2 2
3 3 3
restart
query III
SELECT * FROM T
----
1 1 1
1 1 1
1 1 1
2 2 2
2 2 2
3 3 3
statement ok
CHECKPOINT
query I
SELECT compression FROM pragma_storage_info('T') WHERE segment_type ILIKE 'INTEGER' LIMIT 3
----
RLE
BitPacking
Uncompressed
statement ok
ALTER TABLE T RENAME COLUMN a TO a_1
statement ok
ALTER TABLE T RENAME COLUMN b TO b_1
statement ok
ALTER TABLE T RENAME COLUMN c TO c_1
restart
query III
SELECT * FROM T
----
1 1 1
1 1 1
1 1 1
2 2 2
2 2 2
3 3 3
query I
SELECT compression FROM pragma_storage_info('T') WHERE segment_type ILIKE 'INTEGER' LIMIT 3
----
RLE
BitPacking
Uncompressed
statement ok
ALTER TABLE T RENAME TO T_1
restart
query III
SELECT * FROM T_1
----
1 1 1
1 1 1
1 1 1
2 2 2
2 2 2
3 3 3
query I
SELECT compression FROM pragma_storage_info('T_1') WHERE segment_type ILIKE 'INTEGER' LIMIT 3
----
RLE
BitPacking
Uncompressed
# Test Drop Column
statement ok
ALTER TABLE T_1 DROP COLUMN c_1
statement ok
ALTER TABLE T_1 DROP COLUMN b_1
restart
query I
SELECT * FROM T_1
----
1
1
1
2
2
3
query I
SELECT compression FROM pragma_storage_info('T_1') WHERE segment_type ILIKE 'INTEGER' LIMIT 2
----
RLE
# Test Add Column
statement ok
ALTER TABLE T_1 ADD COLUMN b INTEGER DEFAULT 2
restart
query II
SELECT * FROM T_1
----
1 2
1 2
1 2
2 2
2 2
3 2
statement ok
CHECKPOINT
query I
SELECT compression FROM pragma_storage_info('T_1') WHERE segment_type ILIKE 'INTEGER' LIMIT 3
----
RLE
Constant

View File

@@ -0,0 +1,49 @@
# name: test/sql/create/create_table_with_arraybounds.test
# group: [create]
# Create a table with an ENUM[] type
statement ok
create table T (
vis enum ('hide', 'visible')[]
);
query I
select column_type from (describe T);
----
ENUM('hide', 'visible')[]
statement ok
attach ':memory:' as db2;
statement ok
create schema schema2;
statement ok
create schema db2.schema3;
statement ok
create type schema2.foo as VARCHAR;
statement ok
create type db2.schema3.bar as BOOL;
statement ok
create table B (
vis schema2.foo[]
);
statement ok
insert into b values (['foo', 'bar']);
query I
from b;
----
[foo, bar]
# Create a table with a USER[] type qualified with a schema and a catalog
statement error
create table B (
vis db2.schema3.bar[]
);
----
Catalog Error: Type with name bar does not exist!

View File

@@ -0,0 +1,9 @@
# name: test/sql/create/create_using_index.test
# description: Issue #9739 - DuckDB SIGSEGV when creating TABLE CONSTRAINT with non-existing INDEX
# group: [create]
statement error
CREATE TABLE t0 (i INT, CONSTRAINT any_constraint UNIQUE USING INDEX any_non_existed_index);
----
Parser Error: UNIQUE USING INDEX is not supported