Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 85159475EBB for ; Tue, 1 Oct 2002 14:08:30 -0400 (EDT) Received: from mailout06.sul.t-online.com (mailout06.sul.t-online.com [194.25.134.19]) by postgresql.org (Postfix) with ESMTP id E5ED947679B for ; Tue, 1 Oct 2002 14:08:28 -0400 (EDT) Received: from fwd01.sul.t-online.de by mailout06.sul.t-online.com with smtp id 17wRRc-0002hg-02; Tue, 01 Oct 2002 20:08:28 +0200 Received: from localhost (520054136294-0001@[80.128.17.173]) by fmrl01.sul.t-online.com with esmtp id 17wRRP-0FioNMC; Tue, 1 Oct 2002 20:08:15 +0200 Received: from eckhard by localhost with local (Exim 3.35 #1 (Debian)) id 17wRRD-0000Jx-00 for ; Tue, 01 Oct 2002 20:08:03 +0200 Date: Tue, 1 Oct 2002 20:08:03 +0200 From: Eckhard Hoeffner To: Postgres-PHP Subject: Re: Inserting Null Value or String Value Message-ID: <20021001180803.GA17732@fifoost.org> Mail-Followup-To: Postgres-PHP References: <20021001165453.882.qmail@web14410.mail.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: User-Agent: Mutt/1.4i X-Mailer: Mutt http://www.mutt.org/ Organization: FiFo Ost =?iso-8859-1?Q?M=FCnchen?= X-Editor: Vim http://www.vim.org/ X-URL: http://www.fifoost.org X-Uptime: 19:53:08 up 12:02, 1 user, load average: 0.23, 0.32, 0.24 X-Sender: 520054136294-0001@t-dialin.net X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200210/4 X-Sequence-Number: 1519 * Keary Suska [01 10 02 19:37]: >on 10/1/02 10:54 AM, dcmkx10@yahoo.com purportedly said: > >I am trying to insert a date into a date field, but also sometimes I need = to >insert a null value. Inserting the null value seems to require not using >quotes around null, but if I try to enter a date without quotes around it, >it thinks it is a number. > >Here is the error I get: Warning: PostgreSQL query failed: ERROR: column >"spec_start_date" is of type 'date' but expression is of type 'integer' You >will need to rewrite or cast the expression > >If I surround the date with single quotes it should be fine, but I can't do >that when I want to insert a null value. I know that I can do an "IF quotes> ELSE " in the SQL string, by I am entering many >values and this would really get messy. I was hoping that there was a bett= er >solution. Thanks for any help. > >If there is a way, I haven't found it yet. But it doesn't have to be >messy--simply create a function that does the if-else for you, and your co= de >will stay clean. Maybe you should do the following. At the point where the switch=20 "date" or "NULL" in the php-file is:=20 if(empty($form_date)){ $date_var =3D NULL; }else $date_var =3D "'$date'"; $query =3D "INSERT INTO table (table_row1, date)=20 VALUES ('$value1', $date_var);"; You still have the if/else, but I think there must be somewhere the switch NULL <=3D> date=20=20=20=20=20=20=20=20=20=20 --=20 Eckhard H=F6ffner e-hoeffner@fifoost.org D-80331 M=FCnchen Tel. +49-89-21 03 18 88=20