Re: SQL names for C constants

From: "Merlin Moncure" <mmoncure(at)gmail(dot)com>
To: Vegard Bønes <vegard(dot)bones(at)met(dot)no>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: SQL names for C constants
Date: 2007-02-28 17:53:25
Message-ID: b42b73150702280953t39aa580bra2c5592d611f4e1d@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2/27/07, Vegard Bønes <vegard(dot)bones(at)met(dot)no> wrote:
> Hi!
>
> I am writing a serverside function in plpgsql, which returns a part of a
> large object.
>
> To solve this problem I can do something like this:
>
> fd := lo_open( some_oid, 262144 );
> PERFORM lo_lseek( fd, index, 0 );
> RETURN loread( fd, read_size );
>
> This works well enough, but I do feel slightly uneasy about using
> numbers instead of symbolic names (262144 for INV_READ and 0 for
> SEEK_SET). I do especially find SEEK_SET unsettling, since this constant
> is defined outside of postgresql, and it may therefore be defined to
> other values than 0 on other platforms.
>
> Am I missing something here? Is there a way to specify these names
> without writing the actual numbers, or should I just close my eyes and
> hope that everything will work?

You can make a preprocessor file for your sql stuff and pre-process
all your sql using classic C defines for your constants. with little
work you can even share headers with your applications. Major
downside to this approach is you cannot copy/paste your function
bodies (or any sql using macros) into psql/pgadmin, etc.

You can use psql variables for similar things but unfortunately not
inside functions bodies because they are strings :(. Ideally, for
these type of problems I would like to use psql variables because it
gives me more flexibility than the C preprocessor in terms of
development.

merlin

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Dino Vliet 2007-02-28 18:04:06 /libexec/ld-elf.so.1: Shared object "libpq.so.4" not found
Previous Message John Jawed 2007-02-28 17:25:03 Re: Difference between UNIQUE constraint vs index