Re: Remove Modifiers on Table

From: Susan Cassidy <scassidy(at)edgewave(dot)com>
To: Carlos Mennens <carlos(dot)mennens(at)gmail(dot)com>, PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: Remove Modifiers on Table
Date: 2011-05-17 18:46:50
Message-ID: 3A51F387FE0CC74D80FA60C146987F2501C3D29A3E9E@oc-exchange1.stbernard.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


> Doesn't the SERIAL shortcut automatically do this on the fly? How
> would I set this?
>
> ALTER TABLE table_name ALTER COLUMN id SET DEFAULT nextval('foo_seq_id');

If you have existing data, say with values 1, 2, 3, etc. and you set the column to start using a sequence nextval as default, unless the sequence has been told what value to start with, it will start at 1.

Per the documentation:

SELECT setval('users_id_seq', 42); -- Next nextval (insert) will return 43

Susan Cassidy

In response to

Browse pgsql-general by date

  From Date Subject
Next Message James B. Byrne 2011-05-17 20:02:18 Infinity dates in RoR was How to handle bogus nulls from ActiveRecord
Previous Message Andreas Kretschmer 2011-05-17 18:44:41 Re: Can't unsubscribe