Re: Issue on C function that reads int2[] (using "int2vector")

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Rodrigo Hjort <rodrigo(dot)hjort(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Issue on C function that reads int2[] (using "int2vector")
Date: 2015-11-30 02:39:08
Message-ID: 15566.1448851148@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Rodrigo Hjort <rodrigo(dot)hjort(at)gmail(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David Fetter 2015-11-30 04:02:59 Re: Using quicksort for every external sort run
Previous Message Rodrigo Hjort 2015-11-30 02:26:51 Issue on C function that reads int2[] (using "int2vector")