Thank you so much for your answer. I will be testing the indicated and then I give you return.<br>Best regards,<br><br>Yessica Brinkmann<br><div class="quote" style="line-height: 1.5"><br><br>-------- Mensaje original --------<br>Asunto: Re: I think that my data is saved correctly, but when printing again, other data appears<br>De: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us><br>Para: Yessica Brinkmann <yessica(dot)brinkmann(at)gmail(dot)com><br>CC: pgsql-general(at)lists(dot)postgresql(dot)org<br><br><br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Yessica Brinkmann <yessica(dot)brinkmann(at)gmail(dot)com> writes:<br>> I have a function called get_columnnames, which runs on a Postgresql server<br>> and returns the names of the columns of a table in a Postgresql database.<br>> In the first foreach, in the statement: idxcd-> varattnames [cont] = data;<br>> column names are saved. Those column names are saved correctly. I could<br>> verify this by printing some values.<br>> But later, in the following foreach, when I reprint the values of the names<br>> of the columns that had been saved in the idxcd-> varattnames [cont] = data<br>> statement; They appear to me with errors.<br><br>Yeah, because the "data" value is just a pointer into the tupdesc<br>associated with the SPI result, and that disappears the moment you<br>do SPI_finish(). You'd need to do something to copy the strings<br>into a longer-lived context. A plain pstrdup() won't suffice<br>because you're in a short-lived SPI context already inside that<br>loop; but you could save CurrentMemoryContext before starting up<br>SPI and then use MemoryContextStrdup.<br><br> regards, tom lane<br></blockquote></div>