25.2. Running an Arbitrary Command in DuckDB (duckdb.raw_query) #
The duckdb.raw_query stored procedure can execute any command, not just SELECT. Unlike the duckdb.query stored procedure, duckdb.raw_query does not return the result as rows. The result is sent to the server logs. It is recommended to use the duckdb.query stored procedure when possible.
Required privileges: All roles.
Execute the following command on the Postgres Pro AXE server:
SELECT duckdb.raw_query('command') ON CONFLICT DO NOTHING;
Where command is the command that must be executed.
Postgres Pro AXE executes the specified command directly against DuckDB.
Example 25.2. Executing the duckdb.raw_query Stored Procedure
Creating a table in DuckDB:
SELECT duckdb.raw_query('CREATE TABLE employees (id INTEGER, name VARCHAR, salary DECIMAL)') ON CONFLICT DO NOTHING;
Inserting rows into the table:
SELECT duckdb.raw_query('INSERT INTO employees VALUES (1, ''Alice'', 50000), (2, ''Bob'', 60000)') ON CONFLICT DO NOTHING;
Updating a row in the table:
SELECT duckdb.raw_query('UPDATE employees SET salary = 55000 WHERE id = 1') ON CONFLICT DO NOTHING;
Deleting a row from the table:
SELECT duckdb.raw_query('DELETE FROM employees WHERE id = 2') ON CONFLICT DO NOTHING;
Dropping the table:
SELECT duckdb.raw_query('DROP TABLE employees') ON CONFLICT DO NOTHING;