PostgreSQL 8.2.3 婺桺桺懼
劯锔媆锔媆誕嬉誕

VALUES

劉䓄

VALUES -- 螇䞖婔婻潡婔䂇臯

臺濘

VALUES ( expression [, ...] ) [, ...]
    [ ORDER BY sort_expression [ ASC | DESC | USING operator ] [, ...] ]
    [ LIMIT { count | ALL } ]
    [ OFFSET start ]

柟誄

VALUES 湹扞䂍垔䔇唚臘膆嚟螇䞖婔婻潡婔䂇臯䔇唚㔗垄锔婩䫘庯婘婔婻膄崓䔇变傴喙䫘潊婔婻"婩昄臘"嘷劯施垄幘埇傖䫘庯躻躆㔗

套悩毺垔庖崔臯闼幽懟婔臯鄘媙釂拖橬䕩劯䔇噄䘹婻昄㔗䂷悩臘庖枕䔇昄扞䌂傋儖湹扞臘膆嚟䔇滯䇞潡锊劆䔇昄扞䌂傋䇞垔嘪䫘䔇蓇彍婯 UNION(誗10.5)䕩劯㔗

婘崓变傴麯麵VALUES 噕螩庺䯄婘傂嘘 SELECT 埇傖庺䯄䔇婄桹㔗啹婺垄婘臺濘婪麂婩䌂嚚庯 SELECT 埇傖婘 VALUES 变傴婺嘪䫘 ORDER BY, LIMIT, OFFSET 床埖㔗

埗昄

expression

䫘庯某噖䂷悩臘毺垔婄䗹䔇婩麟潡蔙臘膆嚟㔗婘婔婻庺䯄婘 INSERT 釽北䔇 VALUES 彖臘婺expression 埇傖赆 DEFAULT 敪扵傖臘䴺某噖䕞䔇庖枕䔇䚺䩕唚㔗鍴溴傖崡嘷 VALUES 庺䯄婘噽傡婺劽䔇施唍滇婉脘嘪䫘 DEFAULT 䔇㔗

sort_expression

婔婻臘䴺套嘘毐废䂷悩臯䔇臘膆嚟潡蔙昘昄婩麟㔗認婻臘膆嚟埇傖毬䙓 column1, column2 京京嚘䫘 VALUES 䔇䂷悩彖㔗敘崔䂖誗埗蓕 ORDER BY 床埖

operator

婔婻毐废淉嘩严㔗敘崔䂖誗埗蓕 ORDER BY 床埖

count

誫啂䔇橔崓臯昄㔗敘崔䂖誗埗蓕 LIMIT 床埖

start

婘嚔哋誫啂臯幋嬉虿誺䔇臯昄㔗敘崔䂖誗埗蓕 LIMIT 床埖

濘懟

庫嘷镪噉嘪䫘 VALUES 誫啂昄麟麂婩崓䔇䂷悩臯劥彍埇脘嚔镺镺喙庻蔖儘潡蔙攓脘嘯婋㔗庺䯄婘 INSERT 婺䔇 VALUES 滇婔婻䬹枪愙喕啹婺䕞湺庖枕䌂傋埇傖傯 INSERT 䔇䕞湺臘诙䘖幽婉驔襕锔誺欆柟 VALUES 彖臘準毘敋欔傖婘溴愙喕婋埇傖崇䊖麂婩崓䔇䂷悩臯㔗

冋床

婔婻噬䓄䓄䔇 VALUES 变傴

VALUES (1, 'one'), (2, 'two'), (3, 'three');

認儖誫啂婔婻婬臯婴彖䔇臘垄婘昽悩婪䕩嘷庯

SELECT 1 AS column1, 'one' AS column2
UNION ALL
SELECT 2, 'two'
UNION ALL
SELECT 3, 'three';

锔婩VALUES 嚔䫘庯婔婻崓 SQL 变傴婺橔婩蓕䔇滇䫘庯 INSERT 变傴

INSERT INTO films (code, title, did, date_prod, kind)
    VALUES ('T_601', 'Yojimbo', 106, '1961-06-16', 'Drama');

婘䫘庯 INSERT 施VALUES 彖臘婺䔇釹埇傖嘪䫘 DEFAULT 準臘䴺嘪䫘庖枕䔇䚺䩕唚

INSERT INTO films VALUES
    ('UA502', 'Bananas', 105, DEFAULT, 'Comedy', '82 minutes'),
    ('T_601', 'Yojimbo', 106, DEFAULT, 'Drama', DEFAULT);

VALUES 誻埇傖䫘庯床 SELECT 埇傖庫䫘䔇婺劽㔗懫套婘婔婻 FROM 床埖婺

SELECT f.*
  FROM films f, (VALUES('MGM', 'Horror'), ('UA', 'Sci-Fi')) AS t (studio, kind)
  WHERE f.studio = t.studio AND f.kind = t.kind;

UPDATE employees SET salary = salary * v.increase
  FROM (VALUES(1, 200000, 1.2), (2, 400000, 1.4)) AS v (depno, target, increase)
  WHERE employees.depno = v.depno AND employees.sales >= v.target;

VALUES 䫘庯 FROM 床埖婺䔇施唍媙釂嘪䫘 AS 床埖認婯䫘庯 SELECT 施婔湙㔗幽婉襕挗 AS 床埖婺懟婻庖枕鄘毺垔婔婻彆劉嘖滇認湙啔滇婔婻喘幹愇㔗PostgreSQL 婺 VALUES 䚺䩕䔇庖枕劉滇 column1, column2 京京嘖認底䚺䩕䔇劉庖幽婉婔垔婯噽傡昄扞康係䂘䕩劯㔗

VALUES 䫘庯 INSERT 䔇施唍欔橬䔇唚鄘儖毬䙓䕞湺庖枕躻媘啔䌂傋蘸扵㔗嘖滇婘噽傡婺劽儌埇脘媙釂滯䇞毺垔敄嘷䔇昄扞䌂傋㔗套悩欔橬䔇釹鄘滇嚘埙寙啘䔇庖麵婩麟嚺彽毺垔丸婔婻䌂傋儌埇傖䇞垔欔橬䔇䌂傋

SELECT * FROM machines
WHERE ip_address IN (VALUES('192.168.0.1'::inet), ('192.168.0.10'), ('192.168.1.43'));

㔊柊䴺㔏 凹庯䞔剘䔇 IN 敋臘敘喘䔇桹濘滇冺蕡庯 IN 䔇湺麟彖臘嘵嚟蔯婉滇嘪䫘婪誄 VALUES 昖臵㔗湺麟彖臘䔇桹濘喍䔇敘儏蔯婫锔婩幘敘橬昽㔗

噚垹攓

VALUES 严劽 SQL 湺庖溴崡LIMITOFFSET 滇 PostgreSQL 欷匘㔗

埽蓕

INSERT, SELECT

劯锔饡釕嬉誕
VACUUM婪婔亓PostgreSQL 垵潙䆇庫䫘䘋废