Thread: doubt about datum

doubt about datum

From
Luca Ferrari
Date:
Hi all,
I'm new to postgresql programming and I'd like to understand what a datum is
(what is its purpose); I guess it is a kind of OID for customized data type
created by users, but I'm not sure. Moreover why it does not need transaction
visibility as an ordinary tuple (xmin, cmin, cmax, xmax)?

Thanks,
Luca

Re: doubt about datum

From
Tom Lane
Date:
Luca Ferrari <fluca1978@infinito.it> writes:
> I'm new to postgresql programming and I'd like to understand what a datum is

A value of any data type -- which particular type is not said by the
datum itself, but we always have context information to tell us that.

> Moreover why it does not need transaction
> visibility as an ordinary tuple (xmin, cmin, cmax, xmax)?

Datums are values.  '42'::int does not need visibility information;
its value is always the same.

            regards, tom lane

Re: doubt about datum

From
Luca Ferrari
Date:
On Tuesday 31 July 2007 your cat, walking on the keyboard, wrote:
> Luca Ferrari <fluca1978@infinito.it> writes:
> > I'm new to postgresql programming and I'd like to understand what a datum
> > is
>
> A value of any data type -- which particular type is not said by the
> datum itself, but we always have context information to tell us that.

Not sure to get this. With "any data type" you mean user defined types or also
internal data types? I guess the former. And what do you mean by "context"? I
noticed that Datum is used as return type in the function v1 convention, thus
I guess the context is related to the function itself, which return type is
know by the SQL side. Is this what you mean?


>
> > Moreover why it does not need transaction
> > visibility as an ordinary tuple (xmin, cmin, cmax, xmax)?
>
> Datums are values.  '42'::int does not need visibility information;
> its value is always the same.


Even more confused here! In the case of function returns values I agree that
there is no needing for transaction information, since the value should be
evaluated on the fly, right? Maybe what I'm not getting is about a tuple that
includes both internal values and a datum: is that possibile? Because in this
case how is the tuple header handled (since datum header should overlap the
transaction header xmin,xmax...). Sorry if my question is too trivial.

Thanks,
Luca


Re: doubt about datum

From
Luca Ferrari
Date:
On Tuesday 31 July 2007 Tom Lane's cat, walking on the keyboard, wrote:
> > Moreover why it does not need transaction
> > visibility as an ordinary tuple (xmin, cmin, cmax, xmax)?
>
> Datums are values.  '42'::int does not need visibility information;
> its value is always the same.

Maybe I understand something more, but I'm still in doubt about the tuple
header. In the htup.h file you find:

typedef struct HeapTupleHeaderData
{
    union
    {
        HeapTupleFields t_heap;
        DatumTupleFields t_datum;
    }            t_choice;
        ....
}

maybe I cannot get the meaning of the above t_datum in the tuple header, can
anyone explain me that?

Thanks,
Luca

Re: doubt about datum

From
Tom Lane
Date:
Luca Ferrari <fluca1978@infinito.it> writes:
> header. In the htup.h file you find:

> typedef struct HeapTupleHeaderData
> {
>     union
>     {
>         HeapTupleFields t_heap;
>         DatumTupleFields t_datum;
>     }            t_choice;
>         ....
> }

> maybe I cannot get the meaning of the above t_datum in the tuple header, can
> anyone explain me that?

The t_datum fields are for use in an in-memory tuple that represents a
value of a composite type.  Being a Datum, it needs a length word and
some other stuff that are not needed in a row-on-disk; and it does not
need visibility info, which is what the t_heap fields are.

            regards, tom lane