1

i can select last record by this query

select first 1 idt from table1 order by id desc;

but i want to add a record ( id ++) to end of table in informix

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
MD128
  • 501
  • 4
  • 12

1 Answers1

2

If I understand correctly, you want a SERIAL column in Informix. This is a column that automatically increments when you add a new value.

So, the table should be defined as:

create table table1 (
    id serial primary key,
    . . .
);

Then when you do an insert, leave out the id:

insert into table1 ( . . . )  -- all but id
    values ( . . . );

The id will be automatically incremented and inserted with the data.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • 3
    @alwaystudent: If you follow the instructions given by Gordon, it does work. As an alternative, you can include the serial column in the column list, and specify the value 0 for it, in which case, the next unused serial number will be allocated (and you get told which one was allocated, slightly indirectly. Or you can choose a value (call it V) and it will be used — as long as it doesn't violate the unique constraint. When you do that, if the previous highest serial value was smaller than V, then the next value (that will be allocated using 0) will be set to V+1. – Jonathan Leffler May 05 '19 at 20:22