Skip to content

Conversation

@JC1738
Copy link
Owner

@JC1738 JC1738 commented Jan 21, 2026

Summary

  • Add duckarrow_execute(sql) scalar function to execute DDL/DML statements on the remote Flight SQL server
  • Addresses limitation where DROP TABLE duckarrow.X fails because DuckDB's replacement scan only intercepts table references in SELECT contexts
  • Returns affected row count (BIGINT)

Changes

  • execute_function.go - New scalar function implementation
  • internal/flight/client.go - Add Execute() method using ADBC's ExecuteUpdate()
  • main.go - Register new function during extension init
  • README.md - Add usage documentation

Usage

-- Configure connection first
SELECT duckarrow_configure('grpc+tls://localhost:31337', 'user', 'pass');

-- Execute DDL/DML
SELECT duckarrow_execute('CREATE TABLE "test" (id INTEGER, name VARCHAR)');
SELECT duckarrow_execute('INSERT INTO "test" VALUES (1, ''Alice'')');
SELECT duckarrow_execute('DROP TABLE "test"');

Security

  • SQL input validated for max length (1MB)
  • Null bytes rejected to prevent truncation attacks
  • Remote server errors prefixed for clarity

Test plan

  • Build succeeds (make build)
  • Unit tests pass (make test-unit)
  • Integration test with Flight SQL server
  • Verify DDL execution (CREATE/DROP TABLE)
  • Verify DML execution (INSERT/UPDATE/DELETE)

Enable executing non-query SQL statements (CREATE, DROP, INSERT, UPDATE,
DELETE) on the remote Flight SQL server. This addresses the limitation
that DuckDB's replacement scan only intercepts table references in SELECT
contexts, making DDL statements like "DROP TABLE duckarrow.X" fail.

Changes:
- Add Execute() method to flight.Client using ADBC's ExecuteUpdate()
- Add duckarrow_execute(sql) scalar function returning affected row count
- Register new function in extension initialization
- Update README with usage documentation

Usage:
  SELECT duckarrow_execute('DROP TABLE "my_table"');
  SELECT duckarrow_execute('CREATE TABLE test (id INTEGER)');

Security: SQL input validated for max length (1MB) and null bytes.
@JC1738 JC1738 merged commit 22acf0d into main Jan 21, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants