Inserting Null Value or String Value
Inserting Null Value or String Value
am 01.10.2002 18:54:53 von test test
--0-1322507064-1033491293=:761
Content-Type: text/plain; charset=us-ascii
Hi,
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
The value I am sending is: spec_start_date = 10/01/02
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
Re: Inserting Null Value or String Value
am 01.10.2002 19:37:04 von Keary Suska
> This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
--MS_Mac_OE_3116317025_10963218_MIME_Part
Content-type: text/plain; charset="US-ASCII"
Content-transfer-encoding: 7bit
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
The value I am sending is: spec_start_date = 10/01/02
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 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.
Keary Suska
Esoteritech, Inc.
"Leveraging Open Source for a better Internet"
--MS_Mac_OE_3116317025_10963218_MIME_Part
Content-type: text/html; charset="US-ASCII"
Content-transfer-encoding: quoted-printable
Re: [PHP] Inserting Null Value or String Value
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 someti=
mes 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 &q=
uot;spec_start_date" is of type 'date' but expression is of type 'inte=
ger' You will need to rewrite or cast the expression
The value I am sending is: spec_start_date =3D 10/01/02
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 &qu=
ot;IF <use quotes> ELSE <don't use quotes>" in the SQL str=
ing, by I am entering many values and this would really get messy. I was ho=
ping 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.
Keary Suska
Esoteritech, Inc.
"Leveraging Open Source for a better Internet"
--MS_Mac_OE_3116317025_10963218_MIME_Part--
Re: Inserting Null Value or String Value
am 01.10.2002 20:00:07 von Roland Roberts
>>>>> "Keary" == Keary Suska writes:
Keary> If I surround the date with single quotes it should be
Keary> fine, but I can't do that when I want to insert a null
Keary> value. I know that I can do an "IF
Re: Inserting Null Value or String Value
am 01.10.2002 20:08:03 von Eckhard Hoeffner
* 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
Eckhard Höffner
e-hoeffner@fifoost.org
D-80331 München
Tel. +49-89-21 03 18 88=20
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?
http://archives.postgresql.org
Re: Inserting Null Value or String Value
am 01.10.2002 20:41:57 von pgerzson
Hi Sean,
see below!
2002. október 1. 18:54 dátummal test test ezt írta:
| Hi,
|
| 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
|
| The value I am sending is: spec_start_date = 10/01/02
|
| 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
Re: Inserting Null Value or String Value
am 01.10.2002 21:12:43 von test test
--0-1846274692-1033499563=:28434
Content-Type: text/plain; charset=us-ascii
Actually, this does not work, it generates the SQL fine, but I get a Parse error when trying to insert it. I am doing something very similar, did I mess up somewhere.
Here is the PHP:
if ($special_start_date == '')
{$special_start_date = 'null';}
else {$special_start_date = "'$special_start_date'";}
if ($special_end_date == '')
{$special_end_date = 'null';}
else {$special_end_date = "'$special_end_date'";}
$sql = "INSERT INTO prod_opt (
xref_prod_id,
code,
title,
isbn,
list_price,
our_price,
spec_price,
spec_start_date,
spec_end_date,
quantity,
clearance,
priority)
VALUES (
'".$prod_id."',
'".$item_code."',
'".$option_format."',
'".$isbn."',
".$list_price.",
".$our_price.",
".$special_price.",
".$special_start_date.",
".$special_end_date.",
".$qty.",
'".$clearance."',
".$priority.")";
$result = pg_exec($dbh, $sql);
This is the error I get: Warning: PostgreSQL query failed: ERROR: parser: parse error at or near "10"
This is the SQL generated: UPDATE prod_opt SET xref_prod_id = '4', code = '2', title = 'test', isbn = '2', list_price = 2, our_price = 2, spec_price = 2, spec_start_date = '10/01/02', spec_end_date = '10/01/02', quantity = 2, clearance = 't', priority = 2 WHERE id = '2'
-Sean
Eckhard Hoeffner wrote: * 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 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
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?
http://archives.postgresql.org
---------------------------------
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
--0-1846274692-1033499563=:28434
Content-Type: text/html; charset=us-ascii
Actually, this does not work, it generates the SQL fine, but I get a Parse error when trying to insert it. I am doing something very similar, did I mess up somewhere.
Here is the PHP:
if ($special_start_date == '')
{$special_start_date = 'null';}
else {$special_start_date = "'$special_start_date'";}
if ($special_end_date == '')
{$special_end_date = 'null';}
else {$special_end_date = "'$special_end_date'";}
$sql = "INSERT INTO prod_opt (
xref_prod_id,
code,
title,
isbn,
list_price,
our_price,
spec_price,
spec_start_date,
spec_end_date,
quantity,
clearance,
priority)
VALUES (
'".$prod_id."',
'".$item_code."',
'".$option_format."',
'".$isbn."',
".$list_price.",
".$our_price.",
".$special_price.",
".$special_start_date.",
".$special_end_date.",
".$qty.",
'".$clearance."',
".$priority.")";
$result = pg_exec($dbh, $sql);
This is the error I get: Warning: PostgreSQL query failed: ERROR: parser: parse error at or near "10"
This is the SQL generated: UPDATE prod_opt SET xref_prod_id = '4', code = '2', title = 'test', isbn = '2', list_price = 2, our_price = 2, spec_price = 2, spec_start_date = '10/01/02', spec_end_date = '10/01/02', quantity = 2, clearance = 't', priority = 2 WHERE id = '2'
-Sean
Eckhard Hoeffner wrote:
* 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
=1>Do you Yahoo!?
New
--0-1846274692-1033499563=:28434--
Re: Inserting Null Value or String Value
am 01.10.2002 21:20:10 von test test
--0-1322220705-1033500010=:90691
Content-Type: text/plain; charset=us-ascii
Sorry, I pasted the wrong code. This is the PHP Code for the UPDATE not INSERT:
$sql = "UPDATE prod_opt
SET xref_prod_id = '$prod_id',
code = '$item_code',
title = '$option_format',
isbn = '$isbn',
list_price = $list_price,
our_price = $our_price,
spec_price = $special_price,
spec_start_date = $special_start_date,
spec_end_date = $special_end_date,
quantity = $qty,
clearance = '$clearance',
priority = $priority
WHERE id = '$id'";
$result = pg_exec($dbh, $sql);
Sean wrote:
Actually, this does not work, it generates the SQL fine, but I get a Parse error when trying to insert it. I am doing something very similar, did I mess up somewhere.
Here is the PHP:
if ($special_start_date == '')
{$special_start_date = 'null';}
else {$special_start_date = "'$special_start_date'";}
if ($special_end_date == '')
{$special_end_date = 'null';}
else {$special_end_date = "'$special_end_date'";}
$sql = "INSERT INTO prod_opt (
xref_prod_id,
code,
title,
isbn,
list_price,
our_price,
spec_price,
spec_start_date,
spec_end_date,
quantity,
clearance,
priority)
VALUES (
'".$prod_id."',
'".$item_code."',
'".$option_format."',
'".$isbn."',
".$list_price.",
".$our_price.",
".$special_price.",
".$special_start_date.",
".$special_end_date.",
".$qty.",
'".$clearance."',
".$priority.")";
$result = pg_exec($dbh, $sql);
This is the error I get: Warning: PostgreSQL query failed: ERROR: parser: parse error at or near "10"
This is the SQL generated: UPDATE prod_opt SET xref_prod_id = '4', code = '2', title = 'test', isbn = '2', list_price = 2, our_price = 2, spec_price = 2, spec_start_date = '10/01/02', spec_end_date = '10/01/02', quantity = 2, clearance = 't', priority = 2 WHERE id = '2'
-Sean
Eckhard Hoeffner wrote: * 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 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
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?
http://archives.postgresql.org
---------------------------------
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
---------------------------------
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
--0-1322220705-1033500010=:90691
Content-Type: text/html; charset=us-ascii
Sorry, I pasted the wrong code. This is the PHP Code for the UPDATE not INSERT:
$sql = "UPDATE prod_opt
SET xref_prod_id = '$prod_id',
code = '$item_code',
title = '$option_format',
isbn = '$isbn',
list_price = $list_price,
our_price = $our_price,
spec_price = $special_price,
spec_start_date = $special_start_date,
spec_end_date = $special_end_date,
quantity = $qty,
clearance = '$clearance',
priority = $priority
WHERE id = '$id'";
$result = pg_exec($dbh, $sql);
Sean wrote:
Actually, this does not work, it generates the SQL fine, but I get a Parse error when trying to insert it. I am doing something very similar, did I mess up somewhere.
Here is the PHP:
if ($special_start_date == '')
{$special_start_date = 'null';}
else {$special_start_date = "'$special_start_date'";}
if ($special_end_date == '')
{$special_end_date = 'null';}
else {$special_end_date = "'$special_end_date'";}
$sql = "INSERT INTO prod_opt (
xref_prod_id,
code,
title,
isbn,
list_price,
our_price,
spec_price,
spec_start_date,
spec_end_date,
quantity,
clearance,
priority)
VALUES (
'".$prod_id."',
'".$item_code."',
'".$option_format."',
'".$isbn."',
".$list_price.",
".$our_price.",
".$special_price.",
".$special_start_date.",
".$special_end_date.",
".$qty.",
'".$clearance."',
".$priority.")";
$result = pg_exec($dbh, $sql);
This is the error I get: Warning: PostgreSQL query failed: ERROR: parser: parse error at or near "10"
This is the SQL generated: UPDATE prod_opt SET xref_prod_id = '4', code = '2', title = 'test', isbn = '2', list_price = 2, our_price = 2, spec_price = 2, spec_start_date = '10/01/02', spec_end_date = '10/01/02', quantity = 2, clearance = 't', priority = 2 WHERE id = '2'
-Sean
Eckhard Hoeffner wrote:
* 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
Do you Yahoo!?
New
Do you Yahoo!?
New
--0-1322220705-1033500010=:90691--
Re: Inserting Null Value or String Value
am 02.10.2002 00:48:09 von Keary Suska
on 10/1/02 1:20 PM, dcmkx10@yahoo.com purportedly said:
> This is the SQL generated: UPDATE prod_opt SET xref_prod_id = '4', code = '2',
> title = 'test', isbn = '2', list_price = 2, our_price = 2, spec_price = 2,
> spec_start_date = '10/01/02', spec_end_date = '10/01/02', quantity = 2,
> clearance = 't', priority = 2 WHERE id = '2'
>
> This is the error I get: Warning: PostgreSQL query failed: ERROR: parser:
> parse error at or near "10"
I wouldn't expect that error message, but unless you have changed your date
preferences the date format being used is invalid. By default, you must use
SQl formatted dates, e.g. 2002-10-01
Keary Suska
Esoteritech, Inc.
"Leveraging Open Source for a better Internet"
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)