create a temp table in SPI - Mailing list pgsql-general

From 黄宁
Subject create a temp table in SPI
Date
Msg-id CAKgrFs_pVE1QJWbTPD=nNJuyC+Q0w+oc91kXwLPcKuo+f6L4vw@mail.gmail.com
Whole thread Raw
Responses Re: create a temp table in SPI
List 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();

pgsql-general by date:

Previous
From: Lorusso Domenico
Date:
Subject: Re: How to add function schema in search_path in option definitio
Next
From: KK CHN
Date:
Subject: EDB to Postgres Migration