Skip to content

Commit 03eaed7

Browse files
authored
Merge pull request #261 from duckdb/copyfromdatabase
Add copy from database test - plus throw an error with unsupported CAST_FROM_VARCHAR composite column types
2 parents 58dc3d0 + 08d523a commit 03eaed7

File tree

7 files changed

+90
-7
lines changed

7 files changed

+90
-7
lines changed

.github/workflows/Linux.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ jobs:
113113
source ./create-postgres-tables.sh
114114
make test_release
115115
116-
- uses: actions/upload-artifact@v2
116+
- uses: actions/upload-artifact@v3
117117
with:
118118
name: ${{matrix.arch}}-extensions
119119
path: |

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ release:
7272

7373
test: test_release
7474
test_release: release
75-
./build/release/$(TEST_PATH) "$(PROJ_DIR)test/*"
75+
./build/release/$(TEST_PATH) --test-dir "$(PROJ_DIR)" "test/*"
7676
test_debug: debug
77-
./build/debug/$(TEST_PATH) "$(PROJ_DIR)test/*"
77+
./build/debug/$(TEST_PATH) --test-dir "$(PROJ_DIR)" "test/*"
7878

7979
format:
8080
cp duckdb/.clang-format .

duckdb

Submodule duckdb updated 198 files

src/postgres_scanner.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,18 @@ static unique_ptr<FunctionData> PostgresBind(ClientContext &context, TableFuncti
177177
return std::move(bind_data);
178178
}
179179

180+
static bool ContainsCastToVarchar(const PostgresType &type) {
181+
if (type.info == PostgresTypeAnnotation::CAST_TO_VARCHAR) {
182+
return true;
183+
}
184+
for (auto &child : type.children) {
185+
if (ContainsCastToVarchar(child)) {
186+
return true;
187+
}
188+
}
189+
return false;
190+
}
191+
180192
static void PostgresInitInternal(ClientContext &context, const PostgresBindData *bind_data_p,
181193
PostgresLocalState &lstate, idx_t task_min, idx_t task_max) {
182194
D_ASSERT(bind_data_p);
@@ -200,14 +212,20 @@ static void PostgresInitInternal(ClientContext &context, const PostgresBindData
200212
col_names += KeywordHelper::WriteQuoted(bind_data->names[column_id], '"');
201213
if (bind_data->postgres_types[column_id].info == PostgresTypeAnnotation::CAST_TO_VARCHAR) {
202214
col_names += "::VARCHAR";
203-
}
204-
if (bind_data->types[column_id].id() == LogicalTypeId::LIST) {
215+
} else if (bind_data->types[column_id].id() == LogicalTypeId::LIST) {
205216
if (bind_data->postgres_types[column_id].info != PostgresTypeAnnotation::STANDARD) {
206217
continue;
207218
}
208219
if (bind_data->postgres_types[column_id].children[0].info == PostgresTypeAnnotation::CAST_TO_VARCHAR) {
209220
col_names += "::VARCHAR[]";
210221
}
222+
} else {
223+
if (ContainsCastToVarchar(bind_data->postgres_types[column_id])) {
224+
throw NotImplementedException("Error reading table \"%s\" - cast to varchar not implemented for "
225+
"composite column \"%s\" (type %s)",
226+
bind_data->table_name, bind_data->names[column_id],
227+
bind_data->types[column_id].ToString());
228+
}
211229
}
212230
}
213231
}

src/postgres_utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ LogicalType PostgresUtils::ToPostgresType(const LogicalType &input) {
253253
case LogicalTypeId::UINTEGER:
254254
return LogicalType::BIGINT;
255255
case LogicalTypeId::UBIGINT:
256-
return LogicalType::DECIMAL(20, 0);
256+
return LogicalType::DECIMAL(20, 0);
257257
case LogicalTypeId::HUGEINT:
258258
return LogicalType::DOUBLE;
259259
default:

test/copydb.sql

Whitespace-only changes.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# name: test/sql/storage/attach_copy_from_database.test
2+
# description: Test copy from database
3+
# group: [storage]
4+
5+
require postgres_scanner
6+
7+
require-env POSTGRES_TEST_DATABASE_AVAILABLE
8+
9+
statement ok
10+
PRAGMA enable_verification
11+
12+
statement ok
13+
ATTACH 'dbname=postgresscanner' AS s1 (TYPE POSTGRES)
14+
15+
statement ok
16+
DROP SCHEMA IF EXISTS s1.copy_schema CASCADE
17+
18+
statement ok
19+
CREATE SCHEMA s1.copy_schema
20+
21+
statement ok
22+
USE s1.copy_schema
23+
24+
foreach table_name pg_numtypes pg_bytetypes pg_datetypes
25+
26+
statement ok
27+
CREATE TABLE ${table_name} AS FROM public.${table_name}
28+
29+
endloop
30+
31+
statement ok
32+
USE memory
33+
34+
statement ok
35+
DETACH s1
36+
37+
statement ok
38+
ATTACH 'dbname=postgresscanner' AS s1 (TYPE POSTGRES, SCHEMA 'copy_schema')
39+
40+
statement ok
41+
USE s1.copy_schema
42+
43+
statement ok
44+
create table big_tbl as from range(100000) t(id)
45+
46+
statement ok
47+
create index i_index on big_tbl(id)
48+
49+
statement ok
50+
create view my_view as select min(id) from copy_schema.big_tbl
51+
52+
statement ok
53+
ATTACH '__TEST_DIR__/copy_database.db' AS new_db;
54+
55+
statement ok
56+
COPY FROM DATABASE s1 TO new_db
57+
58+
foreach table_name pg_numtypes pg_bytetypes pg_datetypes big_tbl my_view
59+
60+
query I
61+
SELECT COUNT(*) FROM (FROM new_db.copy_schema.${table_name} EXCEPT FROM ${table_name})
62+
----
63+
0
64+
65+
endloop

0 commit comments

Comments
 (0)