should be it
This commit is contained in:
111
external/duckdb/test/sql/pragma/test_table_info.test
vendored
Normal file
111
external/duckdb/test/sql/pragma/test_table_info.test
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
# name: test/sql/pragma/test_table_info.test
|
||||
# description: Test table_info pragma
|
||||
# group: [pragma]
|
||||
|
||||
statement ok
|
||||
CREATE TABLE integers(i INTEGER DEFAULT 1+3, j INTEGER)
|
||||
|
||||
# PRAGMA table_info(table) returns information on the table
|
||||
query ITTTTT nosort table_info
|
||||
PRAGMA table_info('integers');
|
||||
----
|
||||
0 i INTEGER 0 1 + 3 0
|
||||
1 j INTEGER 0 NULL 0
|
||||
|
||||
# these are all equivalent
|
||||
query ITTTTT nosort table_info
|
||||
PRAGMA table_info(integers);
|
||||
----
|
||||
|
||||
query ITTTTT nosort table_info
|
||||
PRAGMA table_info='integers';
|
||||
----
|
||||
|
||||
query ITTTTT nosort table_info
|
||||
PRAGMA table_info=integers;
|
||||
----
|
||||
|
||||
# table_info on view also works
|
||||
statement ok
|
||||
CREATE VIEW v1 AS SELECT 42::INTEGER AS a, 'hello' AS b
|
||||
|
||||
query ITTTTT
|
||||
PRAGMA table_info('v1')
|
||||
----
|
||||
0 a INTEGER 0 NULL 0
|
||||
1 b VARCHAR 0 NULL 0
|
||||
|
||||
# view with explicit aliases
|
||||
statement ok
|
||||
CREATE VIEW v2(c) AS SELECT 42::INTEGER AS a, 'hello' AS b
|
||||
|
||||
query ITTTTT
|
||||
PRAGMA table_info('v2')
|
||||
----
|
||||
0 c INTEGER 0 NULL 0
|
||||
1 b VARCHAR 0 NULL 0
|
||||
|
||||
statement ok
|
||||
CREATE VIEW v3(c, d) AS SELECT DATE '1992-01-01', 'hello' AS b
|
||||
|
||||
query ITTTTT
|
||||
PRAGMA table_info('v3')
|
||||
----
|
||||
0 c DATE 0 NULL 0
|
||||
1 d VARCHAR 0 NULL 0
|
||||
|
||||
# test table info with other schemas
|
||||
statement ok
|
||||
CREATE SCHEMA test
|
||||
|
||||
statement ok
|
||||
CREATE VIEW test.v1 AS SELECT 42::INTEGER AS a, 'hello' AS b
|
||||
|
||||
query ITTTTT
|
||||
PRAGMA table_info('test.v1')
|
||||
----
|
||||
0 a INTEGER 0 NULL 0
|
||||
1 b VARCHAR 0 NULL 0
|
||||
|
||||
statement error
|
||||
PRAGMA table_info('nonexistant_table');
|
||||
----
|
||||
|
||||
# handle constraints + default values
|
||||
statement ok
|
||||
create table tconstraint1(i integer primary key default(3), j blob not null);
|
||||
|
||||
query ITTTTT
|
||||
PRAGMA table_info(tconstraint1)
|
||||
----
|
||||
0 i INTEGER 1 3 1
|
||||
1 j BLOB 1 NULL 0
|
||||
|
||||
# multi-column pk
|
||||
statement ok
|
||||
create table tconstraint2(i integer, j integer, k integer, l integer unique, primary key(i, j, k));
|
||||
|
||||
query ITTTTT
|
||||
PRAGMA table_info(tconstraint2)
|
||||
----
|
||||
0 i INTEGER 1 NULL 1
|
||||
1 j INTEGER 1 NULL 1
|
||||
2 k INTEGER 1 NULL 1
|
||||
3 l INTEGER 0 NULL 0
|
||||
|
||||
# incorrect number of parameters
|
||||
statement error
|
||||
PRAGMA table_info(1,2,3);
|
||||
----
|
||||
|
||||
statement ok
|
||||
create table t1 (
|
||||
c1 int,
|
||||
c2 int generated always as (c1 + 1)
|
||||
);
|
||||
|
||||
query IIIIII
|
||||
SELECT * FROM pragma_table_info(t1);
|
||||
----
|
||||
0 c1 INTEGER false NULL false
|
||||
1 c2 INTEGER false CAST((c1 + 1) AS INTEGER) false
|
||||
Reference in New Issue
Block a user