pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Pierre-Olivier Gaillard <pierre.gaillard@hol.fr>
Cc: pgsql-interfaces@postgreSQL.org
Subject: Re: [INTERFACES] Jdbc and oid
Date: Tue, 01 Sep 1998 16:24:31 -0400
Message-ID: <886.904681471@sss.pgh.pa.us> (raw)
In-Reply-To: <35EC2CF3.3451941@hol.fr>

Pierre-Olivier Gaillard <pierre.gaillard@hol.fr> writes:
> I need to use the oid of postgresql rows as primary key. The trouble is
> that INSERT does not return the oid of created objects in JDBC (the psql
> frontend does display the oid after INSERT, so the info should be
> available).

I agree this is a serious shortcoming in the API for JDBC.

> In case you need some background : I need this to write classes that
> automatically store themselves to the database. Relationships are to be
> stored as well. This is why I need oids : they are a convenient way to
> reference objects (and probably fast, too).

A couple of points here ---

1. OIDs normally are not preserved across a database dump and reload.
(You can force them to be, but it's inefficient and hastens the day when
you run out of OIDs...)  So it's a bad idea to use OIDs as *long term*
identifiers --- in particular, I'd strongly recommend against storing an
OID in one table row as a reference to another table row.

It's perfectly OK to use OIDs as temporary pointers to particular rows
inside an application, if you can shut down and restart the application
when reloading the database.  I do this all the time.

2. OIDs aren't any faster than any other method of finding a table row.
If you expect SELECT or UPDATE ... "WHERE oid = something" to be fast
for a large table, you'd better create an index on OID for that table.
Otherwise the system's gonna resort to sequential scan.


If you need permanent identifiers for table rows, it's a much better
idea to assign them from a sequence object.  This does mean that you
need an ID column in the table along with the actual data columns.

			regards, tom lane



view thread (3+ messages)  latest in thread

Message-ID: <886.904681471@sss.pgh.pa.us>
Permalink:  ../886.904681471@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/886.904681471@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: tgl@sss.pgh.pa.us, pierre.gaillard@hol.fr
  Subject: Re: [INTERFACES] Jdbc and oid
  In-Reply-To: <886.904681471@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox