Re: How to bind a null value while using insert statements

"Harpreet Dhaliwal" <[email protected]>
Newsgroups gmane.comp.db.postgresql.dbdpg
Message-ID <[email protected]>
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 <[email protected]> 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* <[email protected]
> > <mailto:[email protected]>> 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
> >
> >
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.