quoting values magic

From: Brandon Metcalf <brandon(at)geronimoalloys(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: quoting values magic
Date: 2009-05-22 19:54:04
Message-ID: Pine.LNX.4.58L.0905221445090.17654@cedar.geronimoalloys.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Assume I have an UPDATE statement that looks like

UPDATE foo
SET
pattern = '$pattern',
shape = '$shape',
length = $length,
comment = '$comment'
WHERE foo_id = $foo_id

and length is defined as NUMERIC. Is there any kind of magic that
would allow me to use the SQL above as is even if $length is not
defined? In other words, I'd like to avoid having to modify the SQL
to include or not include "length = $length" based on whether or not
$length is defined as it's acceptable for it to be NULL in foo.

I can't say "length = '$length'" as '' is not valid input for NUMERIC.

Hope that makes sense?

Thanks.

--
Brandon

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2009-05-22 19:56:26 Re: I can't drop a user if I don't drop his grants beforehand??????????????????
Previous Message Mark Watson 2009-05-22 19:41:19 duplicate rows in query