Lists: | Postg와이즈 토토SQL |
---|
From: | Nick Raj <nickrajjain(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Understanding Datum |
Date: | 2011-03-23 17:45:41 |
Message-ID: | AANLkTi=p77ca7VDZOhTKBxi8nvXZnVxOUwC27F8xCaSF@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
Hi,
I am understanding the postgres code. In code, i just want to see what are
values that are passing through the variables?
Can you please tell me if the variable is of type Datum, then how to print
its value? Because i dont the variable v type.
And also what the structure of Datum?
Thanks,
Raj
From: | Radosław Smogura <mail(at)smogura(dot)eu> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Cc: | Nick Raj <nickrajjain(at)gmail(dot)com> |
Subject: | Re: Understanding Datum |
Date: | 2011-03-23 18:10:31 |
Message-ID: | 201103231910.32027.mail@smogura.eu |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
Nick Raj <nickrajjain(at)gmail(dot)com> Wednesday 23 March 2011 18:45:41
> Hi,
> I am understanding the postgres code. In code, i just want to see what are
> values that are passing through the variables?
> Can you please tell me if the variable is of type Datum, then how to print
> its value? Because i dont the variable v type.
>
> And also what the structure of Datum?
>
> Thanks,
> Raj
The structure is explained in one of headers, generally Datum is pointer. It
points to memory containing at first four bytes integer describing size of
data in datum (use macro to extract this), and then, it's followed by bytes
containing data.
Actually almost each object is represented by structure like this
struct something {
int4 size; //Required
// Here put what you want
}
see headers.
If you want to present data from datum you need to 1) check what type of data
datum has (datum doesn't contain this) 2) Find datum representation for this
type.
Regards,
Radek
From: | Nick Raj <nickrajjain(at)gmail(dot)com> |
---|---|
To: | Radosław Smogura <mail(at)smogura(dot)eu> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Understanding Datum |
Date: | 2011-03-23 20:19:54 |
Message-ID: | AANLkTimiy2CmGuWUAuvRToi6uOMo=kiqAbP9yUMXcjLS@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
Hi,
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?
Can you tell detailed structure of Datum, so i can print the value?? How to
find out what type of pointer argument is PG_GETARG_POINTER(1)??
Thanks,
Nirmesh
On Wed, Mar 23, 2011 at 11:40 PM, Radosław Smogura <mail(at)smogura(dot)eu> wrote:
> Nick Raj <nickrajjain(at)gmail(dot)com> Wednesday 23 March 2011 18:45:41
> > Hi,
> > I am understanding the postgres code. In code, i just want to see what
> are
> > values that are passing through the variables?
> > Can you please tell me if the variable is of type Datum, then how to
> print
> > its value? Because i dont the variable v type.
> >
> > And also what the structure of Datum?
> >
> > Thanks,
> > Raj
>
> The structure is explained in one of headers, generally Datum is pointer.
> It
> points to memory containing at first four bytes integer describing size of
> data in datum (use macro to extract this), and then, it's followed by bytes
> containing data.
>
> Actually almost each object is represented by structure like this
> struct something {
> int4 size; //Required
> // Here put what you want
> }
> see headers.
>
> If you want to present data from datum you need to 1) check what type of
> data
> datum has (datum doesn't contain this) 2) Find datum representation for
> this
> type.
>
> Regards,
> Radek
>
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Nick Raj <nickrajjain(at)gmail(dot)com> |
Cc: | Radosław Smogura <mail(at)smogura(dot)eu>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: Understanding Datum |
Date: | 2011-03-23 21:05:42 |
Message-ID: | 4479.1300914342@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
Nick Raj <nickrajjain(at)gmail(dot)com> 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 you'd better be passing around
type OIDs as well as values.
regards, tom lane
From: | Nick Raj <nickrajjain(at)gmail(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Radosław Smogura <mail(at)smogura(dot)eu>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: Understanding Datum |
Date: | 2011-03-24 05:20:32 |
Message-ID: | AANLkTinTBMnBP7Owy=ZBB8aQo+TBSS+YOtjCus6pmP4y@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | Postg와이즈 토토SQL |
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 don't 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 <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Nick Raj <nickrajjain(at)gmail(dot)com> 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 you'd 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)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>
From: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> |
---|---|
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 06:39:39 |
Message-ID: | AANLkTinSu9dhmEhHpdv_0hBWe30Q2vPSEvfpY-O1tybj@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
2011/3/24 Nick Raj <nickrajjain(at)gmail(dot)com>:
> 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 don't having the information of type Datum.
>
> How to print the value of Datum in postgres?
you have to find a adequate out function and you have to call it. A
out functions transform a binary Datum value to CString value.
#include "executor/spi.h" /* this is what you need to
work with SPI */
#include "utils/lsyscache.h"
PG_MODULE_MAGIC;
extern Datum quote_literal(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(quote_literal);
Datum
quote_literal(PG_FUNCTION_ARGS)
{
text *result;
Oid valtype = get_fn_expr_argtype(fcinfo->flinfo, 0);
Datum value = PG_GETARG_DATUM(0);
Oid typoutput;
bool typIsVarlena;
StringInfoData buf;
if (!OidIsValid(valtype))
elog(ERROR, "could not determine data type of input");
initStringInfo(&buf);
appendStringInfoChar(&buf, '\'');
getTypeOutputInfo(valtype, &typoutput, &typIsVarlena);
appendStringInfoString(&buf, OidOutputFunctionCall(typoutput, value));
appendStringInfoChar(&buf, '\'');
result = DatumGetTextP(DirectFunctionCall1(textin,
CStringGetDatum(buf.data)));
PG_RETURN_TEXT_P(result);
}
CREATE OR REPLACE FUNCTION quote_literal(anyelement)
RETURNS text
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT;
CREATE OR REPLACE FUNCTION quote_literal(text)
RETURNS text
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT;
Regards
Pavel Stehule
p.s. this is simple variant of this function. For production usage is
using cache necessary.
>
>
> On Thu, Mar 24, 2011 at 2:35 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>>
>> Nick Raj <nickrajjain(at)gmail(dot)com> 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 you'd 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)
>> To make changes to your subscription:
>> http://www.postgresql.org/mailpref/pgsql-general
>
>
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 |
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.