Hello!
I saw an example with PGQuery which can return the last inserted id.
But could I use same technic with TPGSQL class?
For example:
insert into ins_test(name) values (:name) returning id into :id
Could this class retreive the inserted record id somehow? Or is it available only in TPGQuery records?
Thanks
dd
Returning new ID in TPGSQL class
Re: Returning new ID in TPGSQL class
To solve your task, you can use the following code:
Code: Select all
var
Param: TDAParam;
...
PgSQL.SQL.Text := 'insert into ins_test(name) values (:name) returning id';
PgSQL.ParamByName('name').AsString := 'Name';
Param := PgSQL.Params.Add as TDAParam;
Param.Name := 'id';
Param.ParamType := ptOutPut;
Param.DataType := ftInteger;
PgSQL.Execute;
ShowMessage(Format('ID: %s', [PgSQL.ParamByName('id').AsString]));