Rules for accessing tuple data in backend code

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>
Subject: Rules for accessing tuple data in backend code
Date: 2002-01-28 21:51:30
Message-ID: Pine.LNX.4.30.0201281638310.688-100000@peter.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I'm sort of confused about the ways in which you can access tuple data you
get from heap scans or syscache lookups. Perhaps this can be cleared up
and documented, because new contributors might like this information.
Here's the information and questions I have:

Tuples obtained from heap scans (heap_getnext, etc.) can always be
dissected with heap_getattr().

Tuples obtained from syscache lookups (SearchSysCache) can always be
dissected with SysCacheGetAttr().

What happens when I try heap_getattr() on a syscache tuple?

Tuples obtained from heap scans or syscache lookups may be dissected via
GETSTRUCT if and only if the attribute and all attributes prior to it are
fixed-length and non-nullable.

(Probably there should be cases about explicit index scans here, but I
haven't done those and they should be rare.)

The question I'm particularly struggling with is, when does TOASTing and
de-TOASTing happen? And if it doesn't, what's the official way to do it?
I've found PG_DETOAST_DATUM and PG_DETOAST_DATUM_COPY. Why would I want a
copy? (How can detoasting happen without copying?) And if I want a copy,
in what memory context does it live? And can I just pfree() the copy if I
don't want it any longer?

--
Peter Eisentraut peter_e(at)gmx(dot)net

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message John Gray 2002-01-28 22:53:48 Re: Rules for accessing tuple data in backend code
Previous Message Peter Eisentraut 2002-01-28 21:18:10 Per-database and per-user GUC settings