Re: I think that my data is saved correctly, but when printing again, other data appears

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: I think that my data is saved correctly, but when printing again, other data appears
Дата
Msg-id 17316.1572011977@sss.pgh.pa.us
обсуждение исходный текст
Ответ на I think that my data is saved correctly, but when printing again,other data appears  (Yessica Brinkmann <yessica.brinkmann@gmail.com>)
Список pgsql-general
Yessica Brinkmann <yessica.brinkmann@gmail.com> writes:
> I have a function called get_columnnames, which runs on a Postgresql server
> and returns the names of the columns of a table in a Postgresql database.
> In the first foreach, in the statement: idxcd-> varattnames [cont] = data;
> column names are saved. Those column names are saved correctly. I could
> verify this by printing some values.
> But later, in the following foreach, when I reprint the values of the names
> of the columns that had been saved in the idxcd-> varattnames [cont] = data
> statement; They appear to me with errors.

Yeah, because the "data" value is just a pointer into the tupdesc
associated with the SPI result, and that disappears the moment you
do SPI_finish().  You'd need to do something to copy the strings
into a longer-lived context.  A plain pstrdup() won't suffice
because you're in a short-lived SPI context already inside that
loop; but you could save CurrentMemoryContext before starting up
SPI and then use MemoryContextStrdup.

            regards, tom lane



В списке pgsql-general по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Error building Postgres for Windows
Следующее
От: Alexander Farber
Дата:
Сообщение: Trying to fetch records only if preceded by at least another one