Skip to content

Commit ed48ff6

Browse files
committed
First attempt at fixing issue 761
1 parent 2bdab0d commit ed48ff6

File tree

6 files changed

+68
-1
lines changed

6 files changed

+68
-1
lines changed

include/pgduckdb/pgduckdb_xact.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ void AutocommitSingleStatementQueries();
2323
void MarkStatementNotTopLevel();
2424
void SetStatementTopLevel(bool top_level);
2525
bool IsStatementTopLevel();
26+
std::string FindAndResetPendingError();
2627
} // namespace pgduckdb

src/pgduckdb_node.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include "pgduckdb/pgduckdb_planner.hpp"
77
#include "pgduckdb/pgduckdb_types.hpp"
8+
#include "pgduckdb/pgduckdb_xact.hpp"
89
#include "pgduckdb/vendor/pg_explain.hpp"
910

1011
extern "C" {
@@ -325,6 +326,12 @@ void
325326
Duckdb_EndCustomScan_Cpp(CustomScanState *node) {
326327
DuckdbScanState *duckdb_scan_state = (DuckdbScanState *)node;
327328
CleanupDuckdbScanState(duckdb_scan_state);
329+
330+
auto err = pgduckdb::FindAndResetPendingError();
331+
if (!err.empty() && QueryCancelHoldoffCount == 0) {
332+
throw duckdb::Exception(duckdb::ExceptionType::EXECUTOR, err);
333+
}
334+
328335
/*
329336
* BUG: In rare error casess it's possible that we call this when we are
330337
* currently accepting interupts, in those cases we should not resume them

src/pgduckdb_xact.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,22 @@
1010
#include "pgduckdb/pg/transactions.hpp"
1111
#include "pgduckdb/utility/cpp_wrapper.hpp"
1212

13+
extern "C" {
14+
extern bool ExitOnAnyError;
15+
}
16+
1317
namespace pgduckdb {
1418

1519
static CommandId next_expected_command_id = FirstCommandId;
1620
static bool top_level_statement = true;
21+
static std::string pending_error;
22+
23+
std::string
24+
FindAndResetPendingError() {
25+
auto prev = pending_error;
26+
pending_error = "";
27+
return prev;
28+
}
1729

1830
namespace pg {
1931

@@ -307,14 +319,19 @@ DuckdbSubXactCallback_Cpp(SubXactEvent event) {
307319
if (!DuckDBManager::IsInitialized()) {
308320
return;
309321
}
322+
310323
auto connection = DuckDBManager::GetConnectionUnsafe();
311324
auto &context = *connection->context;
312325
if (!context.transaction.HasActiveTransaction()) {
313326
return;
314327
}
315328

316329
if (event == SUBXACT_EVENT_START_SUB) {
317-
throw duckdb::NotImplementedException("SAVEPOINT is not supported in DuckDB");
330+
if (ExitOnAnyError) {
331+
pending_error = "SAVEPOINT is not supported in DuckDB";
332+
} else {
333+
throw duckdb::NotImplementedException("SAVEPOINT is not supported in DuckDB");
334+
}
318335
}
319336
}
320337

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
SET duckdb.force_execution = TRUE;
2+
DO $$
3+
DECLARE
4+
objtype text;
5+
BEGIN
6+
FOR objtype IN VALUES ('toast table'), ('index column'), ('sequence column'),
7+
('toast table column'), ('view column'), ('materialized view column')
8+
LOOP
9+
BEGIN
10+
PERFORM pg_get_object_address(objtype, '{one}', '{}');
11+
EXCEPTION WHEN invalid_parameter_value THEN
12+
RAISE WARNING 'error for %: %', objtype, sqlerrm;
13+
END;
14+
END LOOP;
15+
END;
16+
$$;
17+
WARNING: error for toast table: unsupported object type "toast table"
18+
WARNING: error for index column: unsupported object type "index column"
19+
WARNING: error for sequence column: unsupported object type "sequence column"
20+
WARNING: error for toast table column: unsupported object type "toast table column"
21+
WARNING: error for view column: unsupported object type "view column"
22+
WARNING: error for materialized view column: unsupported object type "materialized view column"
23+
ERROR: (PGDuckDB/Duckdb_EndCustomScan_Cpp) Executor Error: SAVEPOINT is not supported in DuckDB
24+
CONTEXT: PL/pgSQL function inline_code_block line 5 at FOR over SELECT rows

test/regression/schedule

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ test: issue_410
2525
test: issue_730
2626
test: issue_748
2727
test: issue_749
28+
test: issue_761
2829
test: issue_789
2930
test: issue_796
3031
test: issue_802

test/regression/sql/issue_761.sql

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
SET duckdb.force_execution = TRUE;
2+
3+
DO $$
4+
DECLARE
5+
objtype text;
6+
BEGIN
7+
FOR objtype IN VALUES ('toast table'), ('index column'), ('sequence column'),
8+
('toast table column'), ('view column'), ('materialized view column')
9+
LOOP
10+
BEGIN
11+
PERFORM pg_get_object_address(objtype, '{one}', '{}');
12+
EXCEPTION WHEN invalid_parameter_value THEN
13+
RAISE WARNING 'error for %: %', objtype, sqlerrm;
14+
END;
15+
END LOOP;
16+
END;
17+
$$;

0 commit comments

Comments
 (0)