| От | Martijn van Oosterhout |
|---|---|
| Тема | Re: formatting the output of a function |
| Дата | |
| Msg-id | 20070606202018.GF8997@svana.org обсуждение |
| Ответ на | formatting the output of a function ("Islam Hegazy" <islheg@gawab.com>) |
| Список | pgsql-general |
On Wed, Jun 06, 2007 at 01:45:43PM -0600, Islam Hegazy wrote: > output[0] = (char*)palloc(sizeof(int)); //allocate space for a string that accepts an integer No it doesn't, it allocates space for an integer > output[1] = (char*)palloc(sizeof(double)); //allocate space for a string that accepts an integer This allocates space for a double. > > snprintf(output[0], sizeof(int), "%d", counter); > snprintf(output[1], sizeof(float), "%.5f", result); And here you're using sizeof(float) which is even smaller. Don't try to be smart with the sizes, just use 16 bytes for both and in the snprintf use 16 also, then everything will work fine. > HeapTuple data; > Datum finalResult; > data = BuildTupleFromCStrings(attinmeta, output); Although I think you're going the long way round, you can build a tuple from the integer wtihout making a string first... Have a nice day, -- Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/ > From each according to his ability. To each according to his ability to litigate.
В списке pgsql-general по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера