まずテーブルを作成します。
create table myschema.product ( name varchar(10), price integer, stock integer );
続いてデータを挿入します
insert into product values ('Orange', 200, 12), ('Melon', 450, 6), ('Grape', 320, 8), ('Apple', 180, 14), ('Peach', 380, 5);
testdb=# select * from product;
name | price | stock
——–+——-+——-
Orange | 200 | 12
Melon | 450 | 6
Grape | 320 | 8
Apple | 180 | 14
Peach | 380 | 5
(5 rows)
testdb=# update product set price=340 where name=’Grape’;
UPDATE 1
testdb=# select * from product;
name | price | stock
——–+——-+——-
Orange | 200 | 12
Melon | 450 | 6
Apple | 180 | 14
Peach | 380 | 5
Grape | 340 | 8
testdb=# update product set price=price-50 where stock < 10; UPDATE 3 testdb=# select * from product; name | price | stock --------+-------+------- Orange | 200 | 12 Apple | 180 | 14 Melon | 400 | 6 Peach | 330 | 5 Grape | 290 | 8 (5 rows) 複数更新する場合も条件式でできるのね。