Re: Understanding Datum

From: rsmogura <rsmogura(at)softperience(dot)eu>
To: Nick Raj <nickrajjain(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Radosław Smogura <mail(at)smogura(dot)eu>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: Understanding Datum
Date: 2011-03-24 09:13:44
Message-ID: e4f370d4495d809dda357c95621c444c@mail.softperience.eu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, 24 Mar 2011 10:50:32 +0530, Nick Raj wrote:
> If Datum contains only the value (not having type specific info.),
> then
> Suppose i want to print the Datum V value (already defined in
> postgres)
> then printf("%??", V);
>
> Because V is assigned by PG_GETARG_POINTER(1);
> I dont having the information of type Datum.
>
> How to print the value of Datum in postgres?
>
> On Thu, Mar 24, 2011 at 2:35 AM, Tom Lane wrote:
>
>> Nick Raj writes:
>> > In postgres, typedef uintptr_t Datum
>> > Datum is getting value from PG_GETARG_POINTER(1);
>> > But, now problem is how would i know the type of
>> PG_GETARG_POINTER(1)
>> > (postgres internally pass this argument) to figure out datum
>> type?
>>
>> Datum does not carry any type information, only a value.
>>  Functions are
>> typically coded to know their input types a priori.  If you want
>> to
>> write code that is not type-specific then youd better be passing
>> around
>> type OIDs as well as values.
>>
>>                        regards, tom lane
>>
>> --
>> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org
>> [2])
>> To make changes to your subscription:
>> http://www.postgresql.org/mailpref/pgsql-general [3]
>
>
>
> Links:
> ------
> [1] mailto:nickrajjain(at)gmail(dot)com
> [2] mailto:pgsql-general(at)postgresql(dot)org
> [3] http://www.postgresql.org/mailpref/pgsql-general
> [4] mailto:tgl(at)sss(dot)pgh(dot)pa(dot)us

You may only find this from code context. Bear in mind, in simple
words, datum is like void* with additional size header.

If You write C function you now what kind of datum will income, and
what should outcome (You declare this!). If you examine table, it's same
situation, but You need ask system for this. Even if PG will have type
bytes in Datum, PG supports custom types...

If you wan't to operate on datums You can't work in a way take some
datum and work on it.

You need to obtain /context/, by getting what type tables has on column
x, what type of results function will return, etc; You need to know from
where Your datum income.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Erik Hesselink 2011-03-24 09:17:27 Deadlock in libpq
Previous Message Zheng Yang 2011-03-24 08:49:19 Re: foreign data wrappers