Обсуждение: UPDATE Multiple Records At Once?

Поиск
Список
Период
Сортировка

UPDATE Multiple Records At Once?

От
Carlos Mennens
Дата:
I'm trying to update a customer record in a table however I need to
change several values (cust_address, cust_contact, cust_email). My
question is how do I properly format this into one single command?


forza=# SELECT cust_id, cust_name, cust_address, cust_contact, cust_email
forza-# FROM customers
forza-# WHERE cust_name = 'iamUNIX'
forza-# ; cust_id   | cust_name |     cust_address      |  cust_contact  |
cust_email
------------+-----------+-----------------------+----------------+--------------------1000000006 | MobileNX   | 200
SouthShore Drive | Carlos Mennens |
 
carlos@mobilenx.com
(1 row)

I did a quick Google search and I can see there is a method or
procedure which involves parenthesis () however I'm not sure how I
would change all the values listed above under one command. Can anyone
please give me a quick example so I can see how this is drawn out via
ANSI SQL?


Re: UPDATE Multiple Records At Once?

От
Thomas Kellerer
Дата:
Carlos Mennens wrote on 11.04.2012 19:50:
> I'm trying to update a customer record in a table however I need to
> change several values (cust_address, cust_contact, cust_email). My
> question is how do I properly format this into one single command?
>
>
> forza=# SELECT cust_id, cust_name, cust_address, cust_contact, cust_email
> forza-# FROM customers
> forza-# WHERE cust_name = 'iamUNIX'
> forza-# ;
>    cust_id   | cust_name |     cust_address      |  cust_contact  |
> cust_email
> ------------+-----------+-----------------------+----------------+--------------------
>   1000000006 | MobileNX   | 200 South Shore Drive | Carlos Mennens |
> carlos@mobilenx.com
> (1 row)
>
> I did a quick Google search and I can see there is a method or
> procedure which involves parenthesis () however I'm not sure how I
> would change all the values listed above under one command. Can anyone
> please give me a quick example so I can see how this is drawn out via
> ANSI SQL?
>

UPDATE customers   SET cust_address = 'foo',       cust_contact = 'Arthur',       cust_email = 'arthur@foo.bar'
WHERE cust_name = 'iamUNIX'



Re: UPDATE Multiple Records At Once?

От
lewbloch@gmail.com
Дата:
Carlos Mennens wrote:
> I'm trying to update a customer record in a table however I need to
> change several values (cust_address, cust_contact, cust_email). My
> question is how do I properly format this into one single command?
> 
> 
> forza=# SELECT cust_id, cust_name, cust_address, cust_contact, cust_email
> forza-# FROM customers
> forza-# WHERE cust_name = 'iamUNIX'
> forza-# ;
>   cust_id   | cust_name |     cust_address      |  cust_contact  |
> cust_email
> ------------+-----------+-----------------------+----------------+--------------------
>  1000000006 | MobileNX   | 200 South Shore Drive | Carlos Mennens |
> carlos@xx**xx.com
> (1 row)
> 
> I did a quick Google search and I can see there is a method or
> procedure which involves parenthesis () however I'm not sure how I
> would change all the values listed above under one command. Can anyone
> please give me a quick example so I can see how this is drawn out via
> ANSI SQL?

<http://www.postgresql.org/docs/9.1/static/sql-update.html>

-- 
Lew