X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id CFC25D1DA34 for ; Wed, 18 Feb 2004 19:51:55 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 59446-08 for ; Wed, 18 Feb 2004 15:51:52 -0400 (AST) Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) by svr1.postgresql.org (Postfix) with ESMTP id D45F3D1D315 for ; Wed, 18 Feb 2004 15:51:50 -0400 (AST) Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) by mail1.ihs.com (8.12.10/8.12.10) with ESMTP id i1IJoGVo001172; Wed, 18 Feb 2004 12:50:17 -0700 (MST) Date: Wed, 18 Feb 2004 12:43:34 -0700 (MST) From: "scott.marlowe" To: Jeremy Smith Cc: Subject: Re: Inserting NULL into Integer column In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-IHS-MailScanner: Found to be clean X-IHS-MailScanner-SpamCheck: X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/256 X-Sequence-Number: 16946 On Wed, 18 Feb 2004, Jeremy Smith wrote: > Hi, > > in mysql I was able to make an insert such as: > > INSERT INTO TABLE (integervariable) VALUES ('') > > and have it either insert that variable, or insert the default if it had > been assigned. In postgresql it gives and error every time that this is > attempted. Since I have so many queries that do this on my site already, is > there any way to set up a table so that it just accepts this sort of query? First off, the reason for this problem is that Postgresql adheres to the SQL standard while MySQL heads off on their own, making it up as they go along. This causes many problems for people migrating from MySQL to almost ANY database. Phew, now that that's out of the way, here's the standard ways of doing it. Use DEFAULT: If no default is it will insert a NULL, otherwise the default will be inserted: insert into table (integervar) values (DEFAULT); OR Leave it out of the list of vars to be inserted insert into table (othervars, othervars2) values ('abc',123); OR Insert a NULL if that's what you want: insert into table (integervar) values (NULL); Note that NULL and DEFAULT are not quoted.