Decimal values in

Started by Masterprojekt Naumann1almost 12 years ago3 messages
#1Masterprojekt Naumann1
mpws2013n1@gmail.com

Dear Dev-List,

inside execProcnode.c's ExecProcNode method we want to extract the value of
a tuple for a specific attribute. This works great for integers and
strings, but we are not able to figure out how to do this for floating
point numbers. Below is some example code snippet to show our problem:

TupleTableSlot *
ExecProcNode(PlanState *node) {
TupleTableSlot *result;
...
bool isNull;
Datum datum = slot_getattr(result,0, &isNull);

Form_pg_attribute *attrList = result->tts_tupleDescriptor->attrs;

if(attrList[0]->atttypid==INT4OID){
int value = (int) (datum);
...
} else if(attrList[0]->atttypid==VARCHAROID){
char* value = TextDatumGetCString(datum);
...
//this does not work :(
} else if(attrList[0]->atttypid==<DECIMAL_OID> /*what is the right
OID*/){
//the value does not seem to be stored in the datum
float value = (float) (datum);
...
}
...
}

How can we get those values?

Yours sincerely, Fabian Tschirschnitz.

#2Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Masterprojekt Naumann1 (#1)
Re: Decimal values in

Masterprojekt Naumann1 escribi�:

Dear Dev-List,

inside execProcnode.c's ExecProcNode method we want to extract the value of
a tuple for a specific attribute. This works great for integers and
strings, but we are not able to figure out how to do this for floating
point numbers. Below is some example code snippet to show our problem:

"DECIMAL_OID" (you probably mean NUMERICOID) points to datatype numeric,
which is not floating point but a variable length datatype with its own
special encoding for storage. If you want floating point you need
FLOAT4OID and FLOAT8OID, and columns created with types float and
"double precision", respectively.

--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Alvaro Herrera (#2)
Re: Decimal values in

Alvaro Herrera <alvherre@2ndquadrant.com> writes:

Masterprojekt Naumann1 escribi�:

inside execProcnode.c's ExecProcNode method we want to extract the value of
a tuple for a specific attribute. This works great for integers and
strings, but we are not able to figure out how to do this for floating
point numbers. Below is some example code snippet to show our problem:

"DECIMAL_OID" (you probably mean NUMERICOID) points to datatype numeric,
which is not floating point but a variable length datatype with its own
special encoding for storage. If you want floating point you need
FLOAT4OID and FLOAT8OID, and columns created with types float and
"double precision", respectively.

Also, you should not be using casts, but the appropriate DatumGetXXX
macro. In some cases those reduce to a cast, but your code ought not
assume that.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers