What happens?
Server crashes on executing SQL test
To Reproduce
Add conf:
postgresql.auto.conf:
shared_preload_libraries = 'pg_duckdb'
duckdb.force_execution = true
duckdb.postgres_role = 'duckdb_group'
log_temp_files = -1
Modify src/test/regress/sql/encoding.sql:
CREATE EXTENSION pg_duckdb;
SELECT getdatabaseencoding() <> 'UTF8' AS skip_test \gset
\getenv libdir PG_LIBDIR
\getenv dlsuffix PG_DLSUFFIX
\set regresslib :libdir '/regress' :dlsuffix
CREATE FUNCTION test_bytea_to_text(bytea) RETURNS text
AS :'regresslib' LANGUAGE C STRICT;
CREATE FUNCTION test_text_to_bytea(text) RETURNS bytea
AS :'regresslib' LANGUAGE C STRICT;
CREATE TABLE regress_encoding(good text, truncated text, with_nul text, truncated_with_nul text);
INSERT INTO regress_encoding
VALUES ('café',
'caf' || test_bytea_to_text('\xc3'),
'café' || test_bytea_to_text('\x00') || 'dcba',
'caf' || test_bytea_to_text('\xc300') || 'dcba');
SELECT substring(truncated, 1, 4) FROM regress_encoding;
SELECT reverse(truncated) FROM regress_encoding;
Execute test
make installcheck-tests TESTS='encoding'
regression.diffs:
diff -U3 /home/egor/work/postgrespro/src/test/regress/expected/encoding_1.out /home/egor/work/postgrespro/src/test/regress/results/encoding.out
--- /home/egor/work/postgrespro/src/test/regress/expected/encoding_1.out 2026-03-20 12:06:46.142675795 +0700
+++ /home/egor/work/postgrespro/src/test/regress/results/encoding.out 2026-03-23 18:01:16.587824471 +0700
@@ -1,4 +1,24 @@
-/* skip test if not UTF8 server encoding */
+CREATE EXTENSION pg_duckdb;
+WARNING: The configured duckdb.postgres_role does not exist, falling back to superuser
+WARNING: The configured duckdb.postgres_role does not exist, falling back to superuser
SELECT getdatabaseencoding() <> 'UTF8' AS skip_test \gset
-\if :skip_test
-\quit
+\getenv libdir PG_LIBDIR
+\getenv dlsuffix PG_DLSUFFIX
+\set regresslib :libdir '/regress' :dlsuffix
+CREATE FUNCTION test_bytea_to_text(bytea) RETURNS text
+ AS :'regresslib' LANGUAGE C STRICT;
+CREATE FUNCTION test_text_to_bytea(text) RETURNS bytea
+ AS :'regresslib' LANGUAGE C STRICT;
+CREATE TABLE regress_encoding(good text, truncated text, with_nul text, truncated_with_nul text);
+INSERT INTO regress_encoding
+VALUES ('café',
+ 'caf' || test_bytea_to_text('\xc3'),
+ 'café' || test_bytea_to_text('\x00') || 'dcba',
+ 'caf' || test_bytea_to_text('\xc300') || 'dcba');
+SELECT substring(truncated, 1, 4) FROM regress_encoding;
+ERROR: (PGDuckDB/Duckdb_ExecCustomScan_Cpp) Invalid Input Error: Invalid unicode (byte sequence mismatch) detected in value construction
+SELECT reverse(truncated) FROM regress_encoding;
+server closed the connection unexpectedly
+ This probably means the server terminated abnormally
+ before or while processing the request.
+connection to server was lost
backtrace:
#0 __memcpy_avx512_unaligned_erms () at ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:832
#1 0x00007fadff4d82b6 in duckdb::StringHeap::AddBlob(char const*, unsigned long) () at /home/test/pgsql/lib/libduckdb.so
#2 0x00007fadff48ca31 in void duckdb::ColumnDataCopy<duckdb::string_t>(duckdb::ColumnDataMetaData&, duckdb::UnifiedVectorFormat const&, duckdb::Vector&, unsigned long, unsigned long) () at /home/test/pgsql/lib/libduckdb.so
#3 0x00007fadff4923cf in duckdb::ColumnDataCollection::Append(duckdb::ColumnDataAppendState&, duckdb::DataChunk&) () at /home/test/pgsql/lib/libduckdb.so
#4 0x00007fadff88e112 in duckdb::PhysicalMaterializedCollector::Sink(duckdb::ExecutionContext&, duckdb::DataChunk&, duckdb::OperatorSinkInput&) const ()
at /home/test/pgsql/lib/libduckdb.so
#5 0x00007fadffac0a6e in duckdb::PipelineExecutor::ExecutePushInternal(duckdb::DataChunk&, duckdb::ExecutionBudget&, unsigned long) () at /home/test/pgsql/lib/libduckdb.so
#6 0x00007fadffac56ce in duckdb::PipelineExecutor::Execute(unsigned long) () at /home/test/pgsql/lib/libduckdb.so
#7 0x00007fadffac5a22 in duckdb::PipelineTask::ExecuteTask(duckdb::TaskExecutionMode) () at /home/test/pgsql/lib/libduckdb.so
#8 0x00007fadffabc3f6 in duckdb::ExecutorTask::Execute(duckdb::TaskExecutionMode) () at /home/test/pgsql/lib/libduckdb.so
#9 0x00007fadffac35d2 in duckdb::Executor::ExecuteTask(bool) () at /home/test/pgsql/lib/libduckdb.so
#10 0x00007fadffa86fb0 in duckdb::ClientContext::ExecuteTaskInternal(duckdb::ClientContextLock&, duckdb::BaseQueryResult&, bool) () at /home/test/pgsql/lib/libduckdb.so
#11 0x00007fadffa87173 in duckdb::PendingQueryResult::ExecuteTask() () at /home/test/pgsql/lib/libduckdb.so
#12 0x00007fae042bbe77 in ExecuteQuery (state=state@entry=0x55baef2128c8) at src/pgduckdb_node.cpp:210
#13 0x00007fae042bcb18 in Duckdb_ExecCustomScan_Cpp (node=0x55baef2128c8) at src/pgduckdb_node.cpp:269
#14 pgduckdb::__CPPFunctionGuard__<TupleTableSlot* (*)(CustomScanState*), Duckdb_ExecCustomScan_Cpp, CustomScanState*>
(line=330, file_name=0x7fae0430cd2c "src/pgduckdb_node.cpp", func_name=0x7fae0430ce52 "Duckdb_ExecCustomScan_Cpp") at src/pgduckdb_node.cpp:330
#15 0x000055bad549e0af in ExecCustomScan (pstate=0x55baef2128c8) at nodeCustom.c:142
#16 0x000055bad547fda5 in ExecProcNodeFirst (node=0x55baef2128c8) at execProcnode.c:466
#17 0x000055bad5471264 in ExecProcNode (node=0x55baef2128c8) at ../../../src/include/executor/executor.h:299
#18 0x000055bad5474729 in ExecutePlan (queryDesc=0x55baef22cf10, operation=CMD_SELECT, sendTuples=true, numberTuples=0, direction=ForwardScanDirection, dest=0x55baeef3cb80)
at execMain.c:1886
#19 0x000055bad5471b4e in standard_ExecutorRun (queryDesc=0x55baef22cf10, direction=ForwardScanDirection, count=0, execute_once=false) at execMain.c:456
#20 0x000055bad5471925 in ExecutorRun (queryDesc=0x55baef22cf10, direction=ForwardScanDirection, count=0, execute_once=false) at execMain.c:389
#21 0x000055bad577f62e in PortalRunSelect (portal=0x55baef0853b0, forward=true, count=0, dest=0x55baeef3cb80) at pquery.c:975
#22 0x000055bad577f225 in PortalRun
(portal=0x55baef0853b0, count=9223372036854775807, isTopLevel=true, run_once=true, dest=0x55baeef3cb80, altdest=0x55baeef3cb80, qc=0x7ffe39900cb0) at pquery.c:804
#23 0x000055bad57746c0 in exec_simple_query (query_string=0x55baeef3b110 "SELECT reverse(truncated) FROM regress_encoding;") at postgres.c:1541
#24 0x000055bad577b03e in PostgresMain (dbname=0x55baeeffab70 "regression", username=0x55baeeffab58 "test") at postgres.c:5780
#25 0x000055bad576fe01 in BackendMain (startup_data=0x7ffe3990112c "", startup_data_len=4) at backend_startup.c:117
#26 0x000055bad566946d in postmaster_child_launch (child_type=B_BACKEND, startup_data=0x7ffe3990112c "", startup_data_len=4, client_sock=0x7ffe39901150) at launch_backend.c:299
#27 0x000055bad567025c in BackendStartup (client_sock=0x7ffe39901150) at postmaster.c:3898
#28 0x000055bad566c9b1 in ServerLoop () at postmaster.c:1801
#29 0x000055bad566c1bc in PostmasterMain (argc=3, argv=0x55baeeedc020) at postmaster.c:1456
#30 0x000055bad5503309 in main (argc=3, argv=0x55baeeedc020) at main.c:206
OS:
debian-13
pg_duckdb Version (if built from source use commit hash):
318ee16
Postgres Version (if built from source use commit hash):
876fa84a275eea578b4a89bb910e184f98d991c2
Hardware:
No response
Full Name:
Egor Chindyaskin
Affiliation:
Postgres Professional
What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.
I have tested with a source build
Did you include all relevant data sets for reproducing the issue?
Yes
Did you include all code required to reproduce the issue?
Did you include all relevant configuration (e.g., CPU architecture, Linux distribution) to reproduce the issue?
What happens?
Server crashes on executing SQL test
To Reproduce
Add conf:
postgresql.auto.conf:
Modify src/test/regress/sql/encoding.sql:
Execute test
make installcheck-tests TESTS='encoding'regression.diffs:
backtrace:
OS:
debian-13
pg_duckdb Version (if built from source use commit hash):
318ee16
Postgres Version (if built from source use commit hash):
876fa84a275eea578b4a89bb910e184f98d991c2
Hardware:
No response
Full Name:
Egor Chindyaskin
Affiliation:
Postgres Professional
What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.
I have tested with a source build
Did you include all relevant data sets for reproducing the issue?
Yes
Did you include all code required to reproduce the issue?
Did you include all relevant configuration (e.g., CPU architecture, Linux distribution) to reproduce the issue?