From: Dan Rosner <rosner@cascadepg.com>
To: pgsql-interfaces@postgresql.org
Subject: Inserting null values into a float4 field using Perl DBI
Date: Tue, 04 Jul 2000 19:27:38 -0700
Message-ID: <39629D1A.E6C8B9CD@cascadepg.com> (raw)
Greetings!
Would anyone mind educating me about how to properly
insert null values into a postgresql float4 field
using perl DBI? I keep getting 0 in the field, instead
of a NULL value as I would expect.
Background:
I'm using placeholders with DBI to read in data from a
file. I do this a lot, as in this example:
my $sth = $dbh->prepare_cached( q{
INSERT INTO mytable (field1, field2, field3) VALUES (?, ?, ?)
}) ;
open (FH, "< $path")
or die "Unable to open $path: $!";
while (<FH>) {
chop;
my ($field1, $field2, $field3) = split /,/;
$sth->execute($field1, $field2, $field3);
}
close (FH);
The sample file I'm reading has some Null values
and looks like this:
1,2,3
4,,6
2,,6
7,8,
12,13,14
However, these values turn up in postgres table as 0, not NULL.
When I do a select on the data read in with DBI, I get:
1,2,3
4,0,6
2,0,6
7,8,0
12,13,14
Would anyone mind telling me what I'm missing and/or point me to
an example of how to do this properly. I'm using DBD::Pg 0.93 and
postgres 7.02 on both NT and Linux. Thanks!
Dan
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 using the --to and --cc options:
reply via email
To: pgsql-interfaces@postgresql.org
Cc: rosner@cascadepg.com
Subject: Re: Inserting null values into a float4 field using Perl DBI
In-Reply-To: <39629D1A.E6C8B9CD@cascadepg.com>
* 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