why does access 2010 with postgresql odbc driver call IDENT_CURRENT?

99封情书 提交于 2021-02-08 03:28:47

问题


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 if nextval 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 executed nextval 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 causes INSERT 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!