问题
I am migrating an access 2003 application to access 2010. The application uses the postgres odbc driver to access its data.
On access 2010 it tries to use the IDENT_CURRENT function on the postgresql server (as seen with wireshark) to identify the id of a recently inserted row ... Unfortunately IDENT_CURRENT is not a function supported by postgresql as far as I know ...
I am using the latest postgresql ODBC driver (9.0) with a postgresql 8.3 database.
回答1:
Using currval is the right way to go (emphasis mine):
Return the value most recently obtained by
nextval
for this sequence in the current session. (An error is reported ifnextval
has never been called for this sequence in this session.) Because this is returning a session-local value, it gives a predictable answer whether or not other sessions have executednextval
since the current session did.
And wrapping it up in an IDENT_CURRENT
function is a perfectly reasonable porting technique.
You could also use RETURNING id on your INSERT
statements (again, emphasis mine):
The optional
RETURNING
clause causesINSERT
to compute and return value(s) based on each row actually inserted. This is primarily useful for obtaining values that were supplied by defaults, such as a serial sequence number.
That might be a bit quicker and cleaner but you'd still have some portability issues. OTOH, I think you're going to have portability issues no matter what you do.
来源:https://stackoverflow.com/questions/5552956/why-does-access-2010-with-postgresql-odbc-driver-call-ident-current