From: | "Scott Marlowe" <scott(dot)marlowe(at)gmail(dot)com> |
---|---|
To: | "Tim Uckun" <timuckun(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Question about NOT NULL and default values. |
Date: | 2008-10-17 04:04:17 |
Message-ID: | dcc563d10810162104g282e0243g5b5c5468ec875d46@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Thu, Oct 16, 2008 at 9:58 PM, Tim Uckun <timuckun(at)gmail(dot)com> wrote:
> On Fri, Oct 17, 2008 at 4:40 PM, Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com> wrote:
>> On Thu, Oct 16, 2008 at 9:09 PM, Tim Uckun <timuckun(at)gmail(dot)com> wrote:
>>> Hey all.
>>>
>>> I am using postgres 8.3 with a rails application. I have a column
>>> defined like this.
>>>
>>> ALTER TABLE provisions ADD COLUMN provider_id integer;
>>> ALTER TABLE provisions ALTER COLUMN provider_id SET STORAGE PLAIN;
>>> ALTER TABLE provisions ALTER COLUMN provider_id SET NOT NULL;
>>> ALTER TABLE provisions ALTER COLUMN provider_id SET DEFAULT 0;
>>
>> Hold on, when did you assign a sequence to this column? When you
>> created it as a serial? Or is there none assigned?
>>
>
> There is no sequence. It's a foreign key.
Not sure what being a FK means here. Postgresql uses sequences and
default to make an autoincrementing column.
Old fashioned way (which doesn't work well with ruby):
create sequence test_id_seq;
create table test (id int primary key default nextval('test_id_seq'),
info text);
Easy method, which should work with ruby-pg:
create table test (id serial primary key, info text);
From | Date | Subject | |
---|---|---|---|
Next Message | Scott Marlowe | 2008-10-17 04:05:05 | Re: Question about NOT NULL and default values. |
Previous Message | Tom Lane | 2008-10-17 04:02:33 | Re: Question about fulltext search and to_tsvector function |