| From: | Chris <dmagick(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 03:13:01 |
| Message-ID: | 48F802BD.10402@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
Tim Uckun 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;
>
> In rails if I don't specify the provider_id the ORM passes a NULL in
> the SQL to insert or update and the query blows up.
Not sure how you do this in rails but if you use DEFAULT in the query it
works:
> create table a(a int default 5);
CREATE TABLE
> insert into a(a) values (DEFAULT);
INSERT 0 1
> SELECT * from a;
a
---
5
(1 row)
--
Postgresql & php tutorials
http://www.designmagick.com/
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Scott Marlowe | 2008-10-17 03:18:15 | Re: Question about NOT NULL and default values. |
| Previous Message | Tim Uckun | 2008-10-17 03:09:10 | Question about NOT NULL and default values. |