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

Поиск
Список
Период
Сортировка
От Yessica Brinkmann
Тема Re: I think that my data is saved correctly, but when printing again,other data appears
Дата
Msg-id CABrYqSPtHf3b9+J0UJWTakYEp64nj7UwzJP+1qa6q14yP6biUw@mail.gmail.com
обсуждение исходный текст
Ответ на Re: I think that my data is saved correctly, but when printing again,other data appears  (Yessica Brinkmann <yessica.brinkmann@gmail.com>)
Список pgsql-general
Or if you know any link to a website where to find an example of this, I will thank you very much, please.
Best regards,
Yessica Brinkmann

El vie., 25 oct. 2019 a las 22:06, Yessica Brinkmann (<yessica.brinkmann@gmail.com>) escribió:
Good evening, sorry for the delay in answering. I have a part-time job and I was at it.
I understand what you tell me about the "data" value is just a pointer into the tupdesc associated with the SPI result, and that disappears the moment I do SPI_finish ().
What I do not understand well is how to use CurrentMemoryContext and MemoryContextStrdup, since there are not many examples of using them on the Internet (most are only definitions) and it is the first time I have heard of this, although I already understand this part now of contexts, because I was reading on the subject.
Could you please give me an example of use?
Best Regards,
Yessica Brinkmann

El vie., 25 oct. 2019 a las 12:24, Yessica Brinkmann (<yessica.brinkmann@gmail.com>) escribió:
Thank you so much for your answer. I will be testing the indicated and then I give you return.
Best regards,

Yessica Brinkmann


-------- Mensaje original --------
Asunto: Re: I think that my data is saved correctly, but when printing again, other data appears
De: Tom Lane
Para: Yessica Brinkmann
CC: pgsql-general@lists.postgresql.org


Yessica Brinkmann 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 по дате отправления:

Предыдущее
От: Adrian Klaver
Дата:
Сообщение: Re: Updating data: confirmation and question
Следующее
От: Rich Shepard
Дата:
Сообщение: Re: Updating data: confirmation and question