Thread: Request to clarify on sql_numeric datatype

Request to clarify on sql_numeric datatype

From
Raghavendra Reddy
Date:
Hi,
 
     I have a query on sql_numeric datatype Can you please clarify on this?
      While inserting numeric data type into a table can you please let me know how you are storing the value in the database.
        Whether it  is stored as double or character or directly storing it as structure.
   
     I am implementing the slq_numeric datatype feature for our database and I am stuck up how to store the value in the database.
     Can you please help out regarding this.
 
 Thanks in advance.
 
Thanks and Regards,
Raghavendra
 

Re: Request to clarify on sql_numeric datatype

From
Tom Lane
Date:
Raghavendra Reddy <raghavendrar@aztec.soft.net> writes:
>       While inserting numeric data type into a table can you please let me
> know how you are storing the value in the database.

From src/include/utils/numeric.h:

/** The Numeric data type stored in the database** NOTE: by convention, values in the packed form have been stripped
of*all leading and trailing zero digits (where a "digit" is of base NBASE).* In particular, if the value is zero, there
willbe no digits at all!* The weight is arbitrary in that case, but we normally set it to zero.*/
 
typedef struct NumericData
{   int32       varlen;         /* Variable size (std varlena header) */   int16       n_weight;       /* Weight of 1st
digit */   uint16      n_sign_dscale;  /* Sign + display scale */   char        n_data[1];      /* Digits (really array
ofNumericDigit) */
 
} NumericData;

See also the comments at the top of src/backend/utils/adt/numeric.c.
        regards, tom lane