skip to Main Content

I have an sql table foo created like below

Create table

CREATE TABLE foo(id INTEGER, name TEXT) ;

Inserted some data

INSERT INTO foo VALUES(1, 'Alex');

Created INDEX

CREATE INDEX bar_idx ON foo(id) ;

Now Inserted some extra data

INSERT INTO foo VALUES(1, 'Bob');

Does it automatically updatae previously created index in the column ?

2

Answers


  1. Yes, indexes are always kept up-to-date. In the event of bulk changes of a very large number of rows you may want to run REINDEX but that is not normally necessary.

    Login or Signup to reply.
  2. yes if you simply enter data then it will be update but if you insert another row then
    You need to explicitly rebuild or reorganise the index to ensure that it reflects the current state of the data.(for better practise)

    In your example as you created an index on ‘id’ attribute and later when you inserted another row the index will now be updated

    you have to use REINDEX bar_idx;

    while it is not necessary to run this

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search