pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
how do i insert an empty string ?
3+ messages / 2 participants
[nested] [flat]

* how do i insert an empty string ?
@ 2002-10-15 10:01  Peter Galbavy <peter.galbavy@knowtion.net>
  0 siblings, 2 replies; 3+ messages in thread

From: Peter Galbavy @ 2002-10-15 10:01 UTC (permalink / raw)
  To: pgsql-sql

FAQ: A search yielded nothing explicit...

I have an INSERT statement:

INSERT INTO metadata (md5, origin, name, value)
              VALUES ('fd859f263bd0579935f2146a22d24f32', 'EXIF',
'UserComment', '')

but this fails (using Perl DBI, DBD::Pg) because $dbh->quote() returns two
single quotes, which fails because something along the way thinks this is a
single quote. I do NOT want to insert a NULL but an empty string...

(This is either doing a $dbh->do(...) or a prepare ... execute without
$dbh->quote())

Peter




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: how do i insert an empty string ?
@ 2002-10-15 10:03  Peter Galbavy <peter.galbavy@knowtion.net>
  parent: Peter Galbavy <peter.galbavy@knowtion.net>
  1 sibling, 0 replies; 3+ messages in thread

From: Peter Galbavy @ 2002-10-15 10:03 UTC (permalink / raw)
  To: Peter Galbavy <peter.galbavy@knowtion.net>; pgsql-sql

Sorry: 7.3 beta 2 on OpenBSD 3.2

Peter
----- Original Message -----
From: "Peter Galbavy" <peter.galbavy@knowtion.net>
To: <pgsql-sql@postgresql.org>
Sent: Tuesday, October 15, 2002 11:01 AM
Subject: [SQL] how do i insert an empty string ?


> FAQ: A search yielded nothing explicit...
>
> I have an INSERT statement:
>
> INSERT INTO metadata (md5, origin, name, value)
>               VALUES ('fd859f263bd0579935f2146a22d24f32', 'EXIF',
> 'UserComment', '')
>
> but this fails (using Perl DBI, DBD::Pg) because $dbh->quote() returns two
> single quotes, which fails because something along the way thinks this is
a
> single quote. I do NOT want to insert a NULL but an empty string...
>
> (This is either doing a $dbh->do(...) or a prepare ... execute without
> $dbh->quote())
>
> Peter
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: how do i insert an empty string ?
@ 2002-10-15 14:14  Jeff <threshar@torgo.978.org>
  parent: Peter Galbavy <peter.galbavy@knowtion.net>
  1 sibling, 0 replies; 3+ messages in thread

From: Jeff @ 2002-10-15 14:14 UTC (permalink / raw)
  To: Peter Galbavy <peter.galbavy@knowtion.net>; +Cc: pgsql-sql

On Tue, 15 Oct 2002, Peter Galbavy wrote:

> FAQ: A search yielded nothing explicit...
>
> I have an INSERT statement:
>
> INSERT INTO metadata (md5, origin, name, value)
>               VALUES ('fd859f263bd0579935f2146a22d24f32', 'EXIF',
> 'UserComment', '')
>
> but this fails (using Perl DBI, DBD::Pg) because $dbh->quote() returns two

Since you are using DBI, why not bind the variables and be done with it?

this would become
$query = $db->prepare("INSERT INTO metadata (md5, origin, name, value)
VALUES (?, ?, ?, ?)");
$query->execute($md5, $origin, $name, $value);

This way you don't have to deal with double quoting and all that. (You can
also call bind_param, but I find it easier to just pass args into execute)

------------------------------------------------------------------------------
Jeff Trout <jeff@jefftrout.com>                  http://www.jefftrout.com/
   Ronald McDonald, with the help of cheese soup,
       controls America from a secret volkswagon hidden in the past
-------------------------------------------------------------------------------





^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2002-10-15 14:14 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-10-15 10:01 how do i insert an empty string ? Peter Galbavy <peter.galbavy@knowtion.net>
2002-10-15 10:03 ` Peter Galbavy <peter.galbavy@knowtion.net>
2002-10-15 14:14 ` Jeff <threshar@torgo.978.org>

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