Re: Issue on C function that reads int2[] (using "int2vector") - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Issue on C function that reads int2[] (using "int2vector")
Date
Msg-id 15566.1448851148@sss.pgh.pa.us
Whole thread Raw
In response to Issue on C function that reads int2[] (using "int2vector")  (Rodrigo Hjort <rodrigo.hjort@gmail.com>)
Responses Re: Issue on C function that reads int2[] (using "int2vector")  (Rodrigo Hjort <rodrigo.hjort@gmail.com>)
List pgsql-hackers
Rodrigo Hjort <rodrigo.hjort@gmail.com> writes:
> I created a custom C function with this signature:

> CREATE FUNCTION calculate_hash(numbers int2[])
> RETURNS int8
> AS 'MODULE_PATHNAME', 'pg_calculate_hash'
> LANGUAGE C
> IMMUTABLE STRICT;

> And here is the function source code (inspired in codes I found in
> src/backend/utils/adt/int.c):

> PG_FUNCTION_INFO_V1(pg_calculate_hash);
> Datum
> pg_calculate_hash(PG_FUNCTION_ARGS)
> {
>   int2vector *int2Array = (int2vector *) PG_GETARG_POINTER(0);

Nope.  int2vector is not the same as int2[].  It might occasionally seem
to work, but in general it's not the same type.  And this particular
coding won't work at all on on-disk int2[] data, because it doesn't
account for toasting.
        regards, tom lane



pgsql-hackers by date:

Previous
From: Rodrigo Hjort
Date:
Subject: Issue on C function that reads int2[] (using "int2vector")
Next
From: David Fetter
Date:
Subject: Re: Using quicksort for every external sort run