Thank you so much for the answers. By telling me this: "MemoryContextStrdup enables you to create a copy of a string in an explicitly specified memory context." I better understood the function of MemoryContextStrdup. And thank you very much to Mr. Jony Cohen for giving me the reference of his work. I really was already researching about his work, and I included it in the state of the art of my thesis, but I didn't look at the source code. I will be looking at the source code for a help, and especially in this case to see for the moment, the maintenance of the context for its subsequent restoration. Regards, Yessica Brinkmann
El dom., 27 oct. 2019 a las 19:42, Jony Cohen (<jony.cohe...@gmail.com>) escribió: > Hi, > Worked on something similar a few years back, have a look - it might give > you a few pointers :) > It's on similar lines to what you are looking at (I kept it updated up to > PG version 9.4/9.5) > https://github.com/cohenjo/pg_idx_advisor > > My main focus was to add support for more index types: partial, > functional, CTE, composites etc... > (I also had to keep the original context to restore it - so I think you > will find a sample to what you are looking for... ) > > there's also https://github.com/HypoPG/hypopg which is > actively maintained. > I think you will find code samples even up to the latest versions here... > > Regards, > - Jony > > On Sat, Oct 26, 2019 at 4:06 AM Yessica Brinkmann < > yessica.brinkm...@gmail.com> wrote: > >> 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.brinkm...@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 >>> >>>