Unix Technical Forum

Exporting type OID macros in a cleaner fashion

This is a discussion on Exporting type OID macros in a cleaner fashion within the pgsql Hackers forums, part of the PostgreSQL category; --> This thread: http://archives.postgresql.org/pgsql...6/msg00005.php points up that if a client program would like to refer to datatype OIDs by means ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Hackers

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-12-2008, 03:00 AM
Tom Lane
 
Posts: n/a
Default Exporting type OID macros in a cleaner fashion

This thread:
http://archives.postgresql.org/pgsql...6/msg00005.php
points up that if a client program would like to refer to datatype
OIDs by means of the pg_type.h macros (ie, write "INT4OID" and not
"23"), it's currently forced to include postgres.h, which is not
a good idea for a number of reasons. We intend postgres.h for use
by backend-side code; frontend code ought to use postgres_fe.h, and
indeed a plain libpq client shouldn't be including either. There's
way too much pollution of the client namespace from either file.

I ran into this same problem last week when I wanted to clean up
some hard-coded OIDs in psql's print.c. I did the same thing the
Qt people did, ie, #include postgres.h, but it's a really ugly hack.

I think it'd be a good idea to fix things so that the type OID macros
are available to frontend code without having to break any rules about
what to include. I looked at whether we could sanitize
catalog/pg_type.h so it could be used in a frontend environment, but
there are a couple obstacles there:

* We'd have to move the extern declarations for catalog/pg_type.c
somewhere else, and there's not an obvious candidate.

* There are still the BKI macros (CATALOG, DATA, etc) which really
should not be exported to client code ... DATA in particular seems like
a pretty obtrusive choice of macro name.

The alternative I'm currently thinking about is to build and install an
auto-generated file comparable to fmgroids.h, containing *only* the type
OID macro #defines extracted from pg_type.h. This would require just a
trivial amount of sed hacking.

I'm not entirely clear where to install such a thing though. The
fmgroids.h precedent suggests server/utils/fmgroids.h, but if this is
intended for client-side use it shouldn't go under /server. I'm
tempted to install it as "pgtypeoids.h" at the top level of the
installation include directory ... but then I'm not clear which source
directory ought to generate it.

Thoughts, objections, better ideas?

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-12-2008, 03:01 AM
Martijn van Oosterhout
 
Posts: n/a
Default Re: Exporting type OID macros in a cleaner fashion

On Fri, Jun 16, 2006 at 10:58:05PM -0400, Tom Lane wrote:
> The alternative I'm currently thinking about is to build and install an
> auto-generated file comparable to fmgroids.h, containing *only* the type
> OID macro #defines extracted from pg_type.h. This would require just a
> trivial amount of sed hacking.


This is a good idea. It would be nice to be able to have stuff useful
for the frontend available without having to pullin everything for the
backend.

> I'm not entirely clear where to install such a thing though. The
> fmgroids.h precedent suggests server/utils/fmgroids.h, but if this is
> intended for client-side use it shouldn't go under /server. I'm
> tempted to install it as "pgtypeoids.h" at the top level of the
> installation include directory ... but then I'm not clear which source
> directory ought to generate it.


At first glance I'd get include/catalog to build it and install it.
pgtypeoids.h sounds like a good name to me and it should be in the top
level.

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


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFElH+lIB7bNG8LQkwRAhGJAJ98WS6YjACkwmrd6GCxu7 MV7LXYKACfQtUn
7qV552OlHiSooraQGAkTV0g=
=wEhe
-----END PGP SIGNATURE-----

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-12-2008, 03:10 AM
Greg Sabino Mullane
 
Posts: n/a
Default Re: Exporting type OID macros in a cleaner fashion


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


> The alternative I'm currently thinking about is to build and install an
> auto-generated file comparable to fmgroids.h, containing *only* the type
> OID macro #defines extracted from pg_type.h. This would require just a
> trivial amount of sed hacking.


FWIW, that's exactly what we currently do in DBD::Pg to generate an up to
date list of types:

## $file = "pg_type.h"
open(F, $file) or die qq{Could not open file "$file": $!\n};
my %oid;
my $maxlen = 1;
while(<F>) {
next unless /^#define\s+([A-Z0-9_]*OID)\s+(\d+)/o;
$oid{$1} = $2;
length($1) > $maxlen and $maxlen = length($1);
}
close(F);

We actually go on from there to build a bunch of custom C structs. The maxlen
is simply there to make our final "types.c" line up pretty.

Installing it at the top-level sounds good, although I don't think
we'd see a need to switch to it since we already parse pg_types.h ourselves.

- --
Greg Sabino Mullane greg@turnstep.com
PGP Key: 0x14964AC8 200606241151
http://biglumber.com/x/web?pk=2529DF...9B906714964AC8
-----BEGIN PGP SIGNATURE-----

iD8DBQFEnWAfvJuQZxSWSsgRAjgqAKClEDrahFG5NCSrK47Ae7 P13QCD+ACg1KHe
XS2uYrmI5wf6i8Mpttpi1U8=
=wlUx
-----END PGP SIGNATURE-----



---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:13 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com