I want to create some temporary tables in SPI, but after I created the table and inserted the data, I can’t query any data, why?
the postgres version: PostgreSQL 13.6 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 7.3.0, 64-bit code: int ret = 0; SPI_connect(); ret = SPI_execute("CREATE GLOBAL TEMP TABLE temp_table (id int, value text)", false, 0); if(ret != SPI_OK_UTILITY) { elog(ERROR, "%s: create failed", __FUNCTION__); } ret = SPI_execute("INSERT INTO temp_table VALUES (1, 'a'), (2, 'b')", false, 0); if(ret != SPI_OK_INSERT) { elog(ERROR, "%s: insert failed", __FUNCTION__); } // SPI_commit(); ret = SPI_execute("SELECT * FROM temp_table", true, 0); if(ret != SPI_OK_SELECT) { elog(ERROR, "%s: select failed", __FUNCTION__); } if(SPI_processed > 0) { } else { // elog(ERROR, "%s: find nothing", __FUNCTION__); } // SPITupleTable *tuptable = SPI_tuptable; // TupleDesc tupdesc = tuptable->tupdesc; // // the numvals is 0,but I insert two records // if (tuptable->numvals > 0) // { // HeapTuple tuple = tuptable->vals[0]; // char *tupleval1 = SPI_getvalue(tuple, tupdesc, 1); // char *tupleval2 = SPI_getvalue(tuple, tupdesc, 2); // pfree(tupleval1); // pfree(tupleval2); // } // else // { // elog(ERROR, "%s: can not query something", __FUNCTION__); // } // do something with tuptable SPI_finish();