formatting the output of a function

Поиск
Список
Период
Сортировка
От Islam Hegazy
Тема formatting the output of a function
Дата
Msg-id 02b201c7a875$067b6aa0$0d0e9f88@pc.cpsc.ucalgary.ca
обсуждение исходный текст
Ответы Re: formatting the output of a function  (Martijn van Oosterhout <kleptog@svana.org>)
Re: formatting the output of a function  (Richard Huxton <dev@archonet.com>)
Список pgsql-general
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.
 

int counter;

float  result;

//some code

char **output;

output = (char**)palloc(2*sizeof(char*)); //allocate space for two string pointer

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

snprintf(output[0], sizeof(int), "%d", counter);

snprintf(output[1], sizeof(float), "%.5f", result);

HeapTuple data;

Datum finalResult;

data = BuildTupleFromCStrings(attinmeta, output);

finalResult = HeapTupleGetDatum(data);

SRF_RETURN_NEXT(funcctx, finalResult);

---------------

Any idea what could be the cause of this error?

Regards

Islam Hegazy

В списке pgsql-general по дате отправления:

Предыдущее
От: David Gardner
Дата:
Сообщение: Re: pl/pgsql debuging, was Re: debugging C functions
Следующее
От: Martijn van Oosterhout
Дата:
Сообщение: Re: formatting the output of a function