Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Avoiding gap in ids for a table in OpenERP PostgreSQL

    • 0
    • 1
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 664
    Comment on it

    Sometimes when we delete few or all records from a table, we may want ids of records to be in sync with the last record or the first one, but what we get is that new ids with a significant amount of gap have been generated, for example if it should be 10 but it is 323. In OpenERP sometimes its creates problems when operating on data, so we need to adjust the id(primary key) back to the required id.

    What can be done:

    1. First delete the records if u you want to

    2. Run the following query:

      SELECT setval('account_voucher_id_seq' , mx.mx+1)
      FROM (SELECT max(id) AS mx FROM account_voucher) mx

    This query first selects the max id from the records and then change it to next value, for example if the last id was 4, then next id will be 5.

    Note: account_voucher_id_seq is the sequence under the database->Schemas->Public->Sequences for the table account_voucher, All the sequences for all the tables are defined under the same menu.

    Good Luck

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: