Subject Re: [firebird-support] FB 3.0, how to get IDENTITY of last inserted row
Author Thomas Steinmaurer
Hello Zoran,

> In FB 2.5 I am using
> insert into MyTable (col1, col2) values(val1, val2) returning Id
> where Id is autoinc column (sequence generator + before insert trigger).
> How do I do it in FB 3.0? It doesn’t like “returning Id”. It displays
> this error: SQLDA error. Wrong number of parameters (expected 1, got 0)
> I have Id defined as IDENTITY. Can I get INDENTITY for the last inserted
> row without using SELECT GEN_ID(generator-name, 0) AS ID FROM RDB$DATABASE ?
> I am trying this with Firebird Maestro (supports FB 3) on Win
> Server 2012 R2. With FB 2.5 all works as expected.

The following works fine for me with FB3 (server + client library):

create table t1 (
id integer generated by default as identity primary key
, fname varchar(15)


In isql:

C:\Firebird\Firebird_300_4050_x86>isql -user sysdba -password masterkey
Database: fb3test.fdb, User: SYSDBA
SQL> insert into t1 (fname) values ('hugo') returning id;


So, in general it works. ;-)

With regards,
Thomas Steinmaurer

Professional Tools and Services for Firebird
FB TraceManager, IB LogManager, Database Health Check, Tuning etc.