Re: help defining a basic type operator

Поиск
Список
Период
Сортировка
От Luca Ferrari
Тема Re: help defining a basic type operator
Дата
Msg-id CAKoxK+49nTLbUxiOBYF-KYT51Y9eFvQbv_w7kJP6LgfSZ3bQkg@mail.gmail.com
обсуждение исходный текст
Ответ на Re: help defining a basic type operator  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: help defining a basic type operator  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
On Mon, Aug 20, 2018 at 4:51 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> Luca Ferrari <fluca1978@gmail.com> writes:
> > I'm trying to define a custom data type that would represent a number
> > of bytes in a lossy human way.
>
> You did not show us the SQL definition of the type.  I don't see anything
> obviously wrong in what you showed (other than hfsize_add not setting the
> result's scaling), so the problem is somewhere else.  Given this C
> declaration, the type probably needs to be size 16, double alignment,
> pass-by-reference; maybe you messed up part of that?
>

Shame on me: when I issued a create type I didn't realize that I was
miswriting the length attribute from 'internallength' to
'internalsize', and while an error was reported, the type was created.
Fixing the type creation into:

CREATE TYPE hfsize (
       internallength = 16,
       input  = hfsize_input_function,
       output = hfsize_output_function
);

solved the problem, so it was a length mismatch.

> >   HFSize *sum    = new_HFSize();
>
> What is new_HFSize?

An helper function to allocate a new object (and that was why scaling
did not get referenced in the add function):


HFSize*
new_HFSize()
{
  HFSize *size = (HFSize*) palloc( sizeof( HFSize ) );
  size->scaling = 0;
  size->size = 0.0f;
  return size;
}


Thanks,
Luca


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

Предыдущее
От: Ravi Krishna
Дата:
Сообщение: Multiple COPY on the same table
Следующее
От: Tom Lane
Дата:
Сообщение: Re: help defining a basic type operator