> I'd give it decent odds since our example usage doesn't include the test.
> https://www.postgresql.org/docs/current/spi-examples.html

https://www.postgresql.org/docs/devel/trigger-example.html
<https://www.postgresql.org/docs/current/spi-examples.html>

> /* connect to SPI manager */

>    if ((ret = SPI_connect()) < 0)
>        elog(ERROR, "trigf (fired %s): SPI_connect returned %d", when, ret);


in this page check include in the example.
I think we need to give examples of one kind. If there is no void in
the code, then there should be checks everywhere (at least in the
documentation).

 What do you think about the attached patch?

Best Regards, Stepan Neretin.
From 4c8d6d9ae6f8843bc6d1ad203d629df09657b039 Mon Sep 17 00:00:00 2001
From: Stepan Neretin <sndc...@gmail.com>
Date: Sat, 10 Aug 2024 21:30:37 +0300
Subject: [PATCH v1] Fix SPI Documentation - Standardized the example in the
 execq function to ensure consistent error handling. Now, the error from
 SPI_connect() is checked and reported uniformly. - Removed the
 SPI_ERROR_CONNECT return entry, reflecting that there is now only one return
 value for SPI_connect_ext.

---
 doc/src/sgml/spi.sgml | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/doc/src/sgml/spi.sgml b/doc/src/sgml/spi.sgml
index 7d154914b9..fdd31c3fdf 100644
--- a/doc/src/sgml/spi.sgml
+++ b/doc/src/sgml/spi.sgml
@@ -126,16 +126,10 @@ int SPI_connect_ext(int <parameter>options</parameter>)
      </para>
     </listitem>
    </varlistentry>
-
-   <varlistentry>
-    <term><symbol>SPI_ERROR_CONNECT</symbol></term>
-    <listitem>
-     <para>
-      on error
-     </para>
-    </listitem>
-   </varlistentry>
   </variablelist>
+  <para>
+    All failure cases are reported via <literal>elog/ereport</literal>.
+  </para>
  </refsect1>
 </refentry>
 
@@ -5281,7 +5275,8 @@ execq(PG_FUNCTION_ARGS)
     command = text_to_cstring(PG_GETARG_TEXT_PP(0));
     cnt = PG_GETARG_INT32(1);
 
-    SPI_connect();
+    if ((ret = SPI_connect()) < 0)
+        elog(ERROR, "SPI_connect returned %d");
 
     ret = SPI_exec(command, cnt);
 
-- 
2.43.0

Reply via email to