pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ed Brown <ebrown@arcompanies.net>
To: Philippe Lang <philippe.lang@attiksystem.ch>
To: pgsql-odbc@postgresql.org
Cc: scott.marlowe <scott.marlowe@ihs.com>
Subject: Re: @@IDENTITY (Was: Access - ODBC - serial problem)
Date: Sat, 10 Apr 2004 07:17:55 -0700
Message-ID: <035801c41f06$9e405ea0$0501a8c0@ebrownhome> (raw)
References: <6C0CF58A187DA5479245E0830AF84F420AFF27@poweredge.attiksystem.ch>

I agree with the strangeness of Microsoft's name, but the capability is
useful. What I do in a case like this is use the transaction capability.  If
you do

Begin transaction;
    <Do the insert>;
    Select max(oid_column_name) from table;
Commit work;

You are guaranteed to get the correct ID back in any system that supports
transactions. Because all "real" databases support caching, it's
computationally inexpensive, unless you have a trigger that will insert
another record behind your back.





Ed
----- Original Message ----- 
From: "Philippe Lang" <philippe.lang@attiksystem.ch>
To: <pgsql-odbc@postgresql.org>
Cc: "scott.marlowe" <scott.marlowe@ihs.com>
Sent: Saturday, April 10, 2004 1:59 AM
Subject: Re: [ODBC] @@IDENTITY (Was: Access - ODBC - serial problem)


> For reasons unfathomable to modern man, Microsoft chose @@IDENTITY to
mean,
> not the current user, as I or you or any sane person would expect, but
to hold
> the incremented value of an autoincrementing column fed by an insert.
Another
> triumph in orthogonally named things from Microsoft.
>
> Anyway, what the original conversation was about was getting back the
auto
> increment value from pgsql via ODBC with access on top.  The problem
being
> that postgresql doesn't have a simple "what was the autoincrement I
just put
> in" but requires the user to either use the system catalogs to look up
the
> sequence name and then use currval on it, or something like a plpgsql
function
> to insert your data.

-----------

Without a way of getting the autoincrement from the ODBC driver, there
will always be cases, when adding data to a table through a linked
table, where the data that appears onscreen is not the one that has been
added to the table. And this until you requery the whole table.

- After an insert, Microsft ODBC driver issues a "SELECT @@IDENTITY".

- After an insert, Postgresql ODBC driver reads the data based on the
values that have been inserted. There are cases were these values
already existed in the table before the insert, and so the autoincrement
fetched may not be correct.

Is there anything that can be done at the driver level?


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





view thread (7+ messages)  latest in thread

Message-ID: <035801c41f06$9e405ea0$0501a8c0@ebrownhome>
Permalink:  ../035801c41f06$9e405ea0$0501a8c0@ebrownhome/
Also on:    postgresql.org/message-id/035801c41f06$9e405ea0$0501a8c0@ebrownhome

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-odbc@postgresql.org
  Cc: ebrown@arcompanies.net, philippe.lang@attiksystem.ch, scott.marlowe@ihs.com
  Subject: Re: @@IDENTITY (Was: Access - ODBC - serial problem)
  In-Reply-To: <035801c41f06$9e405ea0$0501a8c0@ebrownhome>
  References: <6C0CF58A187DA5479245E0830AF84F420AFF27@poweredge.attiksystem.ch> <035801c41f06$9e405ea0$0501a8c0@ebrownhome>

* 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