From: | Richard Huxton <dev(at)archonet(dot)com> |
---|---|
To: | Islam Hegazy <islheg(at)gawab(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: formatting the output of a function |
Date: | 2007-06-07 07:46:51 |
Message-ID: | 4667B7EB.7090409@archonet.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Islam Hegazy wrote:
> Hi all
>
> I created a function that returns a set of records. This function returns an integer and a float as the record fields. I have a problem in this function, it truncates the output. e.g. 1342 is displayed as 134, 456.46 is displayed as 456. In other words, it displays the first 3 digits only of a number, whether it is integer of float. I traced the function and the results are computed correctly. I use PostgreSQL 8.2.4. Following is a piece of my code.
> output[0] = (char*)palloc(sizeof(int)); //allocate space for a string that accepts an integer
> output[1] = (char*)palloc(sizeof(double)); //allocate space for a string that accepts an integer
I don't really do C any more, but I don't think these do what you want.
I think here you're allocating space for an integer/double, not for the
string representation of them (i.e. 4/8 bytes). I'm surprised you're not
just getting a crash.
> snprintf(output[0], sizeof(int), "%d", counter);
> snprintf(output[1], sizeof(float), "%.5f", result);
--
Richard Huxton
Archonet Ltd
From | Date | Subject | |
---|---|---|---|
Next Message | Alexander Staubo | 2007-06-07 07:55:39 | Re: [GENERAL] Looking for Graphical people for PostgreSQL tradeshow signage |
Previous Message | Michael Glaesemann | 2007-06-07 04:30:40 | Re: Numeric Sorting |