Thread: The return value of SPI_connect
Hi I found the function SPI_connect() has only one return value(SPI_OK_CONNECT). But I also found that some places check the return value of SPI_connect() like the following: if (SPI_connect() != SPI_OK_CONNECT) elog(ERROR, "SPI_connect failed"); Is it necessary to check the return value of SPI_connect() ? And in doc https://www.postgresql.org/docs/13/spi-spi-connect.html It also says SPI_connect() can return SPI_ERROR_CONNECT on error. May be we can make "int SPI_connect()" => "void SPI_connect()" and fix the doc ? Best regards, houzj
"Hou, Zhijie" <houzj.fnst@cn.fujitsu.com> writes: > May be we can make "int SPI_connect()" => "void SPI_connect()" and fix the doc ? I don't see a lot of value in changing SPI_connect() in isolation. It's part of an API suite that generally expects functions to return error codes. There was a previous thread [1] about getting rid of useless SPI error codes across the board, in favor of having those functions throw errors for error cases. AFAICT nobody has reviewed the proposed patch there, but maybe you'd like to? regards, tom lane [1] https://www.postgresql.org/message-id/flat/cc57ea5c-592a-6c27-aca6-7ad2a166c379%40gmail.com
> > May be we can make "int SPI_connect()" => "void SPI_connect()" and fix > the doc ? > > I don't see a lot of value in changing SPI_connect() in isolation. > It's part of an API suite that generally expects functions to return error > codes. > > There was a previous thread [1] about getting rid of useless SPI error codes > across the board, in favor of having those functions throw errors for error > cases. AFAICT nobody has reviewed the proposed patch there, but maybe you'd > like to? > > regards, tom lane > > [1] > https://www.postgresql.org/message-id/flat/cc57ea5c-592a-6c27-aca6-7ad > 2a166c379%40gmail.com > Thanks ! I will look into it. Best regards, houzj