Re: Is a syscache tuple more like an on-disk tuple or a freshly made one? - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Is a syscache tuple more like an on-disk tuple or a freshly made one?
Date
Msg-id 526.1460758381@sss.pgh.pa.us
Whole thread Raw
In response to Is a syscache tuple more like an on-disk tuple or a freshly made one?  (Chapman Flack <chap@anastigmatix.net>)
List pgsql-hackers
Chapman Flack <chap@anastigmatix.net> writes:
> I am tempted to apply HeapTupleGetDatum to a tuple retrieved from
> the syscache (as I already have code for processing a tuple presented
> as a Datum).

> But I see a comment on HeapTupleHeaderGetDatum: "This must *not* get
> applied to an on-disk tuple; the tuple should be freshly made by
> heap_form_tuple or some wrapper ..."

> ... and here I confess I'm unsure whether a tuple retrieved from
> the syscache is more like an on-disk one, or a freshly-made one,
> for purposes of the warning in that comment.

A tuple from syscache is an on-disk tuple for this purpose; it has
the original catalog row's header fields, not the header fields
appropriate for a Datum.  So no, that will *not* work, even disregarding
the question of whether it'd be safe to pass a pointer into syscache
to some random function.

> Is there a conventional proper way to pass a tuple retrieved from
> syscache to code that accepts a tuple as a Datum?

You could use heap_copy_tuple_as_datum().  See SPI_returntuple()
for an example.
        regards, tom lane



pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: Is a syscache tuple more like an on-disk tuple or a freshly made one?
Next
From: Chapman Flack
Date:
Subject: Re: Is a syscache tuple more like an on-disk tuple or a freshly made one?