From: Eckhard Hoeffner <e-hoeffner@fifoost.org>
To: Postgres-PHP <pgsql-php@postgresql.org>
Subject: Re: Inserting Null Value or String Value
Date: Tue, 1 Oct 2002 20:08:03 +0200
Message-ID: <20021001180803.GA17732@fifoost.org> (raw)
In-Reply-To: <B9BF3960.13CA7%hierophant@pcisys.net>
References: <20021001165453.882.qmail@web14410.mail.yahoo.com>
<B9BF3960.13CA7%hierophant@pcisys.net>
* Keary Suska <hierophant@pcisys.net> [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 <use
>quotes> ELSE <don't use quotes>" in the SQL string, by I am entering many
>values and this would really get messy. I was hoping that there was a better
>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 code
>will stay clean.
Maybe you should do the following. At the point where the switch
"date" or "NULL" in the php-file is:
if(empty($form_date)){
$date_var = NULL;
}else $date_var = "'$date'";
$query = "INSERT INTO table (table_row1, date)
VALUES ('$value1', $date_var);";
You still have the if/else, but I think there must be somewhere the
switch NULL <=> date
--
Eckhard Höffner
e-hoeffner@fifoost.org
D-80331 München
Tel. +49-89-21 03 18 88
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-php@postgresql.org
Cc: e-hoeffner@fifoost.org
Subject: Re: Inserting Null Value or String Value
In-Reply-To: <20021001180803.GA17732@fifoost.org>
References: <20021001165453.882.qmail@web14410.mail.yahoo.com> <B9BF3960.13CA7%hierophant@pcisys.net> <20021001180803.GA17732@fifoost.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox