Updating multiple fields

Started by Joao Paulo Felixalmost 28 years ago3 messagesgeneral
Jump to latest
#1Joao Paulo Felix
felix@cyclades.com

Hello there,

I have the following fields description, info and title.
Is there a PostgreSQL query to update more than one field at the same
time?

Right now I have the following (I am using it with PHP, so please
desregard its code):

pg_Exec($conn, "UPDATE options SET description = '$description'
WHERE product = '$product' AND title = '$old_title';");

pg_Exec($conn, "UPDATE options SET info = '$info'
WHERE product = '$product' AND title = '$old_title';");

pg_Exec($conn, "UPDATE options SET title = '$title'
WHERE product = '$product' AND title = '$old_title';");

Ultimately I would like to have one single query. Is it possible?

Thanks in advance for your help/pointers.

Regards,

JP

--
________________________________________________________________

Joao Paulo Felix
Interactive Media Coordinator

Cyclades Corporation voice: (510) 770-9727
41934 Christy Street fax: (510) 770-0355
Fremont, CA www.cyclades.com
________________________________________________________________

#2Richard Lynch
lynch@lscorp.com
In reply to: Joao Paulo Felix (#1)
Re: [GENERAL] Updating multiple fields

At 10:20 AM 6/26/98, Joao Paulo Felix wrote:

Hello there,

I have the following fields description, info and title.
Is there a PostgreSQL query to update more than one field at the same
time?

Right now I have the following (I am using it with PHP, so please
desregard its code):

pg_Exec($conn, "UPDATE options SET description = '$description'
WHERE product = '$product' AND title = '$old_title';");

pg_Exec($conn, "UPDATE options SET info = '$info'
WHERE product = '$product' AND title = '$old_title';");

pg_Exec($conn, "UPDATE options SET title = '$title'
WHERE product = '$product' AND title = '$old_title';");

Hey! One I can answer!

typos may exist:

pg_Exec($conn, "UPDATE options SET description = '$description', info =
'$info', title = '$title' WHERE product = '$product' AND title =
'$old_title'");

Basically, you can have as many ", field = $value" entries as you like.

I also purposefully stripped off the ';' inside the string because
PostgreSQL doesn't need it, and some other database backend barfs when you
use it, so if you ever want to port, you don't want the ';' as part of the
SQL. Capiche?

--
--
-- "TANSTAAFL" Rich lynch@lscorp.com

#3Rob den Boer
rdboer@hrs-rotterdam.nl
In reply to: Joao Paulo Felix (#1)
RE: [GENERAL] Updating multiple fields

Hi Joao,

-----Original Message-----
From: owner-pgsql-general@hub.org [mailto:owner-pgsql-general@hub.org]On
Subject: [GENERAL] Updating multiple fields

How about this:

pg_Exec($conn, "UPDATE options SET description = '$description' , info =
'$info' , title = $title' WHERE product = '$product' AND title =
'$old_title';");

regards
Rob den Boer