¾¤Î¥Ð¡¼¥¸¥ç¥ó¤Îʸ½ñ ¡§ 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9.6 | 9.5 | 9.4 | 9.3 | 9.2 | 9.1 | 9.0 | 8.4 | 8.3 | 8.2 | 8.1 | 8.0 | 7.4 | 7.3 | 7.2

UPDATE

Name

UPDATE  --  ¥Æ¡¼¥Ö¥ë¤Î¹Ô¤ò¹¹¿·¤¹¤ë¡£

Synopsis

UPDATE [ ONLY ] table SET col = expression [, ...]
    [ FROM fromlist ]
    [ WHERE condition ]

ÆþÎÏ

table

´û¸¥Æ¡¼¥Ö¥ë¤Î̾Á°¤Ç¤¹¡£

column

tableÆâ¤ÎÎó̾¤Ç¤¹¡£

expression

Îó¤ËÂåÆþ¤¹¤ëÍ­¸ú¤Ê¡¢¼°¤Þ¤¿¤ÏÃͤǤ¹¡£

fromlist

WHERE¾ò·ï¤Ë¾¤Î¥Æ¡¼¥Ö¥ë¾å¤ÎÎó¤ò»ØÄê¤Ç¤­¤ë¤è¤¦¤Ë¤¹¤ë PostgreSQL¤ÎÈóɸ½àŪ³ÈÄ¥¤Ç¤¹¡£

condition

WHERE¶ç¤Î¾ÜºÙ¤ÊÀâÌÀ¤Ë¤Ä¤¤¤Æ¤ÏSELECTʸ¤ò»²¾È¤·¤Æ²¼¤µ¤¤¡£

½ÐÎÏ

UPDATE #

À®¸ù¤·¤¿»þ¤ËÊÖ¤µ¤ì¤ë¥á¥Ã¥»¡¼¥¸¤Ç¤¹¡£ #¤Ï¹¹¿·¤µ¤ì¤¿¹Ô¿ô¤ò°ÕÌ£¤·¤Þ¤¹¡£#¤¬0¤Î¾ì¹ç¤Ï¹¹¿·¤µ¤ì¤¿¹Ô¤¬¤Ê¤«¤Ã¤¿¤³¤È¤ò°ÕÌ£¤·¤Þ¤¹¡£

ÀâÌÀ

UPDATE ¤Ï¡¢¾ò·ï¤òËþ¤¿¤¹Á´¤Æ¤Î¹Ô¤Î»ØÄꤵ¤ì¤¿Îó¤ÎÃͤòÊѹ¹¤·¤Þ¤¹¡£Êѹ¹¤µ¤ì¤ë¤Ù¤­Îó¤Î¤ß¤¬Ê¸Æâ¤Îcolumns¥Ñ¥é¥á¡¼¥¿¤Ë¤¢¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£

SELECT ¤ÈƱ¤¸¹½Ê¸¤ò»È¤Ã¤ÆÇÛÎó¤ò»²¾È¤·¤Þ¤¹¡£¤Ä¤Þ¤ê¡¢1¤Ä¤ÎÇÛÎóÍ×ÁǤ⡢¤¢¤ëÈϰϤˤ錄¤ëÇÛÎóÍ×ÁǤ⡢ÇÛÎóÁ´ÂΤâ1¤Ä¤ÎÌ䤤¹ç¤ï¤»¤Ç¹¹¿·¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£

¥Æ¡¼¥Ö¥ë¤òÊѹ¹¤¹¤ë¤¿¤á¤Ë¤Ï½ñ¤­¹þ¤ß¸¢¸Â¤¬É¬ÍפǤ¹¡£¤¢¤ï¤»¤Æ¡¢WHERE¾ò·ïÆâ¤Ç»ØÄꤷ¤¿Ãͤò»ý¤Ä¥Æ¡¼¥Ö¥ë¤Ø¤ÎÆɤ߹þ¤ß¸¢¸Â¤âɬÍפˤʤê¤Þ¤¹¡£

¥Ç¥Õ¥©¥ë¥È¤Ç¡¢UPDATE¤Ï»ØÄꤵ¤ì¤¿¥Æ¡¼¥Ö¥ë¤È¤½¤Î¥µ¥Ö¥Æ¡¼¥Ö¥ë¤Î¥¿¥×¥ë¤ò¹¹¿·¤·¤Þ¤¹¡£»ØÄꤵ¤ì¤¿¥Æ¡¼¥Ö¥ë¤Î¤ß¤ò¹¹¿·¤·¤¿¤¤¾ì¹ç¤ÏONLY¶ç¤ò»ÈÍѤ·¤Æ²¼¤µ¤¤¡£

»ÈÍÑÊýË¡

kind Îó¾å¤Î Drama ¤È¤¤¤¦Ã±¸ì¤ò Dramatic ¤ËÊѹ¹¤·¤Þ¤¹¡£

UPDATE films 
SET kind = 'Dramatic' 
WHERE kind = 'Drama';
SELECT * 
FROM films 
WHERE kind = 'Dramatic' OR kind = 'Drama';

 code  |     title     | did | date_prod  |   kind   | len
-------+---------------+-----+------------+----------+-------
 BL101 | The Third Man | 101 | 1949-12-23 | Dramatic | 01:44
 P_302 | Becket        | 103 | 1964-02-03 | Dramatic | 02:28
 M_401 | War and Peace | 104 | 1967-02-12 | Dramatic | 05:57
 T_601 | Yojimbo       | 106 | 1961-06-16 | Dramatic | 01:50
 DA101 | Das Boot      | 110 | 1981-11-11 | Dramatic | 02:29

¸ß´¹À­

SQL92

SQL92¤Ç¤Ï°ÌÃÖÉÕ¤±·¿UPDATEʸÍѤΰۤʤ빽ʸ¤òÄêµÁ¤·¤Æ¤¤¤Þ¤¹¡£

UPDATE table SET column = expression [, ...]
    WHERE CURRENT OF cursor

¤³¤³¤Ç¡¢cursor¤Ï¥ª¡¼¥×¥óºÑ¤Î¥«¡¼¥½¥ë¤Î¼±Ê̻ҤǤ¹¡£