create a temp table in SPI

From: 黄宁 <huangning0722(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: create a temp table in SPI
Date: 2023-07-13 05:12:23
Message-ID: CAKgrFs_pVE1QJWbTPD=nNJuyC+Q0w+oc91kXwLPcKuo+f6L4vw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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();

Responses

Browse pgsql-general by date

  From Date Subject
Next Message KK CHN 2023-07-13 06:28:12 EDB to Postgres Migration
Previous Message Lorusso Domenico 2023-07-12 20:45:40 Re: How to add function schema in search_path in option definitio