Skip to content

Commit

Permalink
Make duckdb.install_extension a no-op when the extension is already i…
Browse files Browse the repository at this point in the history
…nstalled
  • Loading branch information
JelteF committed Oct 23, 2024
1 parent 03f7208 commit f917ef4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/pgduckdb_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ DuckdbInstallExtension(Datum name_datum) {
auto ret = SPI_execute_with_args(R"(
INSERT INTO duckdb.extensions (name, enabled)
VALUES ($1, true)
ON CONFLICT (name) DO UPDATE SET enabled = true
)",
lengthof(arg_types), arg_types, values, NULL, false, 0);
if (ret != SPI_OK_INSERT)
Expand Down
37 changes: 34 additions & 3 deletions test/regression/expected/extensions.out
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,38 @@ SELECT duckdb.install_extension('icu');
SELECT last_value FROM duckdb.extensions_table_seq;
last_value
------------
2
3
(1 row)

SELECT * FROM duckdb.raw_query($$ SELECT extension_name, loaded, installed FROM duckdb_extensions() WHERE loaded and extension_name != 'jemalloc' $$);
NOTICE: result: extension_name loaded installed
VARCHAR BOOLEAN BOOLEAN
[ Rows: 5]
cached_httpfs true true
icu true true
json true true
parquet true true
pgduckdb true false


raw_query
-----------

(1 row)

-- Check that we can rerun this without issues
SELECT duckdb.install_extension('icu');
install_extension
-------------------
t
(1 row)

-- Increases the sequence twice because we use ON CONFLICT DO UPDATE. So
-- the trigger fires for both INSERT and UPDATE internally.
SELECT last_value FROM duckdb.extensions_table_seq;
last_value
------------
5
(1 row)

SELECT * FROM duckdb.raw_query($$ SELECT extension_name, loaded, installed FROM duckdb_extensions() WHERE loaded and extension_name != 'jemalloc' $$);
Expand Down Expand Up @@ -60,7 +91,7 @@ SELECT duckdb.install_extension('aws');
SELECT last_value FROM duckdb.extensions_table_seq;
last_value
------------
3
7
(1 row)

SELECT * FROM duckdb.raw_query($$ SELECT extension_name, loaded, installed FROM duckdb_extensions() WHERE loaded and extension_name != 'jemalloc' $$);
Expand All @@ -86,7 +117,7 @@ DELETE FROM duckdb.extensions WHERE name = 'aws';
SELECT last_value FROM duckdb.extensions_table_seq;
last_value
------------
4
8
(1 row)

SELECT * FROM duckdb.raw_query($$ SELECT extension_name, loaded, installed FROM duckdb_extensions() WHERE loaded and extension_name != 'jemalloc' $$);
Expand Down
10 changes: 10 additions & 0 deletions test/regression/sql/extensions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ SELECT last_value FROM duckdb.extensions_table_seq;

SELECT * FROM duckdb.raw_query($$ SELECT extension_name, loaded, installed FROM duckdb_extensions() WHERE loaded and extension_name != 'jemalloc' $$);

-- Check that we can rerun this without issues
SELECT duckdb.install_extension('icu');

-- Increases the sequence twice because we use ON CONFLICT DO UPDATE. So
-- the trigger fires for both INSERT and UPDATE internally.
SELECT last_value FROM duckdb.extensions_table_seq;

SELECT * FROM duckdb.raw_query($$ SELECT extension_name, loaded, installed FROM duckdb_extensions() WHERE loaded and extension_name != 'jemalloc' $$);


SELECT duckdb.install_extension('aws');

SELECT last_value FROM duckdb.extensions_table_seq;
Expand Down

0 comments on commit f917ef4

Please sign in to comment.