From 218527d01456b65decdc7596c6f6d5ac2bdeb78b Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 9 Sep 2024 12:18:32 -0400 Subject: Don't bother checking the result of SPI_connect[_ext] anymore. SPI_connect/SPI_connect_ext have not returned any value other than SPI_OK_CONNECT since commit 1833f1a1c in v10; any errors are thrown via ereport. (The most likely failure is out-of-memory, which has always been thrown that way, so callers had better be prepared for such errors.) This makes it somewhat pointless to check these functions' result, and some callers within our code haven't been bothering; indeed, the only usage example within spi.sgml doesn't bother. So it's likely that the omission has propagated into extensions too. Hence, let's standardize on not checking, and document the return value as historical, while not actually changing these functions' behavior. (The original proposal was to change their return type to "void", but that would needlessly break extensions that are conforming to the old practice.) This saves a small amount of boilerplate code in a lot of places. Stepan Neretin Discussion: https://postgr.es/m/CAMaYL5Z9Uk8cD9qGz9QaZ2UBJFOu7jFx5Mwbznz-1tBbPDQZow@mail.gmail.com --- doc/src/sgml/spi.sgml | 18 +++++++++--------- doc/src/sgml/trigger.sgml | 3 +-- 2 files changed, 10 insertions(+), 11 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/spi.sgml b/doc/src/sgml/spi.sgml index 7d154914b90..7e2f2df965d 100644 --- a/doc/src/sgml/spi.sgml +++ b/doc/src/sgml/spi.sgml @@ -126,16 +126,16 @@ int SPI_connect_ext(int options) - - - SPI_ERROR_CONNECT - - - on error - - - + + + The fact that these functions return int + not void is historical. All failure cases are reported + via ereport or elog. + (In versions before PostgreSQL v10, + some but not all failures would be reported with a result value + of SPI_ERROR_CONNECT.) + diff --git a/doc/src/sgml/trigger.sgml b/doc/src/sgml/trigger.sgml index 31626536a2e..49382d07fa8 100644 --- a/doc/src/sgml/trigger.sgml +++ b/doc/src/sgml/trigger.sgml @@ -915,8 +915,7 @@ trigf(PG_FUNCTION_ARGS) tupdesc = trigdata->tg_relation->rd_att; /* connect to SPI manager */ - if ((ret = SPI_connect()) < 0) - elog(ERROR, "trigf (fired %s): SPI_connect returned %d", when, ret); + SPI_connect(); /* get number of rows in table */ ret = SPI_exec("SELECT count(*) FROM ttest", 0); -- cgit v1.2.3