pg.ddx.io pgsql-odbc@postgresql.org mailing list archive
help / color / mirror / Atom feedRe: @@IDENTITY (Was: Access - ODBC - serial problem)
7+ messages / 5 participants
[nested] [flat]
* Re: @@IDENTITY (Was: Access - ODBC - serial problem)
@ 2004-04-09 19:22 Dave Page <dpage@vale-housing.co.uk>
0 siblings, 1 reply; 7+ messages in thread
From: Dave Page @ 2004-04-09 19:22 UTC (permalink / raw)
To: Philippe Lang <philippe.lang@attiksystem.ch>; jorgens@coho.net; pgsql-odbc
> -----Original Message-----
> From: Philippe Lang [mailto:philippe.lang@attiksystem.ch]
> Sent: 09 April 2004 13:33
> To: jorgens@coho.net; pgsql-odbc@postgresql.org
> Subject: Re: [ODBC] Access - ODBC - serial problem...
>
> Is there a Postgresql ODBC driver guru that could give us an
> idea for a driver modification? I don't know the exact job of
> an ODBC driver, nor how it connects to Postgresql, so I
> cannot tell if it would be possible to modify the ODBC
> driver, and do something like a "SELECT @@IDENTITY" (which is
> a SQL Server 2000 call, correct).
>
> Since Microsoft is behind both Access and SQL Server, maybe
> nothing can be done in the driver itself, and I'll have to
> handle my insertions by hand, through pl/pgsql. But really,
> that's a serious limitation...
SELECT CURRENT_USER;
Though I suspect that is not what you want. Are you asking for the
driver to translate '@@IDENTITY' into 'CURRENT_USER'?
Regards, Dave.
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: @@IDENTITY (Was: Access - ODBC - serial problem)
@ 2004-04-09 20:25 scott.marlowe <scott.marlowe@ihs.com>
parent: Dave Page <dpage@vale-housing.co.uk>
0 siblings, 0 replies; 7+ messages in thread
From: scott.marlowe @ 2004-04-09 20:25 UTC (permalink / raw)
To: Dave Page <dpage@vale-housing.co.uk>; +Cc: Philippe Lang <philippe.lang@attiksystem.ch>; jorgens@coho.net; pgsql-odbc
On Fri, 9 Apr 2004, Dave Page wrote:
>
>
> > -----Original Message-----
> > From: Philippe Lang [mailto:philippe.lang@attiksystem.ch]
> > Sent: 09 April 2004 13:33
> > To: jorgens@coho.net; pgsql-odbc@postgresql.org
> > Subject: Re: [ODBC] Access - ODBC - serial problem...
> >
> > Is there a Postgresql ODBC driver guru that could give us an
> > idea for a driver modification? I don't know the exact job of
> > an ODBC driver, nor how it connects to Postgresql, so I
> > cannot tell if it would be possible to modify the ODBC
> > driver, and do something like a "SELECT @@IDENTITY" (which is
> > a SQL Server 2000 call, correct).
> >
> > Since Microsoft is behind both Access and SQL Server, maybe
> > nothing can be done in the driver itself, and I'll have to
> > handle my insertions by hand, through pl/pgsql. But really,
> > that's a serious limitation...
>
> SELECT CURRENT_USER;
>
> Though I suspect that is not what you want. Are you asking for the
> driver to translate '@@IDENTITY' into 'CURRENT_USER'?
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.
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: @@IDENTITY (Was: Access - ODBC - serial problem)
@ 2004-04-10 08:59 Philippe Lang <philippe.lang@attiksystem.ch>
0 siblings, 1 reply; 7+ messages in thread
From: Philippe Lang @ 2004-04-10 08:59 UTC (permalink / raw)
To: pgsql-odbc; +Cc: scott.marlowe <scott.marlowe@ihs.com>
> 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?
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: @@IDENTITY (Was: Access - ODBC - serial problem)
@ 2004-04-10 14:17 Ed Brown <ebrown@arcompanies.net>
parent: Philippe Lang <philippe.lang@attiksystem.ch>
0 siblings, 1 reply; 7+ messages in thread
From: Ed Brown @ 2004-04-10 14:17 UTC (permalink / raw)
To: Philippe Lang <philippe.lang@attiksystem.ch>; pgsql-odbc; +Cc: scott.marlowe <scott.marlowe@ihs.com>
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
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: @@IDENTITY (Was: Access - ODBC - serial problem)
@ 2004-04-10 20:28 Dave Page <dpage@vale-housing.co.uk>
0 siblings, 0 replies; 7+ messages in thread
From: Dave Page @ 2004-04-10 20:28 UTC (permalink / raw)
To: Philippe Lang <philippe.lang@attiksystem.ch>; pgsql-odbc; +Cc: scott.marlowe <scott.marlowe@ihs.com>
> -----Original Message-----
> From: Philippe Lang [mailto:philippe.lang@attiksystem.ch]
> Sent: 10 April 2004 09:59
> To: pgsql-odbc@postgresql.org
> Cc: scott.marlowe
> 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.
Ahh, that was some good thinking on their part, though it does sorta
make sense.
> - 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.
It does? I wasn't aware of that. I assume you mean when using cursors
(which I never use) as it doesn't following a regular insert statement.
> Is there anything that can be done at the driver level?
Standard answer: The best method would be to do a "SELECT
currval('seq_name');" when required on the relevant sequence.
Regards, Dave.
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: @@IDENTITY (Was: Access - ODBC - serial problem)
@ 2004-04-12 16:44 scott.marlowe <scott.marlowe@ihs.com>
parent: Ed Brown <ebrown@arcompanies.net>
0 siblings, 1 reply; 7+ messages in thread
From: scott.marlowe @ 2004-04-12 16:44 UTC (permalink / raw)
To: Ed Brown <ebrown@arcompanies.net>; +Cc: Philippe Lang <philippe.lang@attiksystem.ch>; pgsql-odbc
On Sat, 10 Apr 2004, Ed Brown wrote:
> 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.
In Postgresql, this is NOT I/O inexpensive, but results in a seq scan of
the whole table to find the max value.
select oid_column_name from table order by oid_column_name desc limit 1
is computationally and I/O inexpensive if the table has an index on that
field.
However, I think you have to be in serializable transaction mode for that
code to be gauranteed not to get the wrong data. But I'm not certain on
that one.
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: @@IDENTITY (Was: Access - ODBC - serial problem)
@ 2004-04-12 17:27 Tom Lane <tgl@sss.pgh.pa.us>
parent: scott.marlowe <scott.marlowe@ihs.com>
0 siblings, 0 replies; 7+ messages in thread
From: Tom Lane @ 2004-04-12 17:27 UTC (permalink / raw)
To: scott.marlowe <scott.marlowe@ihs.com>; +Cc: Ed Brown <ebrown@arcompanies.net>; Philippe Lang <philippe.lang@attiksystem.ch>; pgsql-odbc
"scott.marlowe" <scott.marlowe@ihs.com> writes:
> [ use ORDER BY ... LIMIT instead of MAX ]
> However, I think you have to be in serializable transaction mode for that
> code to be gauranteed not to get the wrong data. But I'm not certain on
> that one.
Yes, you need serializable mode with *either* method to ensure you see
your own row, and not one inserted later by another transaction that
managed to commit before you. The ORDER BY trick is just to get around
Postgres' inability to connect MAX() to indexes; it doesn't affect the
transactional semantics at all.
regards, tom lane
^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2004-04-12 17:27 UTC | newest]
Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-04-09 19:22 Re: @@IDENTITY (Was: Access - ODBC - serial problem) Dave Page <dpage@vale-housing.co.uk>
2004-04-09 20:25 ` scott.marlowe <scott.marlowe@ihs.com>
2004-04-10 08:59 Re: @@IDENTITY (Was: Access - ODBC - serial problem) Philippe Lang <philippe.lang@attiksystem.ch>
2004-04-10 14:17 ` Ed Brown <ebrown@arcompanies.net>
2004-04-12 16:44 ` scott.marlowe <scott.marlowe@ihs.com>
2004-04-12 17:27 ` Tom Lane <tgl@sss.pgh.pa.us>
2004-04-10 20:28 Re: @@IDENTITY (Was: Access - ODBC - serial problem) Dave Page <dpage@vale-housing.co.uk>
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