Return Unique Id

Das Goravani goravanis at
Wed Feb 8 17:07:24 UTC 2023


If you are using Postgres or other powerful SQL database the clause you want is "RETURNING"

At the end of your select statement add RETURNING myColumn to the statement.

Then do a fetch into any undefined row or list and it will put the value as the first column in it, then you can grab it and add it into the row you are proceeding with.

You’re right, this is very important and necessary to intelligently continue with what follows your INSERT command. 

If you are on SQLite there is another way of doing it that Omnis provides as a special SQLite command. I forget what it is, how it’s worded, but I can look it up if you need that. It’s something like

Do $statementObject.$lastrowid Returns theValue

With the SQLite DAM you can see $lastrowid as one of the commands offered. It gives you the PK of the last row inserted. 


> On Feb 8, 2023, at 11:17 AM, Daniel Sananes <daniel.s at> wrote:
> Hi
> Thanks for the answers regarding $select().
> I have this under control now and the Begin Text block seems promising.
> The Begin statement approach is promising as well.
> I have a field called user_id which is set as unique and to autoincrement.
> So when I do $insert() the record is added correctly with a unique user_id.
> But I would like to have a return of this number immediately after the $insert().
> As it is now I do not know the id-number and so I cannot intelligently continue with the newly created record.
> Is this a SQL-command?
> I think I have read about this on the list but I cannot really find these threads.
> /Daniel
> 0736 704070
> _____________________________________________________________
> Manage your list subscriptions at
> Start a new message -> mailto:omnisdev-en at 

More information about the omnisdev-en mailing list