Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get the value for the LAST call to GEN_ID() [CORE1975] #2413

Open
firebird-automations opened this issue Jul 3, 2008 · 1 comment
Open

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: Sebastian (jsb977)

Like:
currval(regclass) in postgres
This Return value most recently obtained with nextval for specified sequence

Postgres and oracle are similar:
http://www.postgresql.org/docs/8.1/interactive/functions-sequence.html

this is an new feature.... this can help people to migrate app from MySQL /MSSQL server....( wich uses @LASTI_INSERTED_ID..... ) whitout changes to logical app....
select GEN_ID(....,0) is not an correct solution...... this is not PER SESSION..... and can cause bad reads....(i think)

@firebird-automations
Copy link
Collaborator Author

Commented by: SAUL HERNANDEZ (saul.hernandez)

Remember that GEN_ID use a secuence and this is a global object and you can get last id en everywhere.
I recommend that you think about Identity column in firebird , and use when you need know las id
the next statement:

INSERT INTO PERSON(NAME,LAST_NAME) VALUES('JOHN','MONTANA') RETURNING IDPERSONA

(With this you get the id generate in firebird in a secuence or with identity column)

AND if you want store the id in a variable you can use this statement

INSERT INTO PERSON(NAME,LAST_NAME) VALUES('JOHN','MONTANA') RETURNING IDPERSONA INTO :IDPERSONA (THIS IS A VARIABLE)

I DONT RECOMMEND GEN_ID(....,0) USE FOR GET LAS ID , BECAUSE OTHER USER CAN INSERT RECORD IN THE SAME TIME AND YOU SECUENCE MAYBE DONT BE EXACT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant