Question

I've to make some PHP interaction with an Ingres database. I need to get the ID of the last entry I inserted in the database.

How should I proceed? I'm not an ingres expert, but I suppose there is also auto-incremented ID/Sequences/...?

Thank you very much

Was it helpful?

Solution

The last_identity() function will give you the last generated sequence number for a table, e.g.:

SELECT last_identity() FROM t1

From what I understand the sequence number needs to be created, using CREATE TABLE using the following syntax:

colname integer generated always as identity

e.g.:

CREATE TABLE t1 ( 
    idx integer generated always as identity,
    sometext varchar(100) not null
)

See http://community.ingres.com/wiki/Using_Ingres_Identity_Columns for some additional notes on using identity columns.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top