what is the meaning of Datum?

Started by Luca Ferrarialmost 16 years ago6 messagesgeneral
Jump to latest
#1Luca Ferrari
fluca1978@infinito.it

Hi all,
ok this is a silly question, but I've got a doubt: what is the exact meaning
of Datum? I see having a look at the macroes (e.g., PG_RETURN_XXX) that a
Datum can be used as a pointer or as a single data, that is it can be a
reference or a value. Is this right? So for instance the fact that each stored
procedure returns a Datum means that the semantic of the Datum is interpreted
depending on how the procedure is defined in the SQL language (i.e., it returns
a integer, a tuple, ...). Am I right?

Moreover, is there a documentation (aside the source code) that explains and
links each internal data structure like HeapTuple, HeapTupleHeader, and so on?

Thanks,
Luca

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Luca Ferrari (#1)
Re: what is the meaning of Datum?

Luca Ferrari <fluca1978@infinito.it> writes:

ok this is a silly question, but I've got a doubt: what is the exact meaning
of Datum?

It's the backend-internal representation of a single value of any SQL
data type. The code using the Datum has to know which type it is,
since the Datum itself doesn't contain that information. Usually,
C code will work with a value in a "native" representation, and then
convert to or from Datum in order to pass the value through
data-type-independent interfaces.

regards, tom lane

#3Teodor Macicas
teodor.macicas@epfl.ch
In reply to: Tom Lane (#2)
Re: what is the meaning of Datum?

Tom Lane wrote:

Luca Ferrari <fluca1978@infinito.it> writes:

ok this is a silly question, but I've got a doubt: what is the exact meaning
of Datum?

It's the backend-internal representation of a single value of any SQL
data type. The code using the Datum has to know which type it is,
since the Datum itself doesn't contain that information. Usually,
C code will work with a value in a "native" representation, and then
convert to or from Datum in order to pass the value through
data-type-independent interfaces.

regards, tom lane

And how this convertions will be made ?
Are there internal functions to do this ?

Thanks.
-Tedy

#4Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Luca Ferrari (#1)
Re: what is the meaning of Datum?

Excerpts from Luca Ferrari's message of mié jun 23 06:09:28 -0400 2010:

Hi all,
ok this is a silly question, but I've got a doubt: what is the exact meaning
of Datum? I see having a look at the macroes (e.g., PG_RETURN_XXX) that a
Datum can be used as a pointer or as a single data, that is it can be a
reference or a value. Is this right?

Yes

So for instance the fact that each stored
procedure returns a Datum means that the semantic of the Datum is interpreted
depending on how the procedure is defined in the SQL language (i.e., it returns
a integer, a tuple, ...). Am I right?

Yes

Moreover, is there a documentation (aside the source code) that explains and
links each internal data structure like HeapTuple, HeapTupleHeader, and so on?

The source code comments should be plenty. Have you tried reading
those?

--
Álvaro Herrera <alvherre@commandprompt.com>
The PostgreSQL Company - Command Prompt, Inc.
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

#5Joshua D. Drake
jd@commandprompt.com
In reply to: Alvaro Herrera (#4)
Re: what is the meaning of Datum?

On Wed, 2010-06-23 at 12:15 -0400, Alvaro Herrera wrote:

Moreover, is there a documentation (aside the source code) that explains and
links each internal data structure like HeapTuple, HeapTupleHeader, and so on?

The source code comments should be plenty. Have you tried reading
those?

Here is a nice interface to the code:

http://doxygen.postgresql.org/

Sincerely,

Joshua D. Drake

--
PostgreSQL.org Major Contributor
Command Prompt, Inc: http://www.commandprompt.com/ - 509.416.6579
Consulting, Training, Support, Custom Development, Engineering

#6Tom Lane
tgl@sss.pgh.pa.us
In reply to: Teodor Macicas (#3)
Re: what is the meaning of Datum?

Teodor Macicas <teodor.macicas@epfl.ch> writes:

Tom Lane wrote:

C code will work with a value in a "native" representation, and then
convert to or from Datum in order to pass the value through
data-type-independent interfaces.

And how this convertions will be made ?
Are there internal functions to do this ?

Usually you should use the appropriate DatumGetXXX or XXXGetDatum
macro, or possibly the PG_GET_XXX or PG_RETURN_XXX wrappers for those.
Whether that's a simple cast or a function call is the macro's business.

regards, tom lane