Inserting null values into a float4 field using Perl DBI

From: Dan Rosner <rosner(at)cascadepg(dot)com>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: Inserting null values into a float4 field using Perl DBI
Date: 2000-07-05 02:27:38
Message-ID: 39629D1A.E6C8B9CD@cascadepg.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

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

Browse pgsql-interfaces by date

  From Date Subject
Next Message Peter Mount 2000-07-05 08:05:15 RE: Default mode for transaction in postgreSQL and J DBC
Previous Message Peter Eisentraut 2000-07-04 19:58:19 Re: Upper characters in database names