FAQ
Hi,

I have the following insert statement

insert into abc (a,b,c) values (?,?,?);

when i execute this insert (in perl) i get the following error

Cannot bind a reference (ARRAY(0x925069c)) ((null))

This is because value of column a is defined but null
So how should in bind null value in my insert statement?

Thanks,
Harpreet

Search Discussions

  • Andrew Dunstan at Jan 22, 2007 at 5:13 pm

    Harpreet Dhaliwal wrote:
    Hi,

    I have the following insert statement

    insert into abc (a,b,c) values (?,?,?);

    when i execute this insert (in perl) i get the following error

    Cannot bind a reference (ARRAY(0x925069c)) ((null))

    This is because value of column a is defined but null
    So how should in bind null value in my insert statement?
    For a null value you pass undef - see the DBI docs.

    cheers

    andrew
  • Harpreet Dhaliwal at Jan 22, 2007 at 5:21 pm
    can you please give me some quick pointers in dbi docs?
    thanks,
    ~Harpreet
    On 1/22/07, Andrew Dunstan wrote:

    Harpreet Dhaliwal wrote:
    Hi,

    I have the following insert statement

    insert into abc (a,b,c) values (?,?,?);

    when i execute this insert (in perl) i get the following error

    Cannot bind a reference (ARRAY(0x925069c)) ((null))

    This is because value of column a is defined but null
    So how should in bind null value in my insert statement?
    For a null value you pass undef - see the DBI docs.

    cheers

    andrew
  • Andrew Dunstan at Jan 22, 2007 at 5:38 pm
    perldoc DBI says:

    NULL Values

    Undefined values, or "undef", are used to indicate NULL values. You
    can insert and update columns with a NULL value as you would a
    non-NULL
    value. These examples insert and update the column "age" with a NULL
    value:

    $sth = $dbh->prepare(qq{
    INSERT INTO people (fullname, age) VALUES (?, ?)
    });
    $sth->execute("Joe Bloggs", undef);

    $sth = $dbh->prepare(qq{
    UPDATE people SET age = ? WHERE fullname = ?
    });
    $sth->execute(undef, "Joe Bloggs");


    cheers

    andrew

    Harpreet Dhaliwal wrote:
    can you please give me some quick pointers in dbi docs?
    thanks,
    ~Harpreet

    On 1/22/07, *Andrew Dunstan* wrote:

    Harpreet Dhaliwal wrote:
    Hi,

    I have the following insert statement

    insert into abc (a,b,c) values (?,?,?);

    when i execute this insert (in perl) i get the following error

    Cannot bind a reference (ARRAY(0x925069c)) ((null))

    This is because value of column a is defined but null
    So how should in bind null value in my insert statement?
    For a null value you pass undef - see the DBI docs.

    cheers

    andrew
  • Harpreet Dhaliwal at Jan 22, 2007 at 5:50 pm
    Actually the thing is that sometimes the value can be null and sometimes it
    can have a value depending.
    How should I take care of this situation.

    I mean $abc can and can't be null.
    Simple passing undef for it would mean a null value being pased and i think
    the code would for a situation when it doesn't have a null value. Right?

    Also, can you please copy paste the URL where from u gave me the previous
    info?

    Thanks,
    ~Harpreet.
    On 1/22/07, Andrew Dunstan wrote:


    perldoc DBI says:

    NULL Values

    Undefined values, or "undef", are used to indicate NULL
    values. You
    can insert and update columns with a NULL value as you would a
    non-NULL
    value. These examples insert and update the column "age" with a
    NULL
    value:

    $sth = $dbh->prepare(qq{
    INSERT INTO people (fullname, age) VALUES (?, ?)
    });
    $sth->execute("Joe Bloggs", undef);

    $sth = $dbh->prepare(qq{
    UPDATE people SET age = ? WHERE fullname = ?
    });
    $sth->execute(undef, "Joe Bloggs");


    cheers

    andrew

    Harpreet Dhaliwal wrote:
    can you please give me some quick pointers in dbi docs?
    thanks,
    ~Harpreet

    On 1/22/07, *Andrew Dunstan* <andrew@dunslane.net
    wrote:

    Harpreet Dhaliwal wrote:
    Hi,

    I have the following insert statement

    insert into abc (a,b,c) values (?,?,?);

    when i execute this insert (in perl) i get the following error

    Cannot bind a reference (ARRAY(0x925069c)) ((null))

    This is because value of column a is defined but null
    So how should in bind null value in my insert statement?
    For a null value you pass undef - see the DBI docs.

    cheers

    andrew
  • Andrew Dunstan at Jan 22, 2007 at 7:37 pm
    As long as the value in $abc is undef it will be fine. It's only the
    value that matters, not the symbol.

    Your system should have perl documentation installed. If it doesn't,
    stop right now and get the docs. that's where I got the info from, not
    from a URL.

    cheers

    andrew

    Harpreet Dhaliwal wrote:
    Actually the thing is that sometimes the value can be null and
    sometimes it can have a value depending.
    How should I take care of this situation.

    I mean $abc can and can't be null.
    Simple passing undef for it would mean a null value being pased and i
    think the code would for a situation when it doesn't have a null
    value. Right?

    Also, can you please copy paste the URL where from u gave me the
    previous info?

    Thanks,
    ~Harpreet.

    On 1/22/07, *Andrew Dunstan* wrote:


    perldoc DBI says:

    NULL Values

    Undefined values, or "undef", are used to indicate NULL
    values. You
    can insert and update columns with a NULL value as you would a
    non-NULL
    value. These examples insert and update the column "age"
    with a NULL
    value:

    $sth = $dbh->prepare(qq{
    INSERT INTO people (fullname, age) VALUES (?, ?)
    });
    $sth->execute("Joe Bloggs", undef);

    $sth = $dbh->prepare(qq{
    UPDATE people SET age = ? WHERE fullname = ?
    });
    $sth->execute(undef, "Joe Bloggs");


    cheers

    andrew

    Harpreet Dhaliwal wrote:
    can you please give me some quick pointers in dbi docs?
    thanks,
    ~Harpreet

    On 1/22/07, *Andrew Dunstan* <andrew@dunslane.net
    wrote:

    Harpreet Dhaliwal wrote:
    Hi,

    I have the following insert statement

    insert into abc (a,b,c) values (?,?,?);

    when i execute this insert (in perl) i get the following error

    Cannot bind a reference (ARRAY(0x925069c)) ((null))

    This is because value of column a is defined but null
    So how should in bind null value in my insert statement?
    For a null value you pass undef - see the DBI docs.

    cheers

    andrew
  • Mark Stosberg at Jan 22, 2007 at 5:15 pm

    Harpreet Dhaliwal wrote:
    Hi,

    I have the following insert statement

    insert into abc (a,b,c) values (?,?,?);

    when i execute this insert (in perl) i get the following error

    Cannot bind a reference (ARRAY(0x925069c)) ((null))

    This is because value of column a is defined but null
    So how should in bind null value in my insert statement?
    Harpreet,

    I don't think there is any special treatment when binding null values. I
    suspect there is a bug elsewhere in your code.

    I believe this should work:

    $dbh->do(
    "insert into abc (a,b,c) values (?,?,?)", {}, undef,undef,undef);


    Mark
  • Harpreet Dhaliwal at Jan 22, 2007 at 5:18 pm
    I'm using DBD:pg 1.49.
    Thats the only code I have for testing purpose.

    Thanks,
    Jas
    On 1/22/07, David E. Wheeler wrote:
    On Jan 22, 2007, at 7:25 AM, Harpreet Dhaliwal wrote:

    Cannot bind a reference (ARRAY(0x925069c)) ((null))

    This is because value of column a is defined but null
    So how should in bind null value in my insert statement?
    Can you paste some example code? Also, what versions of DBI and
    DBD::Pg are you using? DBI 1.51 fixed an issue with undefs in calls
    to bin_col().

    http://search.cpan.org/dist/DBI/Changes#Changes_in_DBI_1.51_
    (svn_rev_6475)%2C_6th_June_2006

    Best,

    David
  • David E. Wheeler at Jan 22, 2007 at 5:39 pm

    On Jan 22, 2007, at 09:18, Harpreet Dhaliwal wrote:

    I'm using DBD:pg 1.49.
    Thats the only code I have for testing purpose.
    Can you paste an example of the code that's giving you trouble?

    Best,

    David

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdbd-pg @
categoriesperl
postedJan 22, '07 at 3:26p
activeJan 22, '07 at 7:37p
posts9
users4
websiteperl.org

People

Translate

site design / logo © 2022 Grokbase