Re: PG_RETURN_?

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Don Y <pgsql(at)DakotaCom(dot)Net>
Cc: Richard Huxton <dev(at)archonet(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: PG_RETURN_?
Date: 2006-05-02 16:12:14
Message-ID: 20060502161214.GA13702@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, May 02, 2006 at 08:43:03AM -0700, Don Y wrote:
> Richard Huxton wrote:
> >Don Y wrote:
> >>Hi,
> >>
> >>I have a set of functions for a data type that return
> >>small integers (i.e. [0..12]). I can, of course, represent
> >>it as a char, short or long (CHAR, INT16 or INT32).
> >>re there any advantages/drawbacks to chosing one particular
> >>PG_RETURN_ type over another (realizing that they are
> >>effectively just casts)?
> >
> >If they are integers then an int would be the obvious choice. If you are
> >going to treat them as int2 outside the function then int2, otherwise
> >just integer.
>
> Yes, I was more interested in what might be going on "behind the
> scenes" inside the server that could bias my choice of WHICH
> integer type to use. E.g., if arguments are marshalled as
> byte arrays vs. as Datum arrays, etc. (I would suspect the
> latter). Since I could use something as small as a char to
> represent the values, the choice is more interested in how
> OTHER things would be affected...

You should always *always* match the PG_RETURN_* to the declared type
you are returning. anything else will cause problems. PG_RETURN_INT16
means "return in a format consistant with a type declared as
pass-by-value two byte width". PostgreSQL does not check that what
you're returning actually matches what you declared.

The type as declared determines the storage required to store it. That
might be a far more useful factor to consider than what it copied
internally which, as has been pointed out, is probably below what you
can measure.

Have a nice day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ottavio Campana 2006-05-02 16:27:41 libpq for palm?
Previous Message Richard Huxton 2006-05-02 15:51:34 Re: PG_RETURN_?