pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Yessica Brinkmann <yessica.brinkmann@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: I think that my data is saved correctly, but when printing again, other data appears
Date: Fri, 25 Oct 2019 09:59:37 -0400
Message-ID: <17316.1572011977@sss.pgh.pa.us> (raw)
In-Reply-To: <CABrYqSOSaFoM+FWNhajxpygVLWZECLt4nvtAwz7a_gunDgfgzQ@mail.gmail.com>
References: <CABrYqSOSaFoM+FWNhajxpygVLWZECLt4nvtAwz7a_gunDgfgzQ@mail.gmail.com>

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





view thread (13+ messages)  latest in thread

Message-ID: <17316.1572011977@sss.pgh.pa.us>
Permalink:  ../17316.1572011977@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/17316.1572011977@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, yessica.brinkmann@gmail.com
  Subject: Re: I think that my data is saved correctly, but when printing again, other data appears
  In-Reply-To: <17316.1572011977@sss.pgh.pa.us>
  References: <CABrYqSOSaFoM+FWNhajxpygVLWZECLt4nvtAwz7a_gunDgfgzQ@mail.gmail.com> <17316.1572011977@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox