should be it
This commit is contained in:
24
external/duckdb/test/sql/attach/attach_all_types.test
vendored
Normal file
24
external/duckdb/test/sql/attach/attach_all_types.test
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
# name: test/sql/attach/attach_all_types.test
|
||||
# description: Test ATTACH of a database with all types
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/attach_all_types.db' AS db1
|
||||
|
||||
statement ok
|
||||
CREATE TABLE db1.all_types AS SELECT * FROM test_all_types();
|
||||
|
||||
query II nosort all_types
|
||||
SELECT * FROM test_all_types()
|
||||
|
||||
query II nosort all_types
|
||||
SELECT * FROM db1.all_types
|
||||
|
||||
statement ok
|
||||
DETACH db1
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/attach_all_types.db' AS db1
|
||||
|
||||
query II nosort all_types
|
||||
SELECT * FROM db1.all_types
|
||||
19
external/duckdb/test/sql/attach/attach_catalog_error_early_out.test
vendored
Normal file
19
external/duckdb/test/sql/attach/attach_catalog_error_early_out.test
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
# name: test/sql/attach/attach_catalog_error_early_out.test
|
||||
# description: Test limiting 'did you mean' to the same schema.
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
SET catalog_error_max_schemas = 0;
|
||||
|
||||
loop i 0 10
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/did_you_mean_db_${i}.db';
|
||||
|
||||
endloop
|
||||
|
||||
statement error
|
||||
FROM tbl;
|
||||
----
|
||||
Catalog Error: Table with name tbl does not exist!
|
||||
Did you mean "pg_tablespace"?
|
||||
36
external/duckdb/test/sql/attach/attach_checkpoint_deadlock.test_slow
vendored
Normal file
36
external/duckdb/test/sql/attach/attach_checkpoint_deadlock.test_slow
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
# name: test/sql/attach/attach_checkpoint_deadlock.test_slow
|
||||
# description: Deadlock when checkpointing multiple databases
|
||||
# group: [attach]
|
||||
|
||||
concurrentforeach dbname foo bar i1 i2 i3 i4 i5 i6 i7 i8 i9
|
||||
|
||||
statement ok
|
||||
attach '__TEST_DIR__/checkpoint_${dbname}.duckdb' as ${dbname}
|
||||
|
||||
statement ok
|
||||
create table ${dbname}.${dbname}(foo bigint)
|
||||
|
||||
statement ok
|
||||
insert into ${dbname}.${dbname} select sum(i) from range(1000000) t(i)
|
||||
|
||||
statement maybe
|
||||
checkpoint ${dbname}
|
||||
----
|
||||
there are other write transactions
|
||||
|
||||
statement ok
|
||||
select
|
||||
coalesce(t.table_catalog, current_database()) as "database",
|
||||
t.table_schema as "schema",
|
||||
t.table_name as "name",
|
||||
t.table_type as "type",
|
||||
array_agg(c.column_name order by c.ordinal_position) as "column_names",
|
||||
array_agg(c.data_type order by c.ordinal_position) as "column_types",
|
||||
array_agg(c.is_nullable = 'YES' order by c.ordinal_position) as "column_nullable"
|
||||
from information_schema.tables t
|
||||
join information_schema.columns c on t.table_schema = c.table_schema and t.table_name = c.table_name
|
||||
where t.table_schema = 'main'
|
||||
group by 1, 2, 3, 4
|
||||
order by 1, 2, 3, 4
|
||||
|
||||
endloop
|
||||
15
external/duckdb/test/sql/attach/attach_checkpoint_vacuum.test
vendored
Normal file
15
external/duckdb/test/sql/attach/attach_checkpoint_vacuum.test
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
# name: test/sql/attach/attach_checkpoint_vacuum.test
|
||||
# description: Test ATTACH with CHECKPOINT and VACUUM
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/attach_vacuum.db' AS db1
|
||||
|
||||
statement ok
|
||||
CREATE TABLE db1.integers(i INTEGER);
|
||||
|
||||
statement ok
|
||||
CHECKPOINT db1
|
||||
|
||||
statement ok
|
||||
VACUUM db1.integers
|
||||
26
external/duckdb/test/sql/attach/attach_concurrent_checkpoint.test_slow
vendored
Normal file
26
external/duckdb/test/sql/attach/attach_concurrent_checkpoint.test_slow
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
# name: test/sql/attach/attach_concurrent_checkpoint.test_slow
|
||||
# description: Concurrently checkpoint the same database
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/concurrent_checkpoint.db' AS db
|
||||
|
||||
statement ok
|
||||
CREATE TABLE db.integers(i INTEGER);
|
||||
|
||||
concurrentloop i 0 10
|
||||
|
||||
statement ok
|
||||
INSERT INTO db.integers FROM range(1000000);
|
||||
|
||||
statement maybe
|
||||
CHECKPOINT db
|
||||
----
|
||||
other write transactions active
|
||||
|
||||
endloop
|
||||
|
||||
query II
|
||||
SELECT COUNT(*), SUM(i) FROM db.integers
|
||||
----
|
||||
10000000 4999995000000
|
||||
31
external/duckdb/test/sql/attach/attach_concurrent_detach_mix.test_slow
vendored
Normal file
31
external/duckdb/test/sql/attach/attach_concurrent_detach_mix.test_slow
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
# name: test/sql/attach/attach_concurrent_detach_mix.test_slow
|
||||
# description: Concurrently attaching/detaching/using different databases
|
||||
# group: [attach]
|
||||
|
||||
concurrentloop i 0 40
|
||||
|
||||
loop k 0 10
|
||||
|
||||
statement maybe
|
||||
ATTACH IF NOT EXISTS '__TEST_DIR__/attach_mix_${k}.db'
|
||||
----
|
||||
Unique file handle conflict
|
||||
|
||||
onlyif i<20
|
||||
statement maybe
|
||||
CREATE TABLE attach_mix_${k}.tbl${i} AS SELECT * FROM range(${k} * ${i}) t(i)
|
||||
----
|
||||
|
||||
onlyif i>=20
|
||||
statement maybe
|
||||
SELECT COUNT(*) FROM attach_mix_${k}.tbl${k}
|
||||
----
|
||||
|
||||
statement maybe
|
||||
DETACH attach_mix_${k}
|
||||
----
|
||||
database not found
|
||||
|
||||
endloop
|
||||
|
||||
endloop
|
||||
30
external/duckdb/test/sql/attach/attach_copy.test
vendored
Normal file
30
external/duckdb/test/sql/attach/attach_copy.test
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
# name: test/sql/attach/attach_copy.test
|
||||
# description: Test attach mixed with the COPY statement
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
ATTACH DATABASE ':memory:' AS db1;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE db1.test(a INTEGER, b INTEGER, c VARCHAR(10));
|
||||
|
||||
query I
|
||||
COPY db1.test FROM 'data/csv/test/test.csv';
|
||||
----
|
||||
5000
|
||||
|
||||
query I
|
||||
COPY db1.main.test FROM 'data/csv/test/test.csv';
|
||||
----
|
||||
5000
|
||||
|
||||
statement ok
|
||||
COPY db1.main.test TO '__TEST_DIR__/test.csv';
|
||||
|
||||
statement ok
|
||||
USE db1
|
||||
|
||||
query I
|
||||
COPY test FROM 'data/csv/test/test.csv';
|
||||
----
|
||||
5000
|
||||
12
external/duckdb/test/sql/attach/attach_create_index.test
vendored
Normal file
12
external/duckdb/test/sql/attach/attach_create_index.test
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
# name: test/sql/attach/attach_create_index.test
|
||||
# description: Test create index on an attached database with an alias
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
ATTACH '' AS tmp;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE tmp.t1(id int);
|
||||
|
||||
statement ok
|
||||
CREATE INDEX idx ON tmp.t1(id);
|
||||
49
external/duckdb/test/sql/attach/attach_cross_catalog.test
vendored
Normal file
49
external/duckdb/test/sql/attach/attach_cross_catalog.test
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
# name: test/sql/attach/attach_cross_catalog.test
|
||||
# description: Cross catalog dependencies should not be allowed
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
ATTACH DATABASE ':memory:' AS db1;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE test(a INTEGER);
|
||||
|
||||
# indexes always go in the same schema/catalog as the table
|
||||
statement ok
|
||||
CREATE INDEX index ON test(a)
|
||||
|
||||
# we cannot specify a database or schema when creating an index
|
||||
statement error
|
||||
CREATE INDEX db1.index ON test(a)
|
||||
----
|
||||
syntax error
|
||||
|
||||
# types can be created in different catalogs
|
||||
statement ok
|
||||
CREATE TYPE db1.mood AS ENUM('ok', 'sad', 'happy');
|
||||
|
||||
# but we can only use types from our own catalog
|
||||
# cross-catalog dependencies are not allowed
|
||||
statement ok
|
||||
CREATE TABLE db1.integers(i mood)
|
||||
|
||||
statement error
|
||||
CREATE TABLE integers(i mood)
|
||||
----
|
||||
does not exist
|
||||
|
||||
# casts search in the default catalog
|
||||
# this does not work
|
||||
statement error
|
||||
SELECT 'happy'::mood
|
||||
----
|
||||
does not exist
|
||||
|
||||
# until we specify that we are using db1
|
||||
statement ok
|
||||
USE db1
|
||||
|
||||
query I
|
||||
SELECT 'happy'::mood
|
||||
----
|
||||
happy
|
||||
71
external/duckdb/test/sql/attach/attach_custom_block_size.test
vendored
Normal file
71
external/duckdb/test/sql/attach/attach_custom_block_size.test
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
# name: test/sql/attach/attach_custom_block_size.test
|
||||
# description: Tests attaching database files with different block allocation sizes.
|
||||
# group: [attach]
|
||||
|
||||
statement error
|
||||
ATTACH '__TEST_DIR__/not_pow_of_two.db' (BLOCK_SIZE 123456);
|
||||
----
|
||||
must be a power of two
|
||||
|
||||
statement error
|
||||
ATTACH '__TEST_DIR__/exceeds_maximum.db' (BLOCK_SIZE 2147483648);
|
||||
----
|
||||
the block size must be lesser or equal than the maximum block size
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/not_default.db' (BLOCK_SIZE 16384);
|
||||
|
||||
statement error
|
||||
ATTACH '__TEST_DIR__/too_small.db' (BLOCK_SIZE 128);
|
||||
----
|
||||
must be greater or equal than the minimum
|
||||
|
||||
# default block allocation size works
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/default_size.db' (BLOCK_SIZE 262144);
|
||||
|
||||
# detach and then try to attach with a different block size parameter
|
||||
statement ok
|
||||
DETACH default_size;
|
||||
|
||||
statement error
|
||||
ATTACH '__TEST_DIR__/default_size.db' (BLOCK_SIZE 16384);
|
||||
----
|
||||
block size parameter does not match
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/default_size.db';
|
||||
|
||||
statement ok
|
||||
DETACH default_size;
|
||||
|
||||
# We detect the block allocation size in the header.
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/dbname.db' (BLOCK_SIZE 16384);
|
||||
|
||||
statement ok
|
||||
DETACH dbname;
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/dbname.db';
|
||||
|
||||
statement error
|
||||
SET default_block_size = '123456';
|
||||
----
|
||||
must be a power of two
|
||||
|
||||
statement ok
|
||||
SET default_block_size = '16384';
|
||||
|
||||
statement error
|
||||
SET default_block_size = '128';
|
||||
----
|
||||
must be greater or equal than the minimum
|
||||
|
||||
statement ok
|
||||
SET default_block_size = '262144';
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/default_size.db';
|
||||
20
external/duckdb/test/sql/attach/attach_database_size.test
vendored
Normal file
20
external/duckdb/test/sql/attach/attach_database_size.test
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
# name: test/sql/attach/attach_database_size.test
|
||||
# description: Test ATTACH mixed with database size
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/attach_database_size.db' AS db1
|
||||
|
||||
query I
|
||||
SELECT database_name FROM pragma_database_size() WHERE database_name = 'db1';
|
||||
----
|
||||
db1
|
||||
|
||||
statement ok
|
||||
ATTACH ':memory:' AS db2
|
||||
|
||||
query I
|
||||
SELECT database_name FROM pragma_database_size() WHERE database_name = 'db1' OR database_name = 'db2' ORDER BY ALL;
|
||||
----
|
||||
db1
|
||||
db2
|
||||
53
external/duckdb/test/sql/attach/attach_dbname_quotes.test
vendored
Normal file
53
external/duckdb/test/sql/attach/attach_dbname_quotes.test
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
# name: test/sql/attach/attach_dbname_quotes.test
|
||||
# description: Test ATTACH with a quoted database name
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
ATTACH ':memory:' as "my""db";
|
||||
|
||||
statement ok
|
||||
CREATE TABLE "my""db".tbl(i int);
|
||||
|
||||
statement ok
|
||||
INSERT INTO "my""db".tbl VALUES (42)
|
||||
|
||||
# use with a table name in quotes
|
||||
statement ok
|
||||
USE "my""db";
|
||||
|
||||
statement ok
|
||||
SET search_path=current_setting('search_path')
|
||||
|
||||
query I
|
||||
SELECT * FROM tbl
|
||||
----
|
||||
42
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/attach_quoated_base.db'
|
||||
|
||||
statement ok
|
||||
USE attach_quoated_base
|
||||
|
||||
statement ok
|
||||
CREATE SCHEMA "my""db"."my""schema"
|
||||
|
||||
statement ok
|
||||
CREATE TABLE "my""db"."my""schema".tbl(i int);
|
||||
|
||||
statement ok
|
||||
INSERT INTO "my""db"."my""schema".tbl VALUES (84)
|
||||
|
||||
statement ok
|
||||
USE "my""db"."my""schema"
|
||||
|
||||
query I
|
||||
SELECT * FROM tbl
|
||||
----
|
||||
84
|
||||
|
||||
statement ok
|
||||
CREATE SCHEMA """"
|
||||
|
||||
statement ok
|
||||
USE """"
|
||||
105
external/duckdb/test/sql/attach/attach_default_table.test
vendored
Normal file
105
external/duckdb/test/sql/attach/attach_default_table.test
vendored
Normal file
@@ -0,0 +1,105 @@
|
||||
# name: test/sql/attach/attach_default_table.test
|
||||
# description: Test ATTACH of a database with a default table
|
||||
# group: [attach]
|
||||
|
||||
require parquet
|
||||
|
||||
statement ok
|
||||
attach '__TEST_DIR__/test.db' as ddb (default_table 'my_table')
|
||||
|
||||
statement error
|
||||
FROM ddb
|
||||
----
|
||||
Catalog Error: Table with name ddb does not exist!
|
||||
|
||||
# Now we create the default table
|
||||
statement ok
|
||||
CREATE OR REPLACE TABLE ddb.my_table AS (SELECT 1337 as value);
|
||||
|
||||
# We can query the table by the catalog name
|
||||
query I
|
||||
from ddb
|
||||
----
|
||||
1337
|
||||
|
||||
# We can query the table using the catalog name plus the table name
|
||||
query I
|
||||
from ddb.my_table
|
||||
----
|
||||
1337
|
||||
|
||||
# We can query the table using the catalog name, default schema name and table name
|
||||
query I
|
||||
from ddb.main.my_table
|
||||
----
|
||||
1337
|
||||
|
||||
# Now we create a different table that is actually called my_table in the default catalog
|
||||
statement ok
|
||||
create table ddb as select 42 as value
|
||||
|
||||
# This creates ambiguity: however we can provide the solution to the user in the error message
|
||||
statement error
|
||||
from ddb
|
||||
----
|
||||
Catalog Error: Ambiguity detected for 'ddb': this could either refer to the 'Table' 'ddb', or the attached catalog 'ddb' which has a default table. To avoid this error, either detach the catalog and reattach under a different name, or use a fully qualified name for the 'Table': 'memory.main.ddb' or for the Catalog Default Table: 'ddb.main.my_table'.
|
||||
|
||||
# Ambiguous no more!
|
||||
query I
|
||||
from memory.main.ddb
|
||||
----
|
||||
42
|
||||
|
||||
# Join the two tables
|
||||
query II
|
||||
SELECT
|
||||
t1.value,
|
||||
t2.value
|
||||
FROM
|
||||
memory.main.ddb as t1
|
||||
JOIN
|
||||
ddb.main.my_table as t2
|
||||
ON
|
||||
t1.value != t2.value
|
||||
----
|
||||
42 1337
|
||||
|
||||
statement ok
|
||||
use ddb
|
||||
|
||||
# We can still query the delta catalog default table by its name
|
||||
query I
|
||||
from ddb
|
||||
----
|
||||
1337
|
||||
|
||||
# Or by the default delta table name (`delta_table`)
|
||||
query I
|
||||
from my_table
|
||||
----
|
||||
1337
|
||||
|
||||
# Or by specifying the default schema
|
||||
query I
|
||||
from main.my_table
|
||||
----
|
||||
1337
|
||||
|
||||
# Swith back to main catalog
|
||||
statement ok
|
||||
use memory
|
||||
|
||||
statement ok
|
||||
DROP TABLE memory.main.ddb
|
||||
|
||||
statement ok
|
||||
CREATE VIEW ddb as SELECT 1
|
||||
|
||||
statement error
|
||||
FROM ddb
|
||||
----
|
||||
Catalog Error: Ambiguity detected for 'ddb': this could either refer to the 'View' 'ddb', or the attached catalog 'ddb' which has a default table. To avoid this error, either detach the catalog and reattach under a different name, or use a fully qualified name for the 'View': 'memory.main.ddb' or for the Catalog Default Table: 'ddb.main.my_table'.
|
||||
|
||||
# view can be dropped using only the name because the default table is a table not a view
|
||||
statement ok
|
||||
DROP VIEW ddb;
|
||||
19
external/duckdb/test/sql/attach/attach_defaults.test
vendored
Normal file
19
external/duckdb/test/sql/attach/attach_defaults.test
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
# name: test/sql/attach/attach_defaults.test
|
||||
# description: Test default behavior of ATTACH statement
|
||||
# group: [attach]
|
||||
|
||||
# attach a new database
|
||||
statement ok
|
||||
ATTACH DATABASE ':memory:' AS new_database;
|
||||
|
||||
# we cannot attach a database with the same name
|
||||
statement error
|
||||
ATTACH ':memory:' AS new_database;
|
||||
----
|
||||
already exists
|
||||
|
||||
# without attach -> duplicate name (memory)
|
||||
statement error
|
||||
ATTACH ':memory:'
|
||||
----
|
||||
already exists
|
||||
54
external/duckdb/test/sql/attach/attach_dependencies.test
vendored
Normal file
54
external/duckdb/test/sql/attach/attach_dependencies.test
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
# name: test/sql/attach/attach_dependencies.test
|
||||
# description: Test that we can ATTACH databases with dependencies in the schema
|
||||
# group: [attach]
|
||||
|
||||
# foreign key
|
||||
|
||||
load __TEST_DIR__/fk.db
|
||||
|
||||
statement ok
|
||||
CREATE TABLE pk_tbl (id INTEGER PRIMARY KEY, name VARCHAR UNIQUE);
|
||||
|
||||
statement ok
|
||||
CREATE TABLE fk_tbl (id INTEGER REFERENCES pk_tbl(id));
|
||||
|
||||
# alter columns
|
||||
|
||||
load __TEST_DIR__/alter_column.db
|
||||
|
||||
statement ok
|
||||
CREATE TABLE tbl_alter_column (id INT, other INT, nn_col INT NOT NULL, rm INT, rename_c INT, my_def INT, drop_def INT DEFAULT 10, new_null_col INT);
|
||||
|
||||
statement ok
|
||||
ALTER TABLE tbl_alter_column ADD COLUMN k INTEGER;
|
||||
|
||||
statement ok
|
||||
ALTER TABLE tbl_alter_column ALTER other SET DATA TYPE VARCHAR USING concat(other, '_', 'yay');
|
||||
|
||||
statement ok
|
||||
ALTER TABLE tbl_alter_column ALTER COLUMN nn_col DROP NOT NULL;
|
||||
|
||||
statement ok
|
||||
ALTER TABLE tbl_alter_column DROP rm;
|
||||
|
||||
statement ok
|
||||
ALTER TABLE tbl_alter_column RENAME rename_c TO my_new_col;
|
||||
|
||||
statement ok
|
||||
ALTER TABLE tbl_alter_column ALTER COLUMN my_def SET DEFAULT 10;
|
||||
|
||||
statement ok
|
||||
ALTER TABLE tbl_alter_column ALTER COLUMN drop_def DROP DEFAULT;
|
||||
|
||||
statement ok
|
||||
ALTER TABLE tbl_alter_column ALTER COLUMN new_null_col SET NOT NULL;
|
||||
|
||||
# now attach all databases
|
||||
|
||||
load __TEST_DIR__/other.db
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/fk.db';
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/alter_column.db';
|
||||
82
external/duckdb/test/sql/attach/attach_did_you_mean.test
vendored
Normal file
82
external/duckdb/test/sql/attach/attach_did_you_mean.test
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
# name: test/sql/attach/attach_did_you_mean.test
|
||||
# description: The error messages that suggest possible alternative mixed with ATTACH
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
ATTACH DATABASE ':memory:' AS db1;
|
||||
|
||||
# did you mean errors with an attached database
|
||||
statement ok
|
||||
CREATE TABLE hello(i INTEGER);
|
||||
|
||||
statement ok
|
||||
CREATE TABLE db1.test(a INTEGER);
|
||||
|
||||
statement error
|
||||
SELECT * FROM test;
|
||||
----
|
||||
Did you mean "db1.test"
|
||||
|
||||
statement ok
|
||||
CREATE SCHEMA db1.myschema
|
||||
|
||||
statement ok
|
||||
CREATE TABLE db1.myschema.blablabla(i INTEGER)
|
||||
|
||||
statement error
|
||||
SELECT * FROM blablabla;
|
||||
----
|
||||
Did you mean "db1.myschema.blablabla"
|
||||
|
||||
statement ok
|
||||
SET catalog_error_max_schemas=0
|
||||
|
||||
# did you mean... error is skipped if max schemas is set to 0
|
||||
statement error
|
||||
SELECT * FROM blablabla;
|
||||
----
|
||||
Table with name blablabla does not exist
|
||||
|
||||
statement ok
|
||||
RESET catalog_error_max_schemas
|
||||
|
||||
# what if we switch the default database?
|
||||
statement ok
|
||||
USE db1
|
||||
|
||||
statement ok
|
||||
SELECT * FROM test
|
||||
|
||||
statement error
|
||||
SELECT * FROM blablabla
|
||||
----
|
||||
Did you mean "myschema.blablabla"
|
||||
|
||||
statement ok
|
||||
SELECT * FROM myschema.blablabla
|
||||
|
||||
statement error
|
||||
SELECT * FROM hello;
|
||||
----
|
||||
Did you mean "memory.hello"
|
||||
|
||||
statement ok
|
||||
SELECT * FROM memory.hello
|
||||
|
||||
# what if we switch default database AND default schema?
|
||||
statement ok
|
||||
USE db1.myschema
|
||||
|
||||
statement ok
|
||||
SELECT * FROM blablabla
|
||||
|
||||
statement ok
|
||||
SELECT * FROM test;
|
||||
|
||||
statement ok
|
||||
SELECT * FROM db1.main.test
|
||||
|
||||
statement error
|
||||
SELECT * FROM hello;
|
||||
----
|
||||
Did you mean "memory.hello"
|
||||
25
external/duckdb/test/sql/attach/attach_different_alias.test
vendored
Normal file
25
external/duckdb/test/sql/attach/attach_different_alias.test
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
# name: test/sql/attach/attach_different_alias.test
|
||||
# description: Test ATTACH of a database with a different alias
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/attach_alias.db' AS alias1
|
||||
|
||||
statement ok
|
||||
create table alias1.tbl1 as select 1 as a;
|
||||
|
||||
query I
|
||||
FROM alias1.tbl1
|
||||
----
|
||||
1
|
||||
|
||||
statement ok
|
||||
DETACH alias1
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/attach_alias.db' AS alias2
|
||||
|
||||
query I
|
||||
FROM alias2.tbl1
|
||||
----
|
||||
1
|
||||
23
external/duckdb/test/sql/attach/attach_duckdb_type.test
vendored
Normal file
23
external/duckdb/test/sql/attach/attach_duckdb_type.test
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
# name: test/sql/attach/attach_duckdb_type.test
|
||||
# description: Test attaching a file with type DUCKDB.
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/first.db' (TYPE DUCKDB);
|
||||
|
||||
query I
|
||||
SELECT database_name FROM duckdb_databases() WHERE database_name = 'first';
|
||||
----
|
||||
first
|
||||
|
||||
# DUCKDB type does not allow unrecognized options.
|
||||
|
||||
statement error
|
||||
ATTACH '__TEST_DIR__/error.db' (TYPE DUCKDB, HELLO, OPTION 2);
|
||||
----
|
||||
<REGEX>:Binder Error.*Unrecognized option for attach.*
|
||||
|
||||
statement error
|
||||
ATTACH '__TEST_DIR__/error.db' (HELLO, OPTION 2);
|
||||
----
|
||||
<REGEX>:Binder Error.*Unrecognized option for attach.*
|
||||
32
external/duckdb/test/sql/attach/attach_enable_external_access.test
vendored
Normal file
32
external/duckdb/test/sql/attach/attach_enable_external_access.test
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
# name: test/sql/attach/attach_enable_external_access.test
|
||||
# description: enable_external_access with attached databases
|
||||
# group: [attach]
|
||||
|
||||
# attach multiple different databases
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/attach_access1.db' AS a1
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/attach_access2.db' AS a2
|
||||
|
||||
statement ok
|
||||
SET enable_external_access=false
|
||||
|
||||
# we can modify any database that was attached prior to
|
||||
statement ok
|
||||
CREATE TABLE a1.test (a INTEGER PRIMARY KEY, b INTEGER);
|
||||
|
||||
statement ok
|
||||
CHECKPOINT a1
|
||||
|
||||
# however, we cannot attach new database files
|
||||
statement ok
|
||||
CREATE TABLE a2.test (a INTEGER PRIMARY KEY, b INTEGER);
|
||||
|
||||
statement ok
|
||||
CHECKPOINT a2
|
||||
|
||||
statement error
|
||||
ATTACH '__TEST_DIR__/attach_access3.db' AS a2
|
||||
----
|
||||
Permission Error
|
||||
63
external/duckdb/test/sql/attach/attach_encrypted_db_key_test.test
vendored
Normal file
63
external/duckdb/test/sql/attach/attach_encrypted_db_key_test.test
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
# name: test/sql/attach/attach_encrypted_db_key_test.test
|
||||
# group: [attach]
|
||||
|
||||
# workaround - alternative verify always forces the latest storage
|
||||
require no_alternative_verify
|
||||
|
||||
statement error
|
||||
ATTACH '__TEST_DIR__/encrypted.duckdb' AS encrypted (ENCRYPTION_KEY);
|
||||
----
|
||||
Binder Error: "true" is not a valid key. A key must be of type VARCHAR
|
||||
|
||||
# a base64 key as input
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/base64_encrypted.duckdb' AS base64 (ENCRYPTION_KEY 'sYfVG1ZZN1mdtMP7Hd+2KLoU1iqglOMQQmhMm7ZnB8o=');
|
||||
|
||||
# a not base64 encoded key
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/nobase64_encrypted.duckdb' AS nobase64 (ENCRYPTION_KEY 'gH8@#v$k1!!9=+=rYZ^32x==0plm*');
|
||||
|
||||
statement error
|
||||
ATTACH '__TEST_DIR__/encrypted.duckdb' AS encrypted (ENCRYPTION_KEY '');
|
||||
----
|
||||
Binder Error: Not a valid key. A key cannot be empty
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/encrypted.duckdb' AS encrypted (ENCRYPTION_KEY 'asdf');
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/encrypted_aws_key.duckdb' AS encrypted_aws (ENCRYPTION_KEY 'wJalrXUtnFEMI/K7MDENG/bPxRfiCY0000EXAMPLEKEY');
|
||||
|
||||
statement ok
|
||||
DETACH encrypted
|
||||
|
||||
statement ok
|
||||
DETACH encrypted_aws
|
||||
|
||||
statement error
|
||||
ATTACH '__TEST_DIR__/encrypted.duckdb' AS encrypted (ENCRYPTION_KEY 'xxxx');
|
||||
----
|
||||
Wrong encryption key used to open the database file
|
||||
|
||||
statement error
|
||||
ATTACH '__TEST_DIR__/encrypted.duckdb' AS encrypted;
|
||||
----
|
||||
|
||||
statement error
|
||||
ATTACH '__TEST_DIR__/encrypted.duckdb' AS encrypted (ENCRYPTION_KEY 'asdfx');
|
||||
----
|
||||
Wrong encryption key used to open the database file
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/encrypted.duckdb' AS encrypted (ENCRYPTION_KEY 'asdf');
|
||||
|
||||
statement error
|
||||
ATTACH '__TEST_DIR__/encrypted_aws_key.duckdb' AS encrypted_aws (ENCRYPTION_KEY 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEX');
|
||||
----
|
||||
Wrong encryption key used to open the database file
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/encrypted_aws_key.duckdb' AS encrypted_aws (ENCRYPTION_KEY 'wJalrXUtnFEMI/K7MDENG/bPxRfiCY0000EXAMPLEKEY');
|
||||
|
||||
|
||||
|
||||
82
external/duckdb/test/sql/attach/attach_encryption_block_header.test
vendored
Normal file
82
external/duckdb/test/sql/attach/attach_encryption_block_header.test
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
# name: test/sql/attach/attach_encryption_block_header.test
|
||||
# group: [attach]
|
||||
|
||||
# workaround - alternative verify always forces the latest storage
|
||||
require no_alternative_verify
|
||||
|
||||
statement error
|
||||
ATTACH '__TEST_DIR__/encrypted.duckdb' AS encrypted (ENCRYPTION_KEY '');
|
||||
----
|
||||
Binder Error: Not a valid key. A key cannot be empty
|
||||
|
||||
statement error
|
||||
ATTACH '__TEST_DIR__/encrypted.duckdb' AS encrypted (ENCRYPTION_KEY 42);
|
||||
----
|
||||
Binder Error: "42" is not a valid key. A key must be of type VARCHAR
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/encrypted.duckdb' AS encrypted (ENCRYPTION_KEY 'asdf');
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/unencrypted.duckdb' (STORAGE_VERSION 'v1.0.0');
|
||||
|
||||
statement ok
|
||||
CREATE OR REPLACE TABLE encrypted.tbl AS SELECT * FROM range(10) t(i);
|
||||
|
||||
statement ok
|
||||
CREATE OR REPLACE TABLE unencrypted.tbl AS SELECT * FROM range(10) t(i);
|
||||
|
||||
query I
|
||||
SELECT SUM(i) FROM encrypted.tbl
|
||||
----
|
||||
45
|
||||
|
||||
query I
|
||||
SELECT SUM(i) FROM unencrypted.tbl
|
||||
----
|
||||
45
|
||||
|
||||
statement ok
|
||||
DETACH encrypted
|
||||
|
||||
statement ok
|
||||
DETACH unencrypted
|
||||
|
||||
statement error
|
||||
ATTACH '__TEST_DIR__/encrypted.duckdb' AS encrypted
|
||||
----
|
||||
|
||||
statement error
|
||||
ATTACH '__TEST_DIR__/unencrypted.duckdb' AS unencrypted (ENCRYPTION_KEY 'asdf');
|
||||
----
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/unencrypted.duckdb';
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/encrypted.duckdb' AS encrypted (ENCRYPTION_KEY 'asdf');
|
||||
|
||||
query I
|
||||
SELECT SUM(i) FROM encrypted.tbl
|
||||
----
|
||||
45
|
||||
|
||||
query I
|
||||
SELECT tags FROM duckdb_databases() WHERE database_name LIKE '%encrypted%' ORDER BY database_name;
|
||||
----
|
||||
{storage_version=v1.4.0+}
|
||||
{storage_version=v1.0.0+}
|
||||
|
||||
statement ok
|
||||
DETACH encrypted
|
||||
|
||||
statement ok
|
||||
DETACH unencrypted
|
||||
|
||||
statement error
|
||||
ATTACH '__TEST_DIR__/incompatible_parameters.duckdb' (ENCRYPTION_KEY 'asdf', STORAGE_VERSION 'v1.2.0');
|
||||
----
|
||||
Invalid Input Error: Explicit provided STORAGE_VERSION ("v1.2.0") and ENCRYPTION_KEY (storage >= v1.4.0) are not compatible
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/compatible_parameters.duckdb' (ENCRYPTION_KEY 'asdf', STORAGE_VERSION 'v1.4.0');
|
||||
83
external/duckdb/test/sql/attach/attach_enums.test
vendored
Normal file
83
external/duckdb/test/sql/attach/attach_enums.test
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
# name: test/sql/attach/attach_enums.test
|
||||
# description: Test ATTACH of a database with custom enums
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/attach_enums.db' AS db1
|
||||
|
||||
statement ok
|
||||
CREATE TYPE db1.mood AS ENUM ('sad', 'ok', 'happy');
|
||||
|
||||
query I
|
||||
SELECT enum_range(NULL::db1.mood) AS my_enum_range;
|
||||
----
|
||||
[sad, ok, happy]
|
||||
|
||||
query I
|
||||
SELECT enum_range(NULL::db1.main.mood) AS my_enum_range;
|
||||
----
|
||||
[sad, ok, happy]
|
||||
|
||||
statement error
|
||||
SELECT enum_range(NULL::xx.db1.main.mood) AS my_enum_range;
|
||||
----
|
||||
Too many qualifications for type name
|
||||
|
||||
statement ok
|
||||
DROP TYPE db1.mood
|
||||
|
||||
statement ok
|
||||
DROP TYPE IF EXISTS db1.main.mood
|
||||
|
||||
statement ok
|
||||
CREATE TYPE db1.mood AS ENUM ('sad', 'ok', 'happy');
|
||||
|
||||
statement ok
|
||||
CREATE TABLE db1.person (
|
||||
name text,
|
||||
current_mood mood
|
||||
);
|
||||
|
||||
statement ok
|
||||
INSERT INTO db1.person VALUES ('Moe', 'happy');
|
||||
|
||||
query TT
|
||||
select * from db1.person
|
||||
----
|
||||
Moe happy
|
||||
|
||||
statement ok
|
||||
DETACH db1
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/attach_enums.db' AS db1 (READ_ONLY)
|
||||
|
||||
query TT
|
||||
select * from db1.person
|
||||
----
|
||||
Moe happy
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/attach_enums_2.db' AS db2
|
||||
|
||||
statement ok
|
||||
CREATE TYPE db2.mood AS ENUM ('ble','grr','kkcry');
|
||||
|
||||
statement ok
|
||||
CREATE TABLE db2.person (
|
||||
name text,
|
||||
current_mood mood
|
||||
);
|
||||
|
||||
statement ok
|
||||
INSERT INTO db2.person VALUES ('Moe', 'kkcry');
|
||||
|
||||
query TT
|
||||
select * from db1.person
|
||||
----
|
||||
Moe happy
|
||||
|
||||
query TT
|
||||
select * from db2.person
|
||||
----
|
||||
Moe kkcry
|
||||
71
external/duckdb/test/sql/attach/attach_export_import.test
vendored
Normal file
71
external/duckdb/test/sql/attach/attach_export_import.test
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
# name: test/sql/attach/attach_export_import.test
|
||||
# description: Test ATTACH with export and import
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
ATTACH ':memory:' AS db1
|
||||
|
||||
statement ok
|
||||
ATTACH ':memory:' as other
|
||||
|
||||
statement ok
|
||||
USE db1;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE db1.integers(i INTEGER);
|
||||
|
||||
statement ok
|
||||
INSERT INTO db1.integers VALUES (1), (2), (3), (NULL);
|
||||
|
||||
# FIXME: when we don't use 'USE' then we have to refer to 'integers' as 'db1.integers'
|
||||
# this breaks when re-imported, because the table will be created as just 'integers', not 'db1.integers'
|
||||
|
||||
# Create a view that references the integers table
|
||||
statement ok
|
||||
CREATE VIEW db1.integers_view AS SELECT * FROM integers;
|
||||
|
||||
statement ok
|
||||
BEGIN TRANSACTION;
|
||||
|
||||
# Create a table that should not be exported
|
||||
statement ok
|
||||
CREATE TABLE other.dont_export_me (i integer);
|
||||
|
||||
# now export the db
|
||||
statement ok
|
||||
EXPORT DATABASE db1 TO '__TEST_DIR__/export_test' (FORMAT CSV)
|
||||
|
||||
statement ok
|
||||
rollback;
|
||||
|
||||
statement ok
|
||||
drop table db1.integers CASCADE;
|
||||
|
||||
statement error
|
||||
SELECT * FROM integers
|
||||
----
|
||||
does not exist
|
||||
|
||||
statement ok
|
||||
drop view integers_view;
|
||||
|
||||
statement ok
|
||||
IMPORT DATABASE '__TEST_DIR__/export_test'
|
||||
|
||||
query I nosort q1
|
||||
SELECT * FROM integers ORDER BY i NULLS LAST
|
||||
----
|
||||
|
||||
# FIXME: this seems to be bugged
|
||||
# the view doesn't seem to get exported/imported correctly:
|
||||
|
||||
# Catalog Error: Table with name integers_view does not exist!
|
||||
query I nosort q1
|
||||
SELECT * FROM integers_view order by i NULLS LAST;
|
||||
----
|
||||
|
||||
statement error
|
||||
SELECT * FROM other.dont_export_me;
|
||||
----
|
||||
Catalog Error: Table with name dont_export_me does not exist!
|
||||
|
||||
20
external/duckdb/test/sql/attach/attach_expr.test
vendored
Normal file
20
external/duckdb/test/sql/attach/attach_expr.test
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
# name: test/sql/attach/attach_expr.test
|
||||
# description: Test ATTACH with expressions in the parameter list
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement ok
|
||||
SET VARIABLE db_type='DUCKDB'
|
||||
|
||||
statement ok
|
||||
ATTACH ':memory:' AS db1 (TYPE getvariable('db_type'))
|
||||
|
||||
statement ok
|
||||
SET VARIABLE db_type='UNKNOWN_TYPE'
|
||||
|
||||
statement error
|
||||
ATTACH ':memory:' AS db2 (TYPE getvariable('db_type'))
|
||||
----
|
||||
unknown_type
|
||||
15
external/duckdb/test/sql/attach/attach_external_access.test
vendored
Normal file
15
external/duckdb/test/sql/attach/attach_external_access.test
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
# name: test/sql/attach/attach_external_access.test
|
||||
# description: Test ATTACH with enable external access set to false
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
SET enable_external_access=false
|
||||
|
||||
# we can attach in-memory databases
|
||||
statement ok
|
||||
ATTACH ':memory:' AS db1
|
||||
|
||||
statement error
|
||||
ATTACH 'mydb.db' AS db2
|
||||
----
|
||||
Permission Error
|
||||
109
external/duckdb/test/sql/attach/attach_filepath_roundtrip.test
vendored
Normal file
109
external/duckdb/test/sql/attach/attach_filepath_roundtrip.test
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
# name: test/sql/attach/attach_filepath_roundtrip.test
|
||||
# description: Test file path roundtripping and concurrency
|
||||
# group: [attach]
|
||||
|
||||
require notwindows
|
||||
|
||||
# use a concurrent loop to attach many databases
|
||||
|
||||
concurrentloop i 1 100
|
||||
|
||||
statement maybe
|
||||
ATTACH '__TEST_DIR__/concurrent.db';
|
||||
----
|
||||
|
||||
endloop
|
||||
|
||||
query I
|
||||
SELECT database_name FROM duckdb_databases() WHERE database_name = 'concurrent';
|
||||
----
|
||||
concurrent
|
||||
|
||||
statement ok
|
||||
DETACH concurrent;
|
||||
|
||||
# roundtrip
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/db1.db';
|
||||
|
||||
statement ok
|
||||
DETACH db1;
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/db1.db';
|
||||
|
||||
# multiple connections
|
||||
|
||||
statement ok con2
|
||||
ATTACH '__TEST_DIR__/con2_rollback_detach.db';
|
||||
|
||||
statement ok con1
|
||||
START TRANSACTION;
|
||||
|
||||
statement ok con2
|
||||
START TRANSACTION;
|
||||
|
||||
# attach files in con1
|
||||
|
||||
statement ok con1
|
||||
ATTACH '__TEST_DIR__/con1.db';
|
||||
|
||||
statement ok con1
|
||||
ATTACH '__TEST_DIR__/con1_commit.db';
|
||||
|
||||
# detach file in con2
|
||||
|
||||
statement ok con2
|
||||
DETACH con2_rollback_detach;
|
||||
|
||||
# detach is instant - so we can attach
|
||||
|
||||
statement ok con1
|
||||
ATTACH '__TEST_DIR__/con2_rollback_detach.db';
|
||||
|
||||
statement ok con1
|
||||
DETACH con2_rollback_detach
|
||||
|
||||
# can't attach con1.db file in con2
|
||||
statement error con2
|
||||
ATTACH '__TEST_DIR__/con1.db';
|
||||
----
|
||||
already attached by database
|
||||
|
||||
statement ok con1
|
||||
DETACH con1;
|
||||
|
||||
# we still can't attach (need to commit the DETACH)
|
||||
|
||||
statement error con2
|
||||
ATTACH '__TEST_DIR__/con1.db';
|
||||
----
|
||||
already attached by database
|
||||
|
||||
# commit con1 and roll back con2
|
||||
|
||||
statement ok con1
|
||||
COMMIT;
|
||||
|
||||
statement ok con2
|
||||
ROLLBACK
|
||||
|
||||
# now we can ATTACH, as we committed the DETACH
|
||||
|
||||
statement ok con2
|
||||
ATTACH '__TEST_DIR__/con1.db';
|
||||
|
||||
statement error con1
|
||||
ATTACH '__TEST_DIR__/con1.db';
|
||||
----
|
||||
already attached
|
||||
|
||||
statement error con2
|
||||
ATTACH '__TEST_DIR__/con1_commit.db';
|
||||
----
|
||||
already attached
|
||||
|
||||
# we can attach again
|
||||
statement ok con1
|
||||
ATTACH '__TEST_DIR__/con2_rollback_detach.db';
|
||||
34
external/duckdb/test/sql/attach/attach_force_checkpoint_deadlock.test_slow
vendored
Normal file
34
external/duckdb/test/sql/attach/attach_force_checkpoint_deadlock.test_slow
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
# name: test/sql/attach/attach_force_checkpoint_deadlock.test_slow
|
||||
# description: Deadlock when force checkpointing multiple databases
|
||||
# group: [attach]
|
||||
|
||||
concurrentforeach dbname foo bar i1 i2 i3 i4 i5 i6 i7 i8 i9
|
||||
|
||||
statement ok
|
||||
attach '__TEST_DIR__/force_checkpoint_${dbname}.duckdb' as ${dbname}
|
||||
|
||||
statement ok
|
||||
create table ${dbname}.${dbname}(foo bigint)
|
||||
|
||||
statement ok
|
||||
insert into ${dbname}.${dbname} select sum(i) from range(1000000) t(i)
|
||||
|
||||
statement ok
|
||||
force checkpoint ${dbname}
|
||||
|
||||
statement ok
|
||||
select
|
||||
coalesce(t.table_catalog, current_database()) as "database",
|
||||
t.table_schema as "schema",
|
||||
t.table_name as "name",
|
||||
t.table_type as "type",
|
||||
array_agg(c.column_name order by c.ordinal_position) as "column_names",
|
||||
array_agg(c.data_type order by c.ordinal_position) as "column_types",
|
||||
array_agg(c.is_nullable = 'YES' order by c.ordinal_position) as "column_nullable"
|
||||
from information_schema.tables t
|
||||
join information_schema.columns c on t.table_schema = c.table_schema and t.table_name = c.table_name
|
||||
where t.table_schema = 'main'
|
||||
group by 1, 2, 3, 4
|
||||
order by 1, 2, 3, 4
|
||||
|
||||
endloop
|
||||
36
external/duckdb/test/sql/attach/attach_foreign_key.test
vendored
Normal file
36
external/duckdb/test/sql/attach/attach_foreign_key.test
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
# name: test/sql/attach/attach_foreign_key.test
|
||||
# description: Test attach mixed with foreign key constraints
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
ATTACH DATABASE ':memory:' AS db1;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE album(artistid INTEGER, albumname TEXT, albumcover TEXT, UNIQUE (artistid, albumname));
|
||||
|
||||
statement error
|
||||
CREATE TABLE db1.song(songid INTEGER, songartist INTEGER, songalbum TEXT, songname TEXT, FOREIGN KEY(songartist, songalbum) REFERENCES album(artistid, albumname));
|
||||
----
|
||||
across different schemas or catalogs
|
||||
|
||||
statement ok
|
||||
USE db1;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE album(artistid INTEGER, albumname TEXT, albumcover TEXT, UNIQUE (artistid, albumname));
|
||||
|
||||
statement ok
|
||||
INSERT INTO album VALUES (1, 'A', 'A_cover'), (2, 'B', 'B_cover'), (3, 'C', 'C_cover'), (4, 'D', 'D_cover');
|
||||
|
||||
statement ok
|
||||
CREATE TABLE song(songid INTEGER, songartist INTEGER, songalbum TEXT, songname TEXT, FOREIGN KEY(songartist, songalbum) REFERENCES album(artistid, albumname));
|
||||
|
||||
statement ok
|
||||
ATTACH DATABASE ':memory:' AS db2;
|
||||
|
||||
statement ok
|
||||
USE db2;
|
||||
|
||||
# check that foreign key is correctly resolved even when different catalog search path is used
|
||||
statement ok
|
||||
INSERT INTO db1.song VALUES (11, 1, 'A', 'A_song'), (12, 2, 'B', 'B_song'), (13, 3, 'C', 'C_song');
|
||||
13
external/duckdb/test/sql/attach/attach_fsspec.test
vendored
Normal file
13
external/duckdb/test/sql/attach/attach_fsspec.test
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
# name: test/sql/attach/attach_fsspec.test
|
||||
# description: Test attach using fsspec
|
||||
# group: [attach]
|
||||
|
||||
statement error
|
||||
ATTACH 'dummy_extension:/hello.world';
|
||||
----
|
||||
not found
|
||||
|
||||
statement error
|
||||
ATTACH 'file://dummy.csv'
|
||||
----
|
||||
IO Error: Cannot open file "file://dummy.csv"
|
||||
34
external/duckdb/test/sql/attach/attach_home_directory.test
vendored
Normal file
34
external/duckdb/test/sql/attach/attach_home_directory.test
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
# name: test/sql/attach/attach_home_directory.test
|
||||
# description: Test resolution of ATTACH with home directory
|
||||
# group: [attach]
|
||||
|
||||
# FIXME: ATTACH does not correctly receive the FileOpener of the client
|
||||
mode skip
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/home_dir.db' AS s1
|
||||
|
||||
statement ok
|
||||
CREATE TABLE s1.integers AS FROM range(10) t(i);
|
||||
|
||||
query I
|
||||
SELECT SUM(i) FROM s1.integers
|
||||
----
|
||||
45
|
||||
|
||||
statement ok
|
||||
DETACH s1
|
||||
|
||||
statement ok
|
||||
SET home_directory='__TEST_DIR__'
|
||||
|
||||
statement ok
|
||||
ATTACH '~/home_dir.db' AS s1
|
||||
|
||||
query I
|
||||
SELECT SUM(i) FROM s1.integers
|
||||
----
|
||||
45
|
||||
|
||||
statement ok
|
||||
DETACH s1
|
||||
11
external/duckdb/test/sql/attach/attach_huggingface_index.test
vendored
Normal file
11
external/duckdb/test/sql/attach/attach_huggingface_index.test
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
# name: test/sql/attach/attach_huggingface_index.test
|
||||
# description: Test attach mixed with sequences and default values
|
||||
# group: [attach]
|
||||
|
||||
# The database is written with a vector size of 2048.
|
||||
require vector_size 2048
|
||||
|
||||
unzip data/storage/huggingface_index.db.gz __TEST_DIR__/huggingface_index.db
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/huggingface_index.db'
|
||||
33
external/duckdb/test/sql/attach/attach_icu_collation.test
vendored
Normal file
33
external/duckdb/test/sql/attach/attach_icu_collation.test
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
# name: test/sql/attach/attach_icu_collation.test
|
||||
# description: ATTACH to a database that uses ICU collations in types
|
||||
# group: [attach]
|
||||
|
||||
require icu
|
||||
|
||||
# The database is written with a vector size of 2048.
|
||||
require vector_size 2048
|
||||
|
||||
unzip data/storage/german_collation.db.gz __TEST_DIR__/german_collation.db
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/german_collation.db' AS db
|
||||
|
||||
query I rowsort
|
||||
SELECT * FROM db.strings
|
||||
----
|
||||
Gabel
|
||||
Goethe
|
||||
Goldmann
|
||||
Göbel
|
||||
Göthe
|
||||
Götz
|
||||
|
||||
query I
|
||||
SELECT * FROM db.strings ORDER BY 1
|
||||
----
|
||||
Gabel
|
||||
Göbel
|
||||
Goethe
|
||||
Goldmann
|
||||
Göthe
|
||||
Götz
|
||||
60
external/duckdb/test/sql/attach/attach_if_not_exists.test
vendored
Normal file
60
external/duckdb/test/sql/attach/attach_if_not_exists.test
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
# name: test/sql/attach/attach_if_not_exists.test
|
||||
# description: Test ATTACH IF NOT EXISTS
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/attach_if_not_exists.db' AS db1
|
||||
|
||||
# ATTACH IF NOT EXISTS
|
||||
statement ok
|
||||
ATTACH IF NOT EXISTS '__TEST_DIR__/attach_if_not_exists.db' AS db1
|
||||
|
||||
# skip is based on database name, not database path
|
||||
statement ok
|
||||
ATTACH IF NOT EXISTS ':memory:' AS db1
|
||||
|
||||
statement ok
|
||||
CREATE TABLE db1.integers(i INTEGER);
|
||||
|
||||
# attaching the same database with a different alias throws an exception
|
||||
statement error
|
||||
ATTACH IF NOT EXISTS '__TEST_DIR__/attach_if_not_exists.db' AS db2
|
||||
----
|
||||
already attached
|
||||
|
||||
# as does attaching to the same alias
|
||||
statement error
|
||||
ATTACH ':memory:' AS db1
|
||||
----
|
||||
already exists
|
||||
|
||||
# detach and re-attach in read-only mode
|
||||
statement ok
|
||||
DETACH db1
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/attach_if_not_exists.db' AS db1 (READ_WRITE);
|
||||
|
||||
statement error
|
||||
ATTACH IF NOT EXISTS '__TEST_DIR__/attach_if_not_exists.db' AS db1 (READ_ONLY);
|
||||
----
|
||||
already attached in READ_WRITE mode, cannot re-attach in READ_ONLY mode
|
||||
|
||||
# automatic always works
|
||||
statement ok
|
||||
ATTACH IF NOT EXISTS '__TEST_DIR__/attach_if_not_exists.db' AS db1
|
||||
|
||||
statement ok
|
||||
DETACH db1
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/attach_if_not_exists.db' AS db1 (READ_ONLY)
|
||||
|
||||
statement error
|
||||
ATTACH IF NOT EXISTS '__TEST_DIR__/attach_if_not_exists.db' AS db1 (READ_WRITE);
|
||||
----
|
||||
already attached in READ_ONLY mode, cannot re-attach in READ_WRITE mode
|
||||
|
||||
# automatic always works
|
||||
statement ok
|
||||
ATTACH IF NOT EXISTS '__TEST_DIR__/attach_if_not_exists.db' AS db1
|
||||
23
external/duckdb/test/sql/attach/attach_if_not_exists_detach.test
vendored
Normal file
23
external/duckdb/test/sql/attach/attach_if_not_exists_detach.test
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
# name: test/sql/attach/attach_if_not_exists_detach.test
|
||||
# description: Test ATTACH IF NOT EXISTS
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/attach_if_not_exists_detach.db' AS db1
|
||||
|
||||
# con1 opens a transaction for db1 that prevents it from being fully detached
|
||||
statement ok con1
|
||||
BEGIN
|
||||
|
||||
statement ok con1
|
||||
CREATE TABLE db1.tbl(i INTEGER);
|
||||
|
||||
# con2 can detach db1, but it will not actually be detached
|
||||
statement ok con2
|
||||
DETACH db1
|
||||
|
||||
# upon attaching we should fail
|
||||
statement error con2
|
||||
ATTACH IF NOT EXISTS '__TEST_DIR__/attach_if_not_exists_detach.db' AS db1
|
||||
----
|
||||
the process of being detached
|
||||
46
external/duckdb/test/sql/attach/attach_index.test
vendored
Normal file
46
external/duckdb/test/sql/attach/attach_index.test
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
# name: test/sql/attach/attach_index.test
|
||||
# description: Issue #6666 - ATTACH fails on duckdb database with INDEX
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/attach_index_db.db'
|
||||
|
||||
statement ok
|
||||
USE attach_index_db
|
||||
|
||||
statement ok
|
||||
CREATE TABLE tbl_a (
|
||||
a_id INTEGER PRIMARY KEY,
|
||||
value VARCHAR NOT NULL
|
||||
)
|
||||
|
||||
statement ok
|
||||
CREATE INDEX idx_tbl_a ON tbl_a (value)
|
||||
|
||||
statement ok
|
||||
INSERT INTO tbl_a VALUES (1, 'x')
|
||||
|
||||
statement ok
|
||||
INSERT INTO tbl_a VALUES (2, 'y')
|
||||
|
||||
query II
|
||||
SELECT * FROM tbl_a WHERE a_id = 2
|
||||
----
|
||||
2 y
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/other_attach_index.db'
|
||||
|
||||
statement ok
|
||||
USE other_attach_index
|
||||
|
||||
statement ok
|
||||
DETACH attach_index_db
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/attach_index_db.db'
|
||||
|
||||
query II
|
||||
SELECT * FROM attach_index_db.tbl_a WHERE a_id = 2
|
||||
----
|
||||
2 y
|
||||
27
external/duckdb/test/sql/attach/attach_issue16122.test
vendored
Normal file
27
external/duckdb/test/sql/attach/attach_issue16122.test
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
# name: test/sql/attach/attach_issue16122.test
|
||||
# description: Issue #16122 - Attach binding to incorrect table
|
||||
# group: [attach]
|
||||
|
||||
load __TEST_DIR__/issue16122.db
|
||||
|
||||
statement ok
|
||||
create table mytable (C1 VARCHAR(10));
|
||||
|
||||
statement ok
|
||||
insert into mytable values ('a');
|
||||
|
||||
statement ok
|
||||
attach '__TEST_DIR__/issue16122_new.db' as TOMERGE;
|
||||
|
||||
statement ok
|
||||
create table TOMERGE.mytable (C1 VARCHAR(10));
|
||||
|
||||
query I
|
||||
insert into TOMERGE.mytable SELECT * FROM mytable;
|
||||
----
|
||||
1
|
||||
|
||||
query I
|
||||
select * from TOMERGE.mytable;
|
||||
----
|
||||
a
|
||||
26
external/duckdb/test/sql/attach/attach_issue7567.test
vendored
Normal file
26
external/duckdb/test/sql/attach/attach_issue7567.test
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
# name: test/sql/attach/attach_issue7567.test
|
||||
# description: Issue #7567 - Setting the current schema should not change the current database
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
attach ':memory:' as test;
|
||||
|
||||
statement ok
|
||||
use test;
|
||||
|
||||
statement ok
|
||||
create schema schema1;
|
||||
|
||||
statement ok
|
||||
create table schema1.table1 as select 1 as a;
|
||||
|
||||
statement error
|
||||
set schema='schema2';
|
||||
----
|
||||
No catalog + schema named "schema2" found
|
||||
|
||||
statement ok
|
||||
set schema='schema1';
|
||||
|
||||
statement ok
|
||||
select * from table1;
|
||||
20
external/duckdb/test/sql/attach/attach_issue7711.test
vendored
Normal file
20
external/duckdb/test/sql/attach/attach_issue7711.test
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
# name: test/sql/attach/attach_issue7711.test
|
||||
# description: Issue #7711 - Detaching the current database prevents from using another one
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
attach ':memory:' as test;
|
||||
|
||||
statement ok
|
||||
use test;
|
||||
|
||||
statement error
|
||||
detach test;
|
||||
----
|
||||
Cannot detach database "test" because it is the default database
|
||||
|
||||
statement ok
|
||||
use memory
|
||||
|
||||
statement ok
|
||||
detach test
|
||||
34
external/duckdb/test/sql/attach/attach_issue_7660.test
vendored
Normal file
34
external/duckdb/test/sql/attach/attach_issue_7660.test
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
# name: test/sql/attach/attach_issue_7660.test
|
||||
# description: Issue #7660 - USE databases causes export database to produce duplicate data
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
attach ':memory:' as test;
|
||||
|
||||
statement ok
|
||||
use test;
|
||||
|
||||
statement ok
|
||||
create table tbl1 as select 1 as a;
|
||||
|
||||
query I
|
||||
FROM test.tbl1
|
||||
----
|
||||
1
|
||||
|
||||
statement ok
|
||||
export database '__TEST_DIR__/test_issue_7660';
|
||||
|
||||
statement ok
|
||||
USE memory
|
||||
|
||||
statement ok
|
||||
DETACH test
|
||||
|
||||
statement ok
|
||||
import database '__TEST_DIR__/test_issue_7660'
|
||||
|
||||
query I
|
||||
FROM tbl1
|
||||
----
|
||||
1
|
||||
42
external/duckdb/test/sql/attach/attach_lambda_view.test
vendored
Normal file
42
external/duckdb/test/sql/attach/attach_lambda_view.test
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
# name: test/sql/attach/attach_lambda_view.test
|
||||
# description: Test lambdas in attached databases
|
||||
# group: [attach]
|
||||
|
||||
foreach i 2 3
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/version_1_${i}_0.db' (STORAGE_VERSION 'v1.${i}.0');
|
||||
|
||||
statement ok
|
||||
CREATE TABLE version_1_${i}_0.lists(l integer[], initial integer);
|
||||
|
||||
statement ok
|
||||
INSERT INTO version_1_${i}_0.lists VALUES ([1], -1), ([1, 2, 3], -2), (NULL, -3), ([-1, NULL, 2], -3);
|
||||
|
||||
statement ok
|
||||
CREATE VIEW version_1_${i}_0.reduced_lists AS
|
||||
SELECT list_reduce(l, LAMBDA x, y : x + y, initial) AS r FROM version_1_${i}_0.lists;
|
||||
|
||||
query I
|
||||
FROM version_1_${i}_0.reduced_lists;
|
||||
----
|
||||
0
|
||||
4
|
||||
NULL
|
||||
NULL
|
||||
|
||||
statement ok
|
||||
DETACH version_1_${i}_0
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/version_1_${i}_0.db'
|
||||
|
||||
query I
|
||||
FROM version_1_${i}_0.reduced_lists;
|
||||
----
|
||||
0
|
||||
4
|
||||
NULL
|
||||
NULL
|
||||
|
||||
endloop
|
||||
30
external/duckdb/test/sql/attach/attach_macros.test
vendored
Normal file
30
external/duckdb/test/sql/attach/attach_macros.test
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
# name: test/sql/attach/attach_macros.test
|
||||
# description: Tests for macro functions in attached databases
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
ATTACH ':memory:' AS db1;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE db1.tbl AS SELECT 42 AS x, 3 AS y;
|
||||
|
||||
statement ok
|
||||
CREATE MACRO db1.two_x_plus_y(x, y) AS 2 * x + y;
|
||||
|
||||
query I
|
||||
SELECT db1.two_x_plus_y(x, y) FROM db1.tbl;
|
||||
----
|
||||
87
|
||||
|
||||
query I
|
||||
SELECT db1.main.two_x_plus_y(x, y) FROM db1.tbl;
|
||||
----
|
||||
87
|
||||
|
||||
statement ok
|
||||
USE db1
|
||||
|
||||
query I
|
||||
SELECT two_x_plus_y(x, y) FROM db1.tbl;
|
||||
----
|
||||
87
|
||||
47
external/duckdb/test/sql/attach/attach_modify_multiple_databases.test
vendored
Normal file
47
external/duckdb/test/sql/attach/attach_modify_multiple_databases.test
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
# name: test/sql/attach/attach_modify_multiple_databases.test
|
||||
# description: Modify multiple databases in one transaction
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
# attach a new database
|
||||
statement ok
|
||||
ATTACH DATABASE ':memory:' AS database;
|
||||
|
||||
statement ok
|
||||
BEGIN TRANSACTION
|
||||
|
||||
statement ok
|
||||
CREATE TABLE database.integers(i INTEGER);
|
||||
|
||||
statement error
|
||||
CREATE TABLE integers(i INTEGER);
|
||||
----
|
||||
a single transaction can only write to a single attached database
|
||||
|
||||
statement ok
|
||||
ROLLBACK
|
||||
|
||||
statement ok
|
||||
CREATE TABLE database.integers(i INTEGER);
|
||||
|
||||
statement ok
|
||||
CREATE TABLE integers(i INTEGER);
|
||||
|
||||
statement ok
|
||||
INSERT INTO database.integers SELECT * FROM range(10);
|
||||
|
||||
statement ok
|
||||
BEGIN TRANSACTION
|
||||
|
||||
statement ok
|
||||
INSERT INTO integers SELECT * FROM range(10);
|
||||
|
||||
statement error
|
||||
INSERT INTO database.integers SELECT * FROM range(10);
|
||||
----
|
||||
a single transaction can only write to a single attached database
|
||||
|
||||
statement ok
|
||||
ROLLBACK
|
||||
123
external/duckdb/test/sql/attach/attach_multi_identifiers.test
vendored
Normal file
123
external/duckdb/test/sql/attach/attach_multi_identifiers.test
vendored
Normal file
@@ -0,0 +1,123 @@
|
||||
# name: test/sql/attach/attach_multi_identifiers.test
|
||||
# description: Test ATTACH with complex identifiers
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement ok
|
||||
ATTACH ':memory:' AS db1;
|
||||
|
||||
statement ok
|
||||
ATTACH ':memory:' AS db2;
|
||||
|
||||
statement ok
|
||||
CREATE SCHEMA db1.s1;
|
||||
|
||||
statement ok
|
||||
CREATE SCHEMA db2.s1;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE db1.s1.t(c INT);
|
||||
|
||||
statement ok
|
||||
CREATE TABLE db2.s1.t(c INT);
|
||||
|
||||
statement ok
|
||||
INSERT INTO db1.s1.t VALUES (42);
|
||||
|
||||
statement ok
|
||||
INSERT INTO db2.s1.t SELECT c * 2 FROM db1.s1.t
|
||||
|
||||
query II
|
||||
SELECT * FROM db1.s1.t, db2.s1.t
|
||||
----
|
||||
42 84
|
||||
|
||||
query II
|
||||
SELECT db1.t.c, db2.t.c FROM db1.s1.t, db2.s1.t
|
||||
----
|
||||
42 84
|
||||
|
||||
query II
|
||||
SELECT db1.s1.t.c, db2.s1.t.c FROM db1.s1.t, db2.s1.t
|
||||
----
|
||||
42 84
|
||||
|
||||
query I
|
||||
SELECT * EXCLUDE (db1.s1.t.c) FROM db1.s1.t, db2.s1.t
|
||||
----
|
||||
84
|
||||
|
||||
query I
|
||||
SELECT * EXCLUDE (DB1.S1.T.C) FROM db1.s1.t, db2.s1.t
|
||||
----
|
||||
84
|
||||
|
||||
query I
|
||||
SELECT * EXCLUDE (s1.t.c) FROM db1.s1.t, (SELECT 42) t
|
||||
----
|
||||
42
|
||||
|
||||
# rename
|
||||
query I
|
||||
SELECT * EXCLUDE (new_col) FROM (SELECT * RENAME (db1.s1.t.c AS new_col) FROM db1.s1.t, db2.s1.t)
|
||||
----
|
||||
84
|
||||
|
||||
query I
|
||||
SELECT * EXCLUDE (new_col) FROM (SELECT * RENAME (DB1.S1.T.C AS new_col) FROM db1.s1.t, db2.s1.t)
|
||||
----
|
||||
84
|
||||
|
||||
query I
|
||||
SELECT * EXCLUDE (new_col) FROM (SELECT * RENAME (s1.t.c AS new_col) FROM db1.s1.t, (SELECT 42) t)
|
||||
----
|
||||
42
|
||||
|
||||
# struct pack
|
||||
query II
|
||||
SELECT db1.s1.t, db2.s1.t FROM db1.s1.t, db2.s1.t
|
||||
----
|
||||
{'c': 42} {'c': 84}
|
||||
|
||||
query II
|
||||
SELECT db1.t, db2.t FROM db1.s1.t, db2.s1.t
|
||||
----
|
||||
{'c': 42} {'c': 84}
|
||||
|
||||
# conflicting identifiers
|
||||
statement error
|
||||
SELECT c FROM db1.s1.t, db2.s1.t
|
||||
----
|
||||
<REGEX>:.*Ambiguous reference to column name.*db1.s1.t.c.*db2.s1.t.c.*
|
||||
|
||||
statement error
|
||||
SELECT t.c FROM db1.s1.t, db2.s1.t
|
||||
----
|
||||
Ambiguous reference to table
|
||||
|
||||
statement error
|
||||
SELECT s1.t.c FROM db1.s1.t, db2.s1.t
|
||||
----
|
||||
Ambiguous reference to table
|
||||
|
||||
query I
|
||||
SELECT db1.s1.t.c FROM db1.s1.t, db2.s1.t
|
||||
----
|
||||
42
|
||||
|
||||
# generated columns
|
||||
statement ok
|
||||
CREATE OR REPLACE TABLE db1.s1.t (
|
||||
c INT,
|
||||
c_squared AS (c * c),
|
||||
);
|
||||
|
||||
statement ok
|
||||
INSERT INTO db1.s1.t VALUES (42);
|
||||
|
||||
query III
|
||||
SELECT * FROM db1.s1.t, db2.s1.t
|
||||
----
|
||||
42 1764 84
|
||||
70
external/duckdb/test/sql/attach/attach_nested_types.test
vendored
Normal file
70
external/duckdb/test/sql/attach/attach_nested_types.test
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
# name: test/sql/attach/attach_nested_types.test
|
||||
# description: Test attach with nested types
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
# attach a new database
|
||||
statement ok
|
||||
ATTACH DATABASE ':memory:' AS database;
|
||||
|
||||
statement ok
|
||||
CREATE SCHEMA database.schema;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE database.schema.table(col ROW(field INTEGER));
|
||||
|
||||
statement ok
|
||||
INSERT INTO database.schema.table VALUES ({'field': 42});
|
||||
|
||||
query I
|
||||
SELECT database.schema.table.col.field FROM database.schema.table
|
||||
----
|
||||
42
|
||||
|
||||
query I
|
||||
SELECT database.schema.table.col FROM database.schema.table
|
||||
----
|
||||
{'field': 42}
|
||||
|
||||
query I
|
||||
SELECT database.schema.table FROM database.schema.table
|
||||
----
|
||||
{'col': {'field': 42}}
|
||||
|
||||
statement ok
|
||||
USE database
|
||||
|
||||
query I
|
||||
SELECT schema.table FROM database.schema.table
|
||||
----
|
||||
{'col': {'field': 42}}
|
||||
|
||||
query I
|
||||
SELECT "table" FROM database.schema.table
|
||||
----
|
||||
{'col': {'field': 42}}
|
||||
|
||||
statement ok
|
||||
USE database.schema
|
||||
|
||||
query I
|
||||
SELECT "table" FROM "table"
|
||||
----
|
||||
{'col': {'field': 42}}
|
||||
|
||||
query I
|
||||
SELECT schema.table FROM "table"
|
||||
----
|
||||
{'col': {'field': 42}}
|
||||
|
||||
query I
|
||||
SELECT database.table FROM "table"
|
||||
----
|
||||
{'col': {'field': 42}}
|
||||
|
||||
query I
|
||||
SELECT database.schema.table FROM "table"
|
||||
----
|
||||
{'col': {'field': 42}}
|
||||
68
external/duckdb/test/sql/attach/attach_new_compression.test
vendored
Normal file
68
external/duckdb/test/sql/attach/attach_new_compression.test
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
# name: test/sql/attach/attach_new_compression.test
|
||||
# description: Tests attaching database files and using new compression methods
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/test_new_compression.db' AS db1 (STORAGE_VERSION 'v1.0.0');
|
||||
|
||||
statement ok
|
||||
SET force_compression='roaring'
|
||||
|
||||
statement ok
|
||||
CREATE TABLE db1.tbl AS SELECT CASE WHEN i%2=0 THEN NULL ELSE i END i FROM range(10000) t(i);
|
||||
|
||||
statement ok
|
||||
SET force_compression='zstd';
|
||||
|
||||
statement ok
|
||||
CREATE TABLE db1.str_tbl AS SELECT STRING_AGG('long_string_' || i, '-') FROM range(1000) t(i);
|
||||
|
||||
# verify new compression methods are not used when attaching with a low storage version
|
||||
query I
|
||||
SELECT COUNT(*)>0 FROM pragma_storage_info('db1.tbl') WHERE compression='Roaring'
|
||||
----
|
||||
false
|
||||
|
||||
query I
|
||||
SELECT COUNT(*)>0 FROM pragma_storage_info('db1.str_tbl') WHERE compression='ZSTD'
|
||||
----
|
||||
false
|
||||
|
||||
statement ok
|
||||
DETACH db1
|
||||
|
||||
# attach with a new storage version and re-write the table
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/test_new_compression.db' AS db1 (STORAGE_VERSION 'v1.2.0');
|
||||
|
||||
statement ok
|
||||
SET force_compression='roaring'
|
||||
|
||||
statement ok
|
||||
CREATE TABLE db1.tbl2 AS FROM db1.tbl
|
||||
|
||||
statement ok
|
||||
CHECKPOINT db1
|
||||
|
||||
statement ok
|
||||
SET force_compression='zstd';
|
||||
|
||||
statement ok
|
||||
CREATE TABLE db1.str_tbl2 AS FROM db1.str_tbl
|
||||
|
||||
statement ok
|
||||
CHECKPOINT db1
|
||||
|
||||
# roaring is used now
|
||||
query I
|
||||
SELECT COUNT(*)>0 FROM pragma_storage_info('db1.tbl2') WHERE compression='Roaring'
|
||||
----
|
||||
true
|
||||
|
||||
query I
|
||||
SELECT COUNT(*)>0 FROM pragma_storage_info('db1.str_tbl2') WHERE compression='ZSTD'
|
||||
----
|
||||
true
|
||||
11
external/duckdb/test/sql/attach/attach_null.test
vendored
Normal file
11
external/duckdb/test/sql/attach/attach_null.test
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
# name: test/sql/attach/attach_null.test
|
||||
# description: Tests NULL as an attach option
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement error
|
||||
ATTACH '__TEST_DIR__/test_new_compression.db' AS db1 (TYPE NULL);
|
||||
----
|
||||
NULL is not supported
|
||||
59
external/duckdb/test/sql/attach/attach_or_replace.test
vendored
Normal file
59
external/duckdb/test/sql/attach/attach_or_replace.test
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
# name: test/sql/attach/attach_or_replace.test
|
||||
# description: Test ATTACH OR REPLACE
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/attach_or_replace.db' AS db1;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE db1.all_types AS SELECT * FROM test_all_types();
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/attach_or_replace_new.db' AS db2;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE db2.all_types_new AS SELECT * FROM test_all_types();
|
||||
|
||||
statement ok
|
||||
DETACH db2;
|
||||
|
||||
# ATTACH OR REPLACE same path to same alias should work
|
||||
statement ok
|
||||
ATTACH OR REPLACE '__TEST_DIR__/attach_or_replace.db' AS db1;
|
||||
|
||||
statement ok
|
||||
SELECT * FROM db1.all_types;
|
||||
|
||||
# ATTACHing the same path to a different alias is an error
|
||||
statement error
|
||||
ATTACH OR REPLACE '__TEST_DIR__/attach_or_replace.db' AS db2;
|
||||
----
|
||||
already attached
|
||||
|
||||
statement ok
|
||||
SELECT * FROM db1.all_types;
|
||||
|
||||
# ATTACHing a new path to an existing alias detaches the old path and attaches the new path in its place
|
||||
statement ok
|
||||
ATTACH OR REPLACE '__TEST_DIR__/attach_or_replace_new.db' AS db1;
|
||||
|
||||
# The previous database is no longer attached at this alias, so the table is not found
|
||||
statement error
|
||||
SELECT * FROM db1.all_types;
|
||||
----
|
||||
does not exist
|
||||
|
||||
# The table in the new file is found
|
||||
statement ok
|
||||
SELECT * FROM db1.all_types_new;
|
||||
|
||||
# ATTACHing the now-unattached previous path should now work
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/attach_or_replace.db' AS db2;
|
||||
|
||||
statement ok
|
||||
SELECT * FROM db2.all_types;
|
||||
|
||||
41
external/duckdb/test/sql/attach/attach_persistent.test
vendored
Normal file
41
external/duckdb/test/sql/attach/attach_persistent.test
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
# name: test/sql/attach/attach_persistent.test
|
||||
# description: Test attaching of a persistent database
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/persistent_attach.db'
|
||||
|
||||
statement error
|
||||
ATTACH '__TEST_DIR__/persistent_attach.db'
|
||||
----
|
||||
|
||||
statement ok
|
||||
CREATE TABLE persistent_attach.integers(i INTEGER)
|
||||
|
||||
statement ok
|
||||
INSERT INTO persistent_attach.integers VALUES (42)
|
||||
|
||||
query I
|
||||
SELECT SUM(i) FROM persistent_attach.integers
|
||||
----
|
||||
42
|
||||
|
||||
# detach and re-attach
|
||||
statement ok
|
||||
DETACH persistent_attach
|
||||
|
||||
statement error
|
||||
SELECT SUM(i) FROM persistent_attach.integers
|
||||
----
|
||||
does not exist
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/persistent_attach.db'
|
||||
|
||||
query I
|
||||
SELECT SUM(i) FROM persistent_attach.integers
|
||||
----
|
||||
42
|
||||
19
external/duckdb/test/sql/attach/attach_pragma_storage_info.test
vendored
Normal file
19
external/duckdb/test/sql/attach/attach_pragma_storage_info.test
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
# name: test/sql/attach/attach_pragma_storage_info.test
|
||||
# group: [attach]
|
||||
|
||||
load __TEST_DIR__/alter_dependency_conflict.db
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/database.db' as persistent;
|
||||
|
||||
statement ok
|
||||
CREATE OR REPLACE TABLE persistent.T1 (A0 int);
|
||||
|
||||
statement ok
|
||||
insert into persistent.T1 values (5);
|
||||
|
||||
query I
|
||||
SELECT column_name from pragma_storage_info('persistent.T1');
|
||||
----
|
||||
A0
|
||||
A0
|
||||
87
external/duckdb/test/sql/attach/attach_read_only.test
vendored
Normal file
87
external/duckdb/test/sql/attach/attach_read_only.test
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
# name: test/sql/attach/attach_read_only.test
|
||||
# description: Test attaching of a read-only database
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement error
|
||||
ATTACH ':memory:' AS db1 (READONLY 1)
|
||||
----
|
||||
Cannot launch in-memory database in read-only mode
|
||||
|
||||
statement error
|
||||
ATTACH ':memory:' AS db1 (BLABLABLA 1)
|
||||
----
|
||||
Unrecognized option
|
||||
|
||||
statement error
|
||||
ATTACH '__TEST_DIR__/attach_read_only.db' AS db1 (READONLY 1)
|
||||
----
|
||||
database does not exist
|
||||
|
||||
# create a database file and close it again
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/attach_read_only.db' AS db1
|
||||
|
||||
statement ok
|
||||
CREATE TABLE db1.integers AS SELECT * FROM range(10) t(i);
|
||||
|
||||
statement ok
|
||||
DETACH db1
|
||||
|
||||
# now attach in read only mode
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/attach_read_only.db' AS db1 (READONLY 1)
|
||||
|
||||
query I
|
||||
SELECT SUM(i) FROM db1.integers
|
||||
----
|
||||
45
|
||||
|
||||
# database is opened in read-only mode - cannot create a table
|
||||
statement error
|
||||
CREATE TABLE db1.test AS SELECT * FROM range(10) t(i);
|
||||
----
|
||||
read-only
|
||||
|
||||
# we can attach a second database in read-write mode and write to there
|
||||
statement ok
|
||||
ATTACH ':memory:' AS db2
|
||||
|
||||
statement ok
|
||||
CREATE TABLE db2.integers AS SELECT * FROM db1.integers
|
||||
|
||||
query I
|
||||
SELECT SUM(i) FROM db2.integers
|
||||
----
|
||||
45
|
||||
|
||||
# attach main database in read only mode
|
||||
# load the DB from disk
|
||||
load __TEST_DIR__/attach_read_only.db readonly
|
||||
|
||||
query I
|
||||
SELECT SUM(i) FROM integers
|
||||
----
|
||||
45
|
||||
|
||||
# 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
|
||||
|
||||
# attach a non-read-only database
|
||||
statement ok
|
||||
ATTACH ':memory:' AS db1 (READ_WRITE);
|
||||
|
||||
# we can write tables to that database
|
||||
statement ok
|
||||
CREATE TABLE db1.test AS SELECT * FROM integers
|
||||
|
||||
# but not to the main (read-only) database
|
||||
statement error
|
||||
CREATE TABLE test AS SELECT * FROM db1.test
|
||||
----
|
||||
read-only
|
||||
31
external/duckdb/test/sql/attach/attach_read_only_transaction.test
vendored
Normal file
31
external/duckdb/test/sql/attach/attach_read_only_transaction.test
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
# name: test/sql/attach/attach_read_only_transaction.test
|
||||
# description: Test attach with explicit READ ONLY transactions
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement ok
|
||||
ATTACH ':memory:' AS db1;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE db1.integers(i INTEGER);
|
||||
|
||||
statement ok
|
||||
INSERT INTO db1.integers VALUES (42);
|
||||
|
||||
statement ok
|
||||
BEGIN TRANSACTION READ ONLY
|
||||
|
||||
query I
|
||||
FROM db1.integers
|
||||
----
|
||||
42
|
||||
|
||||
statement error
|
||||
INSERT INTO db1.integers VALUES (48)
|
||||
----
|
||||
transaction is launched in read-only mode
|
||||
|
||||
statement ok
|
||||
COMMIT
|
||||
43
external/duckdb/test/sql/attach/attach_reserved.test
vendored
Normal file
43
external/duckdb/test/sql/attach/attach_reserved.test
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
# name: test/sql/attach/attach_reserved.test
|
||||
# description: Test ATTACH of reserved names
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
# attach a new database called temp
|
||||
statement ok
|
||||
ATTACH DATABASE '__TEST_DIR__/temp.db';
|
||||
|
||||
# we alias "temp" and "main" to use "_db" instead
|
||||
statement ok
|
||||
CREATE TABLE temp_db.integers(i INTEGER);
|
||||
|
||||
statement ok
|
||||
DETACH temp_db;
|
||||
|
||||
# attach a new database called temp
|
||||
statement ok
|
||||
ATTACH DATABASE '__TEST_DIR__/system.db';
|
||||
|
||||
statement ok
|
||||
CREATE TABLE system_db.integers(i INTEGER);
|
||||
|
||||
statement ok
|
||||
DETACH system_db;
|
||||
|
||||
# explicitly selecting these aliases leads to an error
|
||||
statement error
|
||||
ATTACH DATABASE ':memory:' AS temp;
|
||||
----
|
||||
reserved name
|
||||
|
||||
statement error
|
||||
ATTACH DATABASE ':memory:' AS main;
|
||||
----
|
||||
reserved name
|
||||
|
||||
statement error
|
||||
ATTACH DATABASE ':memory:' AS system;
|
||||
----
|
||||
reserved name
|
||||
27
external/duckdb/test/sql/attach/attach_row_group_size.test
vendored
Normal file
27
external/duckdb/test/sql/attach/attach_row_group_size.test
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
# name: test/sql/attach/attach_row_group_size.test
|
||||
# description: Tests attaching database files and using new compression methods
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement error
|
||||
ATTACH '__TEST_DIR__/attach_row_group_size.db' AS db1 (STORAGE_VERSION 'v1.0.0', ROW_GROUP_SIZE 245760);
|
||||
----
|
||||
Explicitly specify a newer storage version when creating the database to enable larger row groups
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/attach_row_group_size.db' AS db1 (STORAGE_VERSION 'v1.0.0');
|
||||
|
||||
statement ok
|
||||
CREATE TABLE db1.tbl AS FROM range(10000) t(i)
|
||||
|
||||
# we can upgrade to a higher row group size
|
||||
statement ok
|
||||
DETACH db1
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/attach_row_group_size.db' AS db1 (STORAGE_VERSION 'v1.2.0', ROW_GROUP_SIZE 245760);
|
||||
|
||||
statement ok
|
||||
INSERT INTO db1.tbl FROM range(10000)
|
||||
28
external/duckdb/test/sql/attach/attach_same_db.test
vendored
Normal file
28
external/duckdb/test/sql/attach/attach_same_db.test
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
# name: test/sql/attach/attach_same_db.test
|
||||
# description: Test attaching of the same database
|
||||
# group: [attach]
|
||||
|
||||
require notwindows
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/attach_same_db.db' AS db1
|
||||
|
||||
statement error
|
||||
ATTACH '__TEST_DIR__/attach_same_db.db' AS db2
|
||||
----
|
||||
|
||||
# we can detach and attach in the same transaction
|
||||
statement ok
|
||||
BEGIN
|
||||
|
||||
statement ok
|
||||
DETACH db1
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/attach_same_db.db' AS db1
|
||||
|
||||
statement ok
|
||||
COMMIT
|
||||
22
external/duckdb/test/sql/attach/attach_schema.test
vendored
Normal file
22
external/duckdb/test/sql/attach/attach_schema.test
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
# name: test/sql/attach/attach_schema.test
|
||||
# description: Test various DDL statements on an attached database
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement ok
|
||||
ATTACH DATABASE ':memory:' AS new_database;
|
||||
|
||||
statement error
|
||||
CREATE SCHEMA new_database.s1.xxx;
|
||||
----
|
||||
too many dots
|
||||
|
||||
statement error
|
||||
CREATE SCHEMA IF NOT EXISTS new_database.s1.xxx;
|
||||
----
|
||||
too many dots
|
||||
|
||||
statement ok
|
||||
CREATE SCHEMA new_database.s1;
|
||||
41
external/duckdb/test/sql/attach/attach_sequence.test
vendored
Normal file
41
external/duckdb/test/sql/attach/attach_sequence.test
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
# name: test/sql/attach/attach_sequence.test
|
||||
# description: Test attach mixed with sequences and default values
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
ATTACH DATABASE '__TEST_DIR__/attach_seq.db' AS db1;
|
||||
|
||||
statement ok
|
||||
CREATE SEQUENCE seq;
|
||||
|
||||
statement error
|
||||
CREATE TABLE db1.integers(i INTEGER DEFAULT nextval('seq'))
|
||||
----
|
||||
TransactionContext Error: Attempting to write to database "db1" in a transaction that has already modified database
|
||||
|
||||
statement ok
|
||||
CREATE SEQUENCE db1.seq
|
||||
|
||||
statement ok
|
||||
CREATE TABLE db1.integers(i INTEGER DEFAULT nextval('db1.seq'))
|
||||
|
||||
query I
|
||||
SELECT nextval('db1.seq')
|
||||
----
|
||||
1
|
||||
|
||||
query I
|
||||
SELECT nextval('seq')
|
||||
----
|
||||
1
|
||||
|
||||
statement error
|
||||
CREATE TABLE integers(i INTEGER DEFAULT nextval('db1.seq'))
|
||||
----
|
||||
<REGEX>:TransactionContext Error:.*in a transaction that has already modified database "db1".*
|
||||
|
||||
statement ok
|
||||
detach db1;
|
||||
|
||||
statement ok
|
||||
ATTACH DATABASE '__TEST_DIR__/attach_seq.db' AS db1;
|
||||
64
external/duckdb/test/sql/attach/attach_serialize_dependency.test
vendored
Normal file
64
external/duckdb/test/sql/attach/attach_serialize_dependency.test
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
# name: test/sql/attach/attach_serialize_dependency.test
|
||||
# description: Test attach and re-attach with serialized dependencies
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
set storage_compatibility_version='latest';
|
||||
|
||||
statement ok
|
||||
attach '__TEST_DIR__/db1.db';
|
||||
|
||||
statement ok
|
||||
use db1;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE A (A1 INTEGER PRIMARY KEY,A2 VARCHAR, A3 INTEGER);
|
||||
|
||||
statement ok
|
||||
CREATE INDEX A_index ON A (A2);
|
||||
|
||||
statement ok
|
||||
CREATE TABLE B(B1 INTEGER REFERENCES A(A1));
|
||||
|
||||
statement ok
|
||||
attach '__TEST_DIR__/db1_other.db';
|
||||
|
||||
statement ok
|
||||
USE db1_other;
|
||||
|
||||
statement ok
|
||||
detach db1;
|
||||
|
||||
statement ok
|
||||
attach '__TEST_DIR__/db1.db' as other_db;
|
||||
|
||||
# now test with a WAL
|
||||
statement ok
|
||||
PRAGMA disable_checkpoint_on_shutdown
|
||||
|
||||
statement ok
|
||||
PRAGMA wal_autocheckpoint='1TB';
|
||||
|
||||
statement ok
|
||||
attach '__TEST_DIR__/db2.db';
|
||||
|
||||
statement ok
|
||||
use db2;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE A (A1 INTEGER PRIMARY KEY,A2 VARCHAR, A3 INTEGER);
|
||||
|
||||
statement ok
|
||||
CREATE INDEX A_index ON A (A2);
|
||||
|
||||
statement ok
|
||||
CREATE TABLE B(B1 INTEGER REFERENCES A(A1));
|
||||
|
||||
statement ok
|
||||
USE db1_other;
|
||||
|
||||
statement ok
|
||||
detach db2;
|
||||
|
||||
statement ok
|
||||
attach '__TEST_DIR__/db2.db' as other_db2;
|
||||
28
external/duckdb/test/sql/attach/attach_show_all_tables.test
vendored
Normal file
28
external/duckdb/test/sql/attach/attach_show_all_tables.test
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
# name: test/sql/attach/attach_show_all_tables.test
|
||||
# description: Test various DDL statements on an attached database
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement ok
|
||||
ATTACH DATABASE ':memory:' AS new_database;
|
||||
|
||||
statement ok
|
||||
CREATE SCHEMA new_database.s1;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE tbl(a INTEGER);
|
||||
|
||||
statement ok
|
||||
CREATE TABLE new_database.tbl(b INTEGER);
|
||||
|
||||
statement ok
|
||||
CREATE TABLE new_database.s1.tbl(c INTEGER);
|
||||
|
||||
query IIIIII
|
||||
SHOW ALL TABLES
|
||||
----
|
||||
memory main tbl [a] [INTEGER] false
|
||||
new_database main tbl [b] [INTEGER] false
|
||||
new_database s1 tbl [c] [INTEGER] false
|
||||
76
external/duckdb/test/sql/attach/attach_show_table.test
vendored
Normal file
76
external/duckdb/test/sql/attach/attach_show_table.test
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
# name: test/sql/attach/attach_show_table.test
|
||||
# description: Show table should respect current scope
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement ok
|
||||
ATTACH DATABASE ':memory:' AS db1;
|
||||
|
||||
statement ok
|
||||
ATTACH DATABASE ':memory:' AS db2;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE db1.table_in_db1(i int);
|
||||
|
||||
statement ok
|
||||
CREATE TABLE db2.table_in_db2(i int);
|
||||
|
||||
statement ok
|
||||
CREATE SCHEMA db2.test_schema;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE db2.test_schema.table_in_db2_test_schema(i int);
|
||||
|
||||
query I
|
||||
SHOW TABLES
|
||||
----
|
||||
|
||||
statement ok
|
||||
USE DB1
|
||||
|
||||
query I
|
||||
SHOW TABLES
|
||||
----
|
||||
table_in_db1
|
||||
|
||||
statement ok
|
||||
USE db1
|
||||
|
||||
query I
|
||||
SHOW TABLES
|
||||
----
|
||||
table_in_db1
|
||||
|
||||
statement ok
|
||||
USE db2
|
||||
|
||||
query I
|
||||
SHOW TABLES
|
||||
----
|
||||
table_in_db2
|
||||
|
||||
statement ok
|
||||
USE db2.test_schema;
|
||||
|
||||
query I
|
||||
SHOW TABLES
|
||||
----
|
||||
table_in_db2
|
||||
table_in_db2_test_schema
|
||||
|
||||
statement ok
|
||||
USE DB2.TEST_sChEmA;
|
||||
|
||||
query I
|
||||
SHOW TABLES
|
||||
----
|
||||
table_in_db2
|
||||
table_in_db2_test_schema
|
||||
|
||||
statement ok
|
||||
FROM table_in_db2
|
||||
|
||||
statement ok
|
||||
FROM table_in_db2_test_schema
|
||||
152
external/duckdb/test/sql/attach/attach_storage_version.test
vendored
Normal file
152
external/duckdb/test/sql/attach/attach_storage_version.test
vendored
Normal file
@@ -0,0 +1,152 @@
|
||||
# name: test/sql/attach/attach_storage_version.test
|
||||
# description: Tests attaching database files with different block allocation sizes.
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/version_1_2_0.db' (STORAGE_VERSION 'v1.2.0');
|
||||
|
||||
# exposed through tags
|
||||
query I
|
||||
SELECT tags['storage_version'] FROM duckdb_databases() WHERE database_name='version_1_2_0'
|
||||
----
|
||||
v1.2.0+
|
||||
|
||||
statement ok
|
||||
DETACH version_1_2_0
|
||||
|
||||
# cannot downgrade storage version
|
||||
statement error
|
||||
ATTACH '__TEST_DIR__/version_1_2_0.db' (STORAGE_VERSION 'v1.0.0');
|
||||
----
|
||||
The storage version of an existing database cannot be lowered
|
||||
|
||||
# unknown storage version
|
||||
statement error
|
||||
ATTACH '__TEST_DIR__/version_1_2_0.db' (STORAGE_VERSION 'non_existant');
|
||||
----
|
||||
not a known DuckDB version
|
||||
|
||||
# we can open it with the current version
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/version_1_2_0.db' (STORAGE_VERSION 'v1.2.0');
|
||||
|
||||
query I
|
||||
SELECT tags['storage_version'] FROM duckdb_databases() WHERE database_name='version_1_2_0'
|
||||
----
|
||||
v1.2.0+
|
||||
|
||||
statement ok
|
||||
DETACH version_1_2_0
|
||||
|
||||
# we can also open it without specifying the version at this point
|
||||
# the version will be loaded from the file
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/version_1_2_0.db';
|
||||
|
||||
query I
|
||||
SELECT tags['storage_version'] FROM duckdb_databases() WHERE database_name='version_1_2_0'
|
||||
----
|
||||
v1.2.0+
|
||||
|
||||
statement ok
|
||||
DETACH version_1_2_0
|
||||
|
||||
statement ok
|
||||
set storage_compatibility_version='v0.10.2'
|
||||
|
||||
# attach a database with the default compatibility version
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/default_version.db';
|
||||
|
||||
statement ok
|
||||
CREATE TABLE default_version.tbl(i VARCHAR);
|
||||
|
||||
# check the default compat version
|
||||
query I
|
||||
SELECT tags['storage_version'] FROM duckdb_databases() WHERE database_name='default_version'
|
||||
----
|
||||
v1.0.0+
|
||||
|
||||
statement ok
|
||||
DETACH default_version
|
||||
|
||||
# upgrade the database
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/default_version.db' (STORAGE_VERSION 'v1.2.0');
|
||||
|
||||
# we have upgraded the tag now
|
||||
query I
|
||||
SELECT tags['storage_version'] FROM duckdb_databases() WHERE database_name='default_version'
|
||||
----
|
||||
v1.2.0+
|
||||
|
||||
statement ok
|
||||
SET force_compression = 'zstd';
|
||||
|
||||
statement ok
|
||||
INSERT INTO default_version.tbl VALUES ('abcd'), ('efgh'), ('hello'), ('world'), (NULL);
|
||||
|
||||
statement ok
|
||||
CHECKPOINT default_version
|
||||
|
||||
statement ok
|
||||
DETACH default_version
|
||||
|
||||
# we can attach the database again (without specifying the default)
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/default_version.db'
|
||||
|
||||
# the upgraded tag is stored in the database file
|
||||
query I
|
||||
SELECT tags['storage_version'] FROM duckdb_databases() WHERE database_name='default_version'
|
||||
----
|
||||
v1.2.0+
|
||||
|
||||
query I
|
||||
FROM default_version.tbl
|
||||
----
|
||||
abcd
|
||||
efgh
|
||||
hello
|
||||
world
|
||||
NULL
|
||||
|
||||
statement ok
|
||||
DETACH default_version
|
||||
|
||||
# we can also attach it by specifying v1.2.0 explicitly
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/default_version.db' (STORAGE_VERSION 'v1.2.0')
|
||||
|
||||
query I
|
||||
FROM default_version.tbl
|
||||
----
|
||||
abcd
|
||||
efgh
|
||||
hello
|
||||
world
|
||||
NULL
|
||||
|
||||
statement ok
|
||||
DETACH default_version
|
||||
|
||||
# but not by specifying a lower version anymore at this point
|
||||
statement error
|
||||
ATTACH '__TEST_DIR__/default_version.db' (STORAGE_VERSION 'v1.0.0')
|
||||
----
|
||||
The storage version of an existing database cannot be lowered
|
||||
|
||||
# setting the storage_compatibility_version explicitly changes the default storage compatibility version when attaching
|
||||
statement ok
|
||||
SET storage_compatibility_version = 'v1.2.0'
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/modified_default_setting.db';
|
||||
|
||||
query I
|
||||
SELECT tags['storage_version'] FROM duckdb_databases() WHERE database_name='modified_default_setting'
|
||||
----
|
||||
v1.2.0+
|
||||
17
external/duckdb/test/sql/attach/attach_table_constraints.test
vendored
Normal file
17
external/duckdb/test/sql/attach/attach_table_constraints.test
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
# name: test/sql/attach/attach_table_constraints.test
|
||||
# description: Test information_schema.table_constraints with attach
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/constraint_test.db' as test
|
||||
|
||||
statement ok
|
||||
CREATE TABLE test.tbl(i INTEGER PRIMARY KEY);
|
||||
|
||||
query III
|
||||
select constraint_catalog, table_catalog, table_name from information_schema.table_constraints limit 1
|
||||
----
|
||||
test test tbl
|
||||
108
external/duckdb/test/sql/attach/attach_table_ddl.test
vendored
Normal file
108
external/duckdb/test/sql/attach/attach_table_ddl.test
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
# name: test/sql/attach/attach_table_ddl.test
|
||||
# description: Test various DDL statements on an attached database
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement ok
|
||||
ATTACH DATABASE ':memory:' AS new_database;
|
||||
|
||||
statement ok
|
||||
CREATE SCHEMA new_database.s1;
|
||||
|
||||
foreach prefix new_database.s1 new_database
|
||||
|
||||
statement ok
|
||||
CREATE TABLE ${prefix}.integers(i INTEGER)
|
||||
|
||||
# insert
|
||||
statement ok
|
||||
INSERT INTO ${prefix}.integers VALUES (42);
|
||||
|
||||
query I
|
||||
SELECT * FROM ${prefix}.integers
|
||||
----
|
||||
42
|
||||
|
||||
# update
|
||||
query I
|
||||
UPDATE ${prefix}.integers SET i=i+1
|
||||
----
|
||||
1
|
||||
|
||||
query I
|
||||
SELECT * FROM ${prefix}.integers
|
||||
----
|
||||
43
|
||||
|
||||
# delete
|
||||
query I
|
||||
DELETE FROM ${prefix}.integers WHERE i=43
|
||||
----
|
||||
1
|
||||
|
||||
query I
|
||||
SELECT COUNT(*) FROM ${prefix}.integers
|
||||
----
|
||||
0
|
||||
|
||||
# alter table statements
|
||||
|
||||
# add column
|
||||
statement ok
|
||||
ALTER TABLE ${prefix}.integers ADD COLUMN j VARCHAR
|
||||
|
||||
statement ok
|
||||
INSERT INTO ${prefix}.integers VALUES (1, 'T100');
|
||||
|
||||
query II
|
||||
SELECT * FROM ${prefix}.integers
|
||||
----
|
||||
1 T100
|
||||
|
||||
# alter type
|
||||
statement ok
|
||||
ALTER TABLE ${prefix}.integers ALTER j TYPE INT USING REPLACE(j, 'T', '')::INT
|
||||
|
||||
query II
|
||||
SELECT * FROM ${prefix}.integers
|
||||
----
|
||||
1 100
|
||||
|
||||
# drop column
|
||||
statement ok
|
||||
ALTER TABLE ${prefix}.integers DROP COLUMN j
|
||||
|
||||
query I
|
||||
SELECT * FROM ${prefix}.integers
|
||||
----
|
||||
1
|
||||
|
||||
# rename column
|
||||
statement ok
|
||||
ALTER TABLE ${prefix}.integers RENAME COLUMN i TO k
|
||||
|
||||
query I
|
||||
SELECT k FROM ${prefix}.integers
|
||||
----
|
||||
1
|
||||
|
||||
# drop table
|
||||
statement ok
|
||||
DROP TABLE ${prefix}.integers
|
||||
|
||||
# rename table
|
||||
statement ok
|
||||
CREATE TABLE ${prefix}.t1(i INTEGER)
|
||||
|
||||
statement ok
|
||||
ALTER TABLE ${prefix}.t1 RENAME TO t2
|
||||
|
||||
statement ok
|
||||
SELECT * FROM ${prefix}.t2
|
||||
|
||||
statement ok
|
||||
DROP TABLE ${prefix}.t2
|
||||
|
||||
endloop
|
||||
48
external/duckdb/test/sql/attach/attach_table_info.test
vendored
Normal file
48
external/duckdb/test/sql/attach/attach_table_info.test
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
# name: test/sql/attach/attach_table_info.test
|
||||
# description: Test ATTACH with table info
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
# attach a new database
|
||||
statement ok
|
||||
ATTACH DATABASE ':memory:' AS new_database;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE new_database.integers(i INTEGER)
|
||||
|
||||
query ITTTTT nosort table_info
|
||||
PRAGMA table_info('new_database.integers');
|
||||
----
|
||||
0 i INTEGER 0 NULL 0
|
||||
|
||||
# mixed with a schema
|
||||
statement ok
|
||||
CREATE SCHEMA new_database.new_schema
|
||||
|
||||
statement ok
|
||||
CREATE TABLE new_database.new_schema.integers(i INTEGER)
|
||||
|
||||
query ITTTTT nosort table_info
|
||||
PRAGMA table_info('new_database.new_schema.integers');
|
||||
----
|
||||
0 i INTEGER 0 NULL 0
|
||||
|
||||
query I
|
||||
SELECT current_database()
|
||||
----
|
||||
memory
|
||||
|
||||
statement ok
|
||||
USE new_database.new_schema
|
||||
|
||||
query ITTTTT nosort table_info
|
||||
PRAGMA table_info('integers');
|
||||
----
|
||||
0 i INTEGER 0 NULL 0
|
||||
|
||||
query I
|
||||
SELECT current_database()
|
||||
----
|
||||
new_database
|
||||
112
external/duckdb/test/sql/attach/attach_transactionality.test
vendored
Normal file
112
external/duckdb/test/sql/attach/attach_transactionality.test
vendored
Normal file
@@ -0,0 +1,112 @@
|
||||
# name: test/sql/attach/attach_transactionality.test
|
||||
# description: Test transactionality of attach
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
# straightforward attach and rollback
|
||||
statement ok
|
||||
BEGIN TRANSACTION
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/attach_transaction.db'
|
||||
|
||||
statement ok
|
||||
ROLLBACK
|
||||
|
||||
# attach and insert data, then rollback
|
||||
# the data should never make it into the attached database
|
||||
statement ok
|
||||
BEGIN TRANSACTION
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/attach_transaction.db'
|
||||
|
||||
statement ok
|
||||
CREATE TABLE attach_transaction.integers(i INTEGER)
|
||||
|
||||
statement ok
|
||||
INSERT INTO attach_transaction.integers VALUES (42)
|
||||
|
||||
statement ok
|
||||
ROLLBACK
|
||||
|
||||
# now commit
|
||||
statement ok
|
||||
BEGIN TRANSACTION
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/attach_transaction.db'
|
||||
|
||||
statement ok
|
||||
CREATE TABLE attach_transaction.integers(i INTEGER)
|
||||
|
||||
statement ok
|
||||
INSERT INTO attach_transaction.integers VALUES (42)
|
||||
|
||||
statement ok
|
||||
COMMIT
|
||||
|
||||
# detach is not transactional
|
||||
statement ok
|
||||
BEGIN TRANSACTION
|
||||
|
||||
statement ok
|
||||
DETACH attach_transaction
|
||||
|
||||
statement ok
|
||||
ROLLBACK
|
||||
|
||||
statement error
|
||||
DETACH attach_transaction
|
||||
----
|
||||
database not found
|
||||
|
||||
# what if we attach, push entries, then detach, and then rollback!?
|
||||
statement ok
|
||||
BEGIN TRANSACTION
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/attach_transaction.db'
|
||||
|
||||
statement ok
|
||||
INSERT INTO attach_transaction.integers VALUES (84)
|
||||
|
||||
statement ok
|
||||
DETACH attach_transaction
|
||||
|
||||
statement ok
|
||||
ROLLBACK
|
||||
|
||||
# now do the same but commit
|
||||
statement ok
|
||||
BEGIN TRANSACTION
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/attach_transaction.db'
|
||||
|
||||
# verify the previous data was not written
|
||||
query I
|
||||
SELECT * FROM attach_transaction.integers
|
||||
----
|
||||
42
|
||||
|
||||
statement ok
|
||||
INSERT INTO attach_transaction.integers VALUES (84)
|
||||
|
||||
statement ok
|
||||
DETACH attach_transaction
|
||||
|
||||
statement ok
|
||||
COMMIT
|
||||
|
||||
# now if we attach we should see [42, 84]
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/attach_transaction.db'
|
||||
|
||||
query I
|
||||
SELECT * FROM attach_transaction.integers ORDER BY 1
|
||||
----
|
||||
42
|
||||
84
|
||||
20
external/duckdb/test/sql/attach/attach_use_rollback.test
vendored
Normal file
20
external/duckdb/test/sql/attach/attach_use_rollback.test
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
# name: test/sql/attach/attach_use_rollback.test
|
||||
# description: Test rolling back of an attach leading to the default database not being attached
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
begin;
|
||||
|
||||
statement ok
|
||||
attach ':memory:' as mem;
|
||||
|
||||
statement ok
|
||||
use mem;
|
||||
|
||||
statement ok
|
||||
rollback;
|
||||
|
||||
statement error
|
||||
create table tbl(i int);
|
||||
----
|
||||
mem does not exist
|
||||
78
external/duckdb/test/sql/attach/attach_view_search_path.test
vendored
Normal file
78
external/duckdb/test/sql/attach/attach_view_search_path.test
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
# name: test/sql/attach/attach_view_search_path.test
|
||||
# description: Test ATTACH with search path
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement ok
|
||||
ATTACH DATABASE '__TEST_DIR__/view_search_path.db' AS view_search_path;
|
||||
|
||||
statement ok
|
||||
USE view_search_path
|
||||
|
||||
statement ok
|
||||
CREATE TABLE my_tbl(i INTEGER)
|
||||
|
||||
statement ok
|
||||
INSERT INTO my_tbl VALUES (42)
|
||||
|
||||
statement ok
|
||||
CREATE VIEW my_view AS FROM my_tbl
|
||||
|
||||
query I
|
||||
FROM my_view
|
||||
----
|
||||
42
|
||||
|
||||
statement ok
|
||||
CREATE SCHEMA my_schema
|
||||
|
||||
statement ok
|
||||
USE my_schema
|
||||
|
||||
statement ok
|
||||
CREATE TABLE my_tbl(i INTEGER)
|
||||
|
||||
statement ok
|
||||
INSERT INTO my_tbl VALUES (84)
|
||||
|
||||
statement ok
|
||||
CREATE VIEW my_view AS FROM my_tbl
|
||||
|
||||
query I
|
||||
FROM my_view
|
||||
----
|
||||
84
|
||||
|
||||
statement ok
|
||||
ATTACH DATABASE '__TEST_DIR__/view_search_path_other.db';
|
||||
|
||||
statement ok
|
||||
USE view_search_path_other;
|
||||
|
||||
query I
|
||||
FROM view_search_path.my_view
|
||||
----
|
||||
42
|
||||
|
||||
query I
|
||||
FROM view_search_path.my_schema.my_view
|
||||
----
|
||||
84
|
||||
|
||||
statement ok
|
||||
DETACH view_search_path
|
||||
|
||||
statement ok
|
||||
ATTACH DATABASE '__TEST_DIR__/view_search_path.db' AS view_search_path;
|
||||
|
||||
query I
|
||||
FROM view_search_path.my_view
|
||||
----
|
||||
42
|
||||
|
||||
query I
|
||||
FROM view_search_path.my_schema.my_view
|
||||
----
|
||||
84
|
||||
71
external/duckdb/test/sql/attach/attach_views.test
vendored
Normal file
71
external/duckdb/test/sql/attach/attach_views.test
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
# name: test/sql/attach/attach_views.test
|
||||
# description: Test views in an attached database
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement ok
|
||||
ATTACH DATABASE ':memory:' AS new_database;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE t1 AS SELECT 42 i
|
||||
|
||||
statement ok
|
||||
CREATE SCHEMA new_database.s1;
|
||||
|
||||
foreach prefix new_database.s1 new_database
|
||||
|
||||
# reference table in other database in view
|
||||
statement ok
|
||||
CREATE VIEW ${prefix}.v1 AS SELECT * FROM t1
|
||||
|
||||
query I
|
||||
SELECT * FROM ${prefix}.v1
|
||||
----
|
||||
42
|
||||
|
||||
# reference table in current database in view
|
||||
statement ok
|
||||
CREATE TABLE ${prefix}.t1 AS SELECT 84 i
|
||||
|
||||
statement ok
|
||||
CREATE OR REPLACE VIEW ${prefix}.v1 AS SELECT * FROM ${prefix}.t1
|
||||
|
||||
query I
|
||||
SELECT * FROM ${prefix}.t1
|
||||
----
|
||||
84
|
||||
|
||||
query I
|
||||
SELECT * FROM ${prefix}.v1
|
||||
----
|
||||
84
|
||||
|
||||
# reference tables from different databases in view
|
||||
statement ok
|
||||
CREATE OR REPLACE VIEW ${prefix}.v1 AS SELECT * FROM ${prefix}.t1 UNION ALL FROM memory.t1 ORDER BY ALL
|
||||
|
||||
query I
|
||||
SELECT * FROM ${prefix}.v1
|
||||
----
|
||||
42
|
||||
84
|
||||
|
||||
# rename view
|
||||
statement ok
|
||||
ALTER VIEW ${prefix}.v1 RENAME TO v2
|
||||
|
||||
query I
|
||||
SELECT * FROM ${prefix}.v2
|
||||
----
|
||||
42
|
||||
84
|
||||
|
||||
statement ok
|
||||
DROP VIEW ${prefix}.v2
|
||||
|
||||
statement ok
|
||||
DROP TABLE ${prefix}.t1
|
||||
|
||||
endloop
|
||||
47
external/duckdb/test/sql/attach/attach_wal_alter.test
vendored
Normal file
47
external/duckdb/test/sql/attach/attach_wal_alter.test
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
# name: test/sql/attach/attach_wal_alter.test
|
||||
# description: WAL cannot alter table
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement ok
|
||||
ATTACH DATABASE '__TEST_DIR__/wal_crash.db' as db1;
|
||||
|
||||
statement ok
|
||||
USE db1;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE t2(c1 INT);
|
||||
|
||||
statement ok
|
||||
CHECKPOINT;
|
||||
|
||||
statement ok
|
||||
SET wal_autocheckpoint='1TB';
|
||||
|
||||
statement ok
|
||||
PRAGMA disable_checkpoint_on_shutdown;
|
||||
|
||||
statement ok
|
||||
ALTER TABLE t2 ALTER c1 SET DEFAULT 0;
|
||||
|
||||
statement ok
|
||||
ATTACH DATABASE ':memory:' as db2;
|
||||
|
||||
statement ok
|
||||
USE db2;
|
||||
|
||||
statement ok
|
||||
detach db1;
|
||||
|
||||
statement ok
|
||||
ATTACH DATABASE '__TEST_DIR__/wal_crash.db' as db1;
|
||||
|
||||
statement ok
|
||||
INSERT INTO db1.t2 DEFAULT VALUES
|
||||
|
||||
query I
|
||||
SELECT * FROM db1.t2
|
||||
----
|
||||
0
|
||||
50
external/duckdb/test/sql/attach/attach_wal_alter_sequence.test
vendored
Normal file
50
external/duckdb/test/sql/attach/attach_wal_alter_sequence.test
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
# name: test/sql/attach/attach_wal_alter_sequence.test
|
||||
# description: Test binding of a WAL with a sequence entry in it
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
PRAGMA disable_checkpoint_on_shutdown
|
||||
|
||||
statement ok
|
||||
PRAGMA wal_autocheckpoint='1TB';
|
||||
|
||||
# create a table with hugeints
|
||||
statement ok
|
||||
attach '__TEST_DIR__/attach_wal_with_sequence.db' as db1;
|
||||
|
||||
statement ok
|
||||
CREATE SEQUENCE db1.seq;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE db1.test (a INTEGER DEFAULT nextval('seq'), b INTEGER, c INTEGER DEFAULT currval('seq'));
|
||||
|
||||
statement ok
|
||||
INSERT INTO db1.test (b) VALUES (1);
|
||||
|
||||
statement ok
|
||||
alter table db1.test RENAME TO blubb;
|
||||
|
||||
statement ok
|
||||
INSERT INTO db1.blubb (b) VALUES (10);
|
||||
|
||||
query III
|
||||
SELECT * FROM db1.blubb
|
||||
----
|
||||
1 1 1
|
||||
2 10 2
|
||||
|
||||
statement ok
|
||||
DETACH db1
|
||||
|
||||
statement ok
|
||||
attach '__TEST_DIR__/attach_wal_with_sequence.db' as db2;
|
||||
|
||||
statement ok
|
||||
INSERT INTO db2.blubb (b) VALUES (100);
|
||||
|
||||
query III
|
||||
SELECT * FROM db2.blubb
|
||||
----
|
||||
1 1 1
|
||||
2 10 2
|
||||
3 100 3
|
||||
12
external/duckdb/test/sql/attach/detach_keyword.test
vendored
Normal file
12
external/duckdb/test/sql/attach/detach_keyword.test
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
# name: test/sql/attach/detach_keyword.test
|
||||
# description: Test DETACH with keywords
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement ok
|
||||
ATTACH DATABASE ':memory:' AS varchar;
|
||||
|
||||
statement ok
|
||||
DETACH varchar
|
||||
59
external/duckdb/test/sql/attach/in_memory_attach.test
vendored
Normal file
59
external/duckdb/test/sql/attach/in_memory_attach.test
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
# name: test/sql/attach/in_memory_attach.test
|
||||
# description: Test in-memory attach
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement ok
|
||||
ATTACH DATABASE ':memory:' AS new_database;
|
||||
|
||||
# specify database but use a default schema
|
||||
statement ok
|
||||
CREATE TABLE new_database.integers(i INTEGER)
|
||||
|
||||
statement ok
|
||||
INSERT INTO new_database.integers VALUES (42);
|
||||
|
||||
# plus schema
|
||||
statement ok
|
||||
INSERT INTO new_database.main.integers VALUES (84);
|
||||
|
||||
# not in search path
|
||||
statement error
|
||||
SELECT * FROM integers
|
||||
----
|
||||
does not exist
|
||||
|
||||
query I
|
||||
SELECT * FROM new_database.integers ORDER BY i
|
||||
----
|
||||
42
|
||||
84
|
||||
|
||||
# plus schema
|
||||
query I
|
||||
SELECT * FROM new_database.main.integers ORDER BY i
|
||||
----
|
||||
42
|
||||
84
|
||||
|
||||
# database + column name does not work
|
||||
statement error
|
||||
SELECT * FROM new_database.integers ORDER BY new_database.i
|
||||
----
|
||||
not found
|
||||
|
||||
# database + table name + column name works
|
||||
query I
|
||||
SELECT * FROM new_database.integers ORDER BY new_database.integers.i
|
||||
----
|
||||
42
|
||||
84
|
||||
|
||||
# database + schema name + table name + column name works as well
|
||||
query I
|
||||
SELECT * FROM new_database.main.integers ORDER BY new_database.main.integers.i
|
||||
----
|
||||
42
|
||||
84
|
||||
112
external/duckdb/test/sql/attach/reattach_schema.test
vendored
Normal file
112
external/duckdb/test/sql/attach/reattach_schema.test
vendored
Normal file
@@ -0,0 +1,112 @@
|
||||
# name: test/sql/attach/reattach_schema.test
|
||||
# description: Re-attach a database with a non-standard schema and re-name the database
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/reattach_schema.db' AS new_db;
|
||||
|
||||
statement ok
|
||||
CREATE SCHEMA new_db.my_schema;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE new_db.my_schema.my_table(col INTEGER);
|
||||
|
||||
statement ok
|
||||
INSERT INTO new_db.my_schema.my_table VALUES (42);
|
||||
|
||||
statement ok
|
||||
CREATE VIEW new_db.my_schema.my_view AS SELECT 84
|
||||
|
||||
statement ok
|
||||
CREATE SEQUENCE new_db.my_schema.my_sequence;
|
||||
|
||||
statement ok
|
||||
CREATE MACRO new_db.my_schema.one() AS (SELECT 1);
|
||||
|
||||
statement ok
|
||||
CREATE MACRO new_db.my_schema.range(a) as TABLE SELECT * FROM range(a)
|
||||
|
||||
query I
|
||||
SELECT new_db.my_schema.one()
|
||||
----
|
||||
1
|
||||
|
||||
query I
|
||||
SELECT * FROM new_db.my_schema.range(3)
|
||||
----
|
||||
0
|
||||
1
|
||||
2
|
||||
|
||||
statement ok
|
||||
DETACH new_db
|
||||
|
||||
statement ok
|
||||
ATTACH '__TEST_DIR__/reattach_schema.db' AS new_name;
|
||||
|
||||
query I
|
||||
SELECT * FROM new_name.my_schema.my_table
|
||||
----
|
||||
42
|
||||
|
||||
query I
|
||||
SELECT * FROM new_name.my_schema.my_view
|
||||
----
|
||||
84
|
||||
|
||||
query I
|
||||
SELECT nextval('new_name.my_schema.my_sequence')
|
||||
----
|
||||
1
|
||||
|
||||
query I
|
||||
SELECT new_name.my_schema.one()
|
||||
----
|
||||
1
|
||||
|
||||
query I
|
||||
SELECT * FROM new_name.my_schema.range(3)
|
||||
----
|
||||
0
|
||||
1
|
||||
2
|
||||
|
||||
statement ok
|
||||
USE new_name.my_schema
|
||||
|
||||
statement error
|
||||
USE new_name.my_schema.my_table
|
||||
----
|
||||
Parser Error: Expected "USE database" or "USE database.schema"
|
||||
|
||||
query I
|
||||
SELECT * FROM my_table
|
||||
----
|
||||
42
|
||||
|
||||
query I
|
||||
SELECT * FROM my_view
|
||||
----
|
||||
84
|
||||
|
||||
query I
|
||||
SELECT nextval('my_sequence')
|
||||
----
|
||||
2
|
||||
|
||||
query I
|
||||
SELECT one()
|
||||
----
|
||||
1
|
||||
|
||||
# FIXME - this leads to infinite recursion
|
||||
mode skip
|
||||
|
||||
query I
|
||||
SELECT * FROM range(3)
|
||||
----
|
||||
0
|
||||
1
|
||||
2
|
||||
|
||||
mode unskip
|
||||
38
external/duckdb/test/sql/attach/show_databases.test
vendored
Normal file
38
external/duckdb/test/sql/attach/show_databases.test
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
# name: test/sql/attach/show_databases.test
|
||||
# description: Test SHOW DATABASES and USE
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement ok
|
||||
ATTACH DATABASE ':memory:' AS new_database;
|
||||
|
||||
query I
|
||||
SHOW DATABASES
|
||||
----
|
||||
memory
|
||||
new_database
|
||||
|
||||
query I
|
||||
SELECT name FROM pragma_database_list ORDER BY name
|
||||
----
|
||||
memory
|
||||
new_database
|
||||
|
||||
# check changing the default database
|
||||
statement ok
|
||||
USE new_database
|
||||
|
||||
statement ok
|
||||
CREATE TABLE tbl AS SELECT 42 i
|
||||
|
||||
query I
|
||||
SELECT * FROM new_database.tbl
|
||||
----
|
||||
42
|
||||
|
||||
statement error
|
||||
USE blablabla
|
||||
----
|
||||
No catalog + schema named "blablabla" found
|
||||
46
external/duckdb/test/sql/attach/system_catalog.test
vendored
Normal file
46
external/duckdb/test/sql/attach/system_catalog.test
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
# name: test/sql/attach/system_catalog.test
|
||||
# description: Test interactions with the SYSTEM catalog
|
||||
# group: [attach]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
# cannot detach system/temp catalogs
|
||||
statement error
|
||||
DETACH DATABASE system
|
||||
----
|
||||
|
||||
statement error
|
||||
DETACH DATABASE temp
|
||||
----
|
||||
|
||||
# cannot create entries in the system catalog
|
||||
statement error
|
||||
CREATE SCHEMA system.eek
|
||||
----
|
||||
system catalog
|
||||
|
||||
statement error
|
||||
CREATE TABLE system.main.integers(i INTEGER)
|
||||
----
|
||||
system catalog
|
||||
|
||||
statement error
|
||||
CREATE VIEW system.main.integers AS SELECT 42
|
||||
----
|
||||
system catalog
|
||||
|
||||
statement error
|
||||
CREATE SEQUENCE system.main.seq
|
||||
----
|
||||
system catalog
|
||||
|
||||
statement error
|
||||
CREATE MACRO system.main.my_macro(a,b) AS a+b
|
||||
----
|
||||
system catalog
|
||||
|
||||
statement error
|
||||
CREATE TYPE system.main.rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple');
|
||||
----
|
||||
system catalog
|
||||
Reference in New Issue
Block a user