Skip site navigation (1) Skip section navigation (2)

Can I use check-constraint to set null?

From: Rikard Bosnjakovic <rikard(dot)bosnjakovic(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Can I use check-constraint to set null?
Date: 2010-08-16 18:01:55
Message-ID: AANLkTik6wgxKakmQz1-Lx_0EJC41oydbfuubWhywrk03@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
(Postgres 8.4.2)

CREATE TABLE test (foo numeric(8,2) CHECK (foo >= 0.0));

ecdb=> insert into test values (-2.2);
ERROR:  new row for relation "test" violates check constraint "test_foo_check"

This is expected.

However, is there a way to insert a null when this check fails,
instead of returning an error (and thus aborting the insert)? I'm
reading on http://www.postgresql.org/docs/current/static/ddl-constraints.html
but cannot find an answer to this question.


-- 
- Rikard

Responses

pgsql-novice by date

Next:From: Victor HugoDate: 2010-08-16 18:03:01
Subject: Re: Remote Connection to server: Connection Refused
Previous:From: Kavitha ParvataneniDate: 2010-08-16 17:52:19
Subject: Remote Connection to server: Connection Refused

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group