| From: | Luca Ferrari <fluca1978(at)gmail(dot)com> | 
|---|---|
| To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> | 
| Cc: | pgsql-general <pgsql-general(at)postgresql(dot)org> | 
| Subject: | Re: help defining a basic type operator | 
| Date: | 2018-08-20 15:24:20 | 
| Message-ID: | CAKoxK+49nTLbUxiOBYF-KYT51Y9eFvQbv_w7kJP6LgfSZ3bQkg@mail.gmail.com | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-general | 
On Mon, Aug 20, 2018 at 4:51 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> Luca Ferrari <fluca1978(at)gmail(dot)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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2018-08-20 15:29:22 | Re: help defining a basic type operator | 
| Previous Message | Ravi Krishna | 2018-08-20 14:54:35 | Multiple COPY on the same table |