Search Postgresql Archives

Re: No serial type

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Nov 18, 2008 at 10:24 AM, Simon Connah
<simon.n.connah@xxxxxxxxxxxxxxx> wrote:
> Hi,
> I've just started using PostgreSQL and have been reading up on it. Part of
> what I wanted to do was to have a column which automatically incremented
> itself by one every time I do an INSERT. From reading the manual I was lead
> to believe that the correct type for this was either serial or bigserial.
> But whenever I try and update my column to this type it says that it can not
> find that data type. Am I doing something wrong?

Serial is a "pseudotype".  It represents creating an int or bigint and
a sequence then assigning a default value for the column and setting
dependency in the db so the sequence will be dropped when the table
gets dropped.  If you don't want to recreate the table, you can do
this:

create table a (i int primary key, info text);
create sequence a_i_seq;
alter table a alter column i set default nextval('a_i_seq');

not sure the alter table syntax is spot on, haven't used it in a few months.

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux