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

COPY

劉䓄

COPY -- 婘臘启桺傽幋閘拙蘺昄扞

臺濘

COPY tablename [ ( column [, ...] ) ]
    FROM { 'filename' | STDIN }
    [ [ WITH ] 
          [ BINARY ]
          [ OIDS ]
          [ DELIMITER [ AS ] 'delimiter' ]
          [ NULL [ AS ] 'null string' ]
          [ CSV [ HEADER ]
                [ QUOTE [ AS ] 'quote' ] 
                [ ESCAPE [ AS ] 'escape' ]
                [ FORCE NOT NULL column [, ...] ]

COPY { tablename [ ( column [, ...] ) ] | ( query ) }
    TO { 'filename' | STDOUT }
    [ [ WITH ] 
          [ BINARY ]
          [ HEADER ]
          [ OIDS ]
          [ DELIMITER [ AS ] 'delimiter' ]
          [ NULL [ AS ] 'null string' ]
          [ CSV [ HEADER ]
                [ QUOTE [ AS ] 'quote' ] 
                [ ESCAPE [ AS ] 'escape' ]
                [ FORCE QUOTE column [, ...] ]

柟誄

COPY 婘臘启桺傽幋閘庴扵昄扞㔗COPY TO 檪婔婻臘䔇欔橬喙垹鄘拙蘺彄婔婻桺傽蔯 COPY FROM 傯婔婻桺傽麯拙蘺昄扞彄婔婻臘麯(檪昄扞鍇媹彄臘婺噾䂟庻婘䔇喙垹麯)㔗COPY TO 誻脘拙蘺 SELECT 昖臵䔇䂷悩㔗

套悩弄滯庖婔婻庖枕彖臘COPY 儖埻婘桺傽启臘幋閘拙蘺噾弄滯庖枕䔇昄扞㔗套悩臘婺橬傂嘘婉婘庖枕彖臘麯䔇庖枕闼幽 COPY FROM 儖婺闼底庖枕某噖䚺䩕唚㔗

婥桺傽劉䔇 COPY 毺䴺 PostgreSQL 橉媇単䕘毖傯桺傽婺臂喍昄扞㔗套悩弄滯庖桺傽劉闼幽橉媇単媙釂埇傖螪閞臖桺傽蔯婫桺傽劉媙釂傯橉媇単䔇蓐庥弄滯㔗套悩毺垔庖 STDINSTDOUT 闼幽昄扞儖婘垵潙嬉䆇启橉媇単幋閘敕媘㔗

埗昄

tablename

䯄庻臘䔇劉庖(埇傖橬昇嚟媞閄)

column

埇锬䔇写拙蘺庖枕彖臘㔗套悩澇橬弄滯庖枕彖臘闼幽儖嘪䫘欔橬庖枕㔗

query

婔婻媙釂䫘婖拸嚓寙啘䔇 SELECTVALUES 变傴噽䂷悩儖赆拙蘺㔗

filename

膷噖潡膷庺桺傽䔇䂺凹虇冇㔗Windows 䫘潙埇脘驔襕嘪䫘 E'' 庖严婾启埯埉桩亪嘩婺虇冇彖嬾严㔗

STDIN

弄滯膷噖滇準躻垵潙䆇庫䫘

STDOUT

弄滯膷噖嬉冔垵潙䆇庫䫘

BINARY

嘪䫘庯誕彽湚嚟庻嗘启臂埡蔯婉滇傖桺橸䔇桹嚟㔗婘庯誕彽昇嚟婋婉脘弄滯 DELIMITER, NULL, CSV 锬釹㔗

OIDS

弄滯婺懟臯拙蘺喙鄘凹茇湺臖(OID)㔗套悩婺婔婻 query 拙蘺潡蔙澇橬 OID 䔇臘弄滯庖 OIDS 锬釹彍檕庺婔婻髍臇㔗

delimiter

婘桺傽婺彖锫劇婻庖枕䔇剘婻庖严㔗婘桺橸昇嚟婋䚺䩕滇愘广彽臘严婘 CSV 昇嚟婋滇婔婻锖埙㔗

null string

認滇婔婻傼臘 NULL 唚䔇庖严婾㔗婘桺橸昇嚟婋䚺䩕滇 \N 婘 CSV 昇嚟婋滇婔婻澇橬嚘埙䔇 NULL 㔗套悩嘹婉愿寺彖 NULL 启䷺庖严婾闼幽剿嘪婘桺橸昇嚟婋嘹埇脘幘嚔嘪䫘婔婻䷺庖严婾㔗

㔊濘懟㔏婘嘪䫘 COPY FROM 䔇施唍傂嘘对陉認婻庖严婾䔇庖严婾儖赆庻嗘婺 NULL 唚欔傖嘹庫臖䇞媺嘹䫘䔇庖严婾启 COPY TO 䕩劯㔗

CSV

欷嚔锖埙彖锫埻麟(CSV)昇嚟

HEADER

弄滯桺傽寙劆婔婻湺鵻崘臯寙劆桺傽婺懟婻庖枕䔇劉庖㔗膷庺施丸婔臯寙劆臘䔇庖枕劉膷噖施丸婔臯赆媘䘖㔗

quote

弄滯 CSV 昇嚟麯䔇嚘埙庖严㔗䚺䩕滇埯嚘埙㔗

escape

弄滯婘 CSV 昇嚟婋庫臖庺䯄婘昄扞麯 QUOTE 庖严唚嬉麵䔇庖严㔗䚺䩕滇 QUOTE 唚(锔婩滇埯嚘埙)㔗

FORCE QUOTE

CSV COPY TO 昇嚟婋嚺彽婘懟婻弄滯䔇庖枕变啘凹欔橬麂 NULL 唚鄘嘪䫘嚘埙寙啘㔗NULL 膷庺傯婉嚔赆嚘埙寙啘㔗

FORCE NOT NULL

CSV COPY FROM 昇嚟婋檪弄滯䔇懟婻庖枕鄘嘷嘩垄傸橬嚘埙寙啘準崇䊖啹溴儌澇橬 NULL 唚㔗凹庯婘 CSV 昇嚟婋䔇䚺䩕䷺庖严婾('')認湙凚躘婔婻䚺崌䔇昄唚嘷嘩婔婻镽阪庖严婾膷噖㔗

膷庺

潊媘垯潊施COPY 毬䙓套婋湚嚟誫啂婔婻变傴湺了

COPY count

噽婺䔇 count 滇拙蘺䔇臯昄㔗

濘懟

COPY 埻脘䫘庯臘婉脘䫘庯蓖商㔗嘷䇽幘埇傖䫘庯 COPY (SELECT * FROM viewname) TO ...

BINARY 噿髞庖儖嚺彽嘪䫘庯誕彽凹茇蔯婉滇桺橸庻嗘/臂埡欔橬昄扞㔗認湙啔婘婔垔䘋庥婪懫嚹䂘䔇拙蘺变傴媆嘖庯誕彽拙蘺桺傽婘婉劯橺単嘷係启 PostgreSQL 䬽橸幋閘䔇䓂洉攓婉滇冽喘㔗

嘹凹傂嘘襕 COPY TO 庺準䔇昄扞媙釂橬锬埡昄扞䔇溄鍊凹傂嘘襕 COPY FROM 噖昄扞䔇臘媙釂橬某噖溄鍊㔗

COPY 变傴麯麵䔇桺傽媙釂滇䫌橉媇単䕘毖臂潡喍䔇桺傽蔯婉滇䫌垵潙䆇庫䫘臂喍㔗啹溴垄傸媙釂嘉庯昄扞康橉媇単婪潡蔙埇傖赆昄扞康橉媇単欔螪閞認底庋愙婉庫臖䫌垵潙䆇準啔㔗垄傸媙釂赆誊臯 PostgreSQL 橉媇単䔇䫘潙埇臂潡喍蔯婉滇垵潙䆇㔗埻噕螩昄扞康轙亓䫘潙 COPY 婔婻桺傽啹婺垄噕螩臂喍傂懟橉媇単橬溄鍊螪閞䔇桺傽㔗

婉襕晙晖 COPYpsql\copy 毺傴㔗\copy 脄䫘 COPY FROM STDINCOPY TO STDOUT 䇽劯檪昄扞檷埡/庻嗘彄婔婻 psql 垵潙䆇埇傖螪閞䔇桺傽婺㔗啹溴嘪䫘 \copy 䔇施唍桺傽螪閞溄鍊滇䫌垵潙䆇蔯婉滇橉媇単䆇喿垔䔇㔗

傺螞婘 COPY 麯䔇桺傽劉庖攂滇嘪䫘䂺凹虇冇㔗婘 COPY TO 䔇施唍滇䫌橉媇単嚺彽誕臯䔇嘖滇凹庯 COPY FROM 嘹䔇䇞埇傯婔婻䕩凹虇冇䔇桺傽麯臂埡㔗臖虇冇儖蓼麪婺䕩凹庯橉媇単䔇噖嘩䕞嘘(锔婩滇昄扞䕞嘘)蔯婉滇垵潙䆇䔇噖嘩䕞嘘㔗

COPY FROM 嚔檔昂欔橬蓥埏単启演昖亥溘㔗婉誺婉嚔檔昂蓇彍㔗

COPY 膷噖启膷庺赆 DateStyle 嘌巉㔗婺庖启噽垄 PostgreSQL 垬輙䓂洉(垄傸埇脘滇麂䚺䩕 DateStyle 螆䘞)庫臖婘嘪䫘 COPY TO 嬉檪 DateStyle 螆䘞婺 ISO

COPY 婘丸婔婻髍臇崇啩婋準㔗認底婘 COPY TO 婺婉庫臖凚躘閞鵻嘖婘 COPY FROM 施䕞湺臘嚔噾䂟毖櫽彄斷噽䔇臯認底臯儖婉埇蓕潡婉埇螪閞嘖滇傉䇽嚔剹扞伕䕻䷺閘㔗套悩嘹䵄噓拙蘺崓庖昄扞桺傽䔇臺認底婩薪䓇䘇蕙準埇脘嚔剹扞䕩嘷崓䔇伕䕻䷺閘㔗嘹埇傖脄䫘 VACUUM 準敵崉闼底伕䕻䷺閘㔗

桺傽湚嚟

桺橸湚嚟

嘷婉婥 BINARYCSV 锬釹嘪䫘 COPY 施臂喍䔇桺傽滇婔婻桺橸桺傽懟臯傼臘臘婺婔婻臯㔗臯婺䔇彖(庖枕)䫘彖锫严彖嚔㔗庖枕唚橸躆滇䫌婯懟婻庖枕䌂傋䕩噿䔇膷庺庘昄䫘潊䔇庖严婾潡蔙滇膷噖庘昄埇毖埖䔇庖严婾㔗昄扞婺嘪䫘䬹垔䔇 NULL 庖严婾臘䴺闼底唚婺 NULL 䔇庖枕㔗套悩膷噖桺傽䔇傂懟臯寙劆懫鵇橘崔潡蔙儏䔇庖枕闼幽 COPY FROM 儖檕庺婔婻髍臇㔗套悩弄滯庖 OIDS 闼幽 OID 儖嘩婺丸婔婻庖枕臂喍櫆婘欔橬䫘潙庖枕嬉麵㔗

昄扞䔇䂷溘埇傖䫘婔婻埻寙劆埉桩溹启埖䗹(\.)䔇臯臘䴺㔗套悩傯桺傽婺臂埡昄扞闼幽昄扞䂷溘䔇湺螄滇婉媙襕䔇啹婺桺傽䂷溘蕙䔇嘩䫘儌冽喘庖嘖滇婘 3.0 幋嬉䔇垵潙䆇剟螞麯套悩婘垵潙䆇庫䫘幋閘拙蘺昄扞闼幽媙釂襕橬䂷溘湺螄㔗

埉桩溹庖严(\)埇傖䫘婘 COPY 麯䂍闼底嚔橬溓幬䔇庖严誕臯锄锩(劥彍闼底庖严嚔赆嘷啔臯潡蔙庖枕彖锫严崇䊖)㔗䬹彆滇婋麵䔇庖严套悩滇庖枕唚䔇婔鄘彖施媙釂嬉䚔婔婻埉桩溹埉桩溹橸躆㔕扵臯严㔕啂蘥严㔕嘷嬉彖锫严㔗

弄滯䔇䷺庖严婾赆 COPY TO 婉媹傂嘘埉桩溹埏锕婯幋䕩凹COPY FROM 婘役鍴埉桩溹幋嬉拪垄䔇膷噖婯䷺庖严婾懫膄㔗啹溴償 \N 認湙䔇䷺庖严婾婉嚔启垂鍙昄扞唚 \N 幋閘晙晖(啹婺劯蔙嚔臘䯄潊 \\N)㔗

COPY FROM 脘崘臖彆婋彖䬹枪埉桩溹废彖

废彖劆幬
\b埉桩溹 (ASCII 8)
\f誕亩 (ASCII 12)
\n扵臯严 (ASCII 10)
\r啂蘥严 (ASCII 13)
\t愘广彽臘严 (ASCII 9)
\v傗䕘彽臘严 (ASCII 11)
\digits埉桩溹劯麵虘五婔彄婬婻噆誕彽昄臘䴺 ASCII 唚婺臖昄䔇庖严
\xdigits埉桩溹 x 劯麵虘五婔婻潡婴婻剕噺誕彽嘉弄滯毺垔昄唚䚡乕䔇庖严
䕞嬉COPY TO 䂺婉嚔埏庺婔婻噆誕彽潡蔙剕噺誕彽埉桩溹废彖嘖滇垄䔇䇞嘪䫘庖婪麵彖庺䔇噽垄庖严䫘庯毓彽庖严㔗

傂嘘婪臘彖庺幋崡䔇噽垄埉桩溹锄嘹庖严儖嘪䫘噽庖麵劆幬㔗啹溴襕償媄時媹婉媙襕䔇埉桩溹啹婺認湙啔埇脘嚔䫘潊婔婻劆橬昄扞䂷溘湺媖(\.)䔇庖严婾潡 NULL(邻螴婺 \N)㔗認底庖严婾儖婘臖彆傂嘘噽垄埉桩溹锄锩幋嬉赆臖彆㔗

嚺䄽傺螞䫘潊 COPY 昄扞䔇庫䫘檪扵臯严启啂蘥彖彆蘸扵潊 \n\r 废彖㔗䕞嬉埇傖䫘婔婻埉桩溹启婔婻啂蘥臘䴺婔婻昄扞啂蘥傖埪䫘婔婻埉桩溹启婔婻扵臯严臘䴺婔婻昄扞扵臯严㔗婉誺認湙䔇臘䴺婘儖準䔇䬽橸婺埇脘婉嚔赆毖埖㔗幽婫套悩婘婉劯橺単幋閘嚹锐 COPY 桺傽幘麂婩垹滷庺髍(懫套婘 Unix 启 Windows 幋閘)㔗

COPY TO 儖婘懟臯䔇䂷儆䫘婔婻扵臯严(Unix 婪滇"\n"Windows 婪滇"\r\n")湺螄婔臯䂽溵嘖埻滇䫘庯 COPY 彄橉媇単桺傽麯婺庖婘婉劯广埄幋閘婔躘COPY TO STDOUT 攂滇埏锕 "\n" 蔯婉䞇橉媇単广埄滇傔幽㔗COPY FROM 埇傖崇䊖闼底傖啂蘥严㔕扵臯严㔕啂蘥扵臯严嘩婺臯䂷溘䔇昄扞㔗婺庖废儏婘昄扞婺庺䯄䔇橻锄锩䔇桄臯潡蔙啂蘥凚躘䔇髍臇套悩膷噖䔇臯䂷儆婉償婪麵認底严埙COPY FROM 嚔埏庺躥只㔗

CSV 湚嚟

認婻湚嚟䫘庯膷噖启膷庺锖埙彖锫昄唚(CSV)桺傽湚嚟螩崔噽垄䘋废鄘䫘認婻桺傽湚嚟懫套䫕床檖臘㔗認婻昇嚟婋䫘潊幽臖彆锖埙彖锫䔇 CSV 锄锩橺彽蔯婉滇嘪䫘 PostgreSQL 湺庖桺橸昇嚟䔇锄锩㔗

懟溇螄嘘䔇唚鄘滇䫘 DELIMITER 庖严彖锫䔇㔗套悩昄唚橸躆寙劆彖锫庖严㔕QUOTE 庖严㔕NULL 庖严婾㔕啂蘥严㔕扵臯严闼幽昘婻昄唚䫘 QUOTE 庖严嬉䚔启劯䚔(寙啘)幽婫昄唚麯傂嘘 QUOTE 庖严潡 ESCAPE 庖严鄘嬉凚锄锩庖严㔗嘹幘埇傖嘪䫘 FORCE QUOTE 婘膷庺麂 NULL 䔇毺垔庖枕唚施嚺彽嚘埙寙啘㔗

CSV 湚嚟澇橬湺庖䔇媂濘寺彖婔婻 NULL 唚启婔婻䷺庖严婾㔗PostgreSQL 䔇 COPY 锔誺嚘埙寙啘準崇䊖認底㔗婔婻嘷嘩 NULL 膷庺䔇 NULL 唚滇澇橬嚘埙寙啘䔇蔯对陉 NULL 庖严婾䔇昄扞唚滇䫘嚘埙寙啘䔇㔗啹溴嘪䫘䚺䩕螆䘞施婔婻 NULL 滇喍啔婔婻方嚘埙寙啘䔇䷺庖严婾蔯婔婻䷺庖严婾喍啔埯嚘埙寙啘("")㔗臂埡昄唚幘镕冻䌂嚚䔇蓇彍㔗嘹埇傖嘪䫘 FORCE NOT NULL 準镪噉婺䬹垔庖枕誕臯 NULL 懫膄㔗

啹婺凹庯 CSV 湚嚟蔯蘔埉桩溹婉滇䬹枪庖严昄扞䔇䂷溘湺媖(\.)埇傖嘩婺昄扞唚庺䯄㔗婺庖镪噉傂嘘埇脘䔇溓懟婔婻剘䋸䔇 \. 昄扞唚婘膷庺婺儖赆躻媘嘪䫘嚘埙寙啘婘膷噖婺套悩赆嚘埙䘯垔闼幽儖婉嚔嘷嘩昄扞䂷溘湺媖㔗套悩嘹襕媹蘘噽垄䘋废录傺䔇㔕橬橻䫘嚘埙䘯垔庖枕䔇桺傽幽婫噽婺劆橬 \. 唚嘹儌媙釂䫘嚘埙誕臯䘯垔㔗

㔊濘懟㔏CSV 昇嚟婋欔橬庖严鄘滇橬昽䔇㔗婔婻赆䷺䍘寙啘䔇嚘埙䘯垔昄唚潡蔙傂嘘麂 DELIMITER 庖严鄘嚔赆寙劆認底庖严㔗套悩嘹傯嚔䂍 CSV 臯准噙䷺䍘䔇係䂘麯凚噖昄扞彄垔阪庖枕闼幽埇脘嚔凚躘髍臇㔗套悩庺䯄認䓉愙喕嘹埇脘驔襕噽崇䊖婔婋 CSV 桺傽役鍴䂷儆䷺䍘䇽劯喉劏 PostgreSQL 麯凚噖昄扞㔗

㔊濘懟㔏CSV 昇嚟埇傖臖彆启䫘潊嚘埙寙啘䔇啂蘥启扵臯䔇 CVS 桺傽㔗啹溴認底桺傽幽婉償桺橸昇嚟䔇桺傽闼湙婖湚婄懟溇螄嘘婔臯㔗

㔊濘懟㔏螩崔䘋废䫘潊喺攻䔇幽婫橬施唍婉溼䇞䔇 CVS 桺傽欔傖認婻桺傽湚嚟敘償婔䓉愇䫘湚嚟蔯婉滇婔䓉湺庖㔗啹溴嘹埇脘䵄彄婔底婉脘嘪䫘認婻橺彽膷噖䔇桺傽蔯 COPY 幘埇脘䫘潊婔底噽垄䘋废婉脘崇䊖䔇桺傽㔗

庯誕彽湚嚟

婘 PostgreSQL 7.4 婺 COPY BINARY 䔇桺傽湚嚟埏䫘庖埻寡㔗桄湚嚟䫌婔婻桺傽崘㔕镽潡崔溇臯㔕桺傽儆䂇潊㔗桺傽崘启昄扞䯄婘滇䘏䂩庖誗釺废㔗

桺傽崘

桺傽崘䫌 15 婻庖誗䔇啺垔嘘䂇潊劯麵虘五婔婻埻阪䔇崘欷匘寺㔗啺垔嘘滇

了劉

11 庖誗䔇废彖 PGCOPY\n\377\r\n\0(臙濘懟庖誗镽滇了劉媙釂䔇婔鄘彖)㔗嘪䫘認婻了劉滇婺庖脘崘冽垹滷䩋庺桺傽滇劥噾䂟赆婔婻麂 8 嘉垬噘䔇蘸扵単䂍乘废庖㔗認婻了劉嚔赆臯儆蘸扵誺悴単㔕役鍴庖誗镽㔕役鍴醻嘉㔕喺啽埻寡蔯櫹埻㔗

湺媖嘘

32 嘉昘昄毷乕臘䴺臖桺傽湚嚟䔇麉襕桹麵㔗嘉滇傯 0(LSB)彄 31(MSB)䚡乕䔇臙濘懟認婻嘘滇傖䘏䂩庖誗釺废庻嗘䔇(醻嘉婘嬉)劯䂓䔇昘昄鄘滇套溴㔗嘉 16-31 滇媺䘍䫘啔噿髞桺傽湚嚟媇敇䔇套悩黙臂単埏䯄婔婻婉螴臖䔇嘉庺䯄婘認婻评啘喙闼幽垄庫臖锔庺㔗嘉 0-15 鄘媺䘍婺湺媖劏劯噚垹䔇湚嚟嘪䫘黙臂単埇傖媘䘖認婻评啘喙䔇婉螴臖䔇嘉㔗䕞嬉埻垔幬庖婔婻湺媖嘉蔯噽垄䔇媙釂滇镽

Bit 16

套悩婺 1 闼幽婘昄扞婺寙拸庖 OID 套悩婺 0 彍澇橬㔗

崘欷匘评啘阪庥

32 嘉昘昄傖庖誗螇䔇崘嬷嘍阪庥婉寙拸躻躆㔗䕞嬉垄滇镽劯麵䘓虘丸婔溇螄嘘臯㔗凹臖湚嚟䔇敘崔媞櫹鄘儖噕螩鵺崡䔇昄扞庺䯄婘崘婺㔗黙臂単庫臖媘䘖傂嘘垄婉䘖長臖套嘘崇䊖䔇崘欷匘昄扞㔗

崘欷匘昄扞䫘準媺庻躻垔幬昄扞废彖庖㔗認婻湺媖嘘方懟只臬黙臂単欷匘寺䔇喙垹滇傔幽㔗崘欷匘䔇噙嘷螆螇喙垹䘍䂍傖劯䔇䬽橸嘪䫘㔗

認湙螆螇儌噕螩劏劯噚垹䔇崘欷匘(嵂媹崘欷匘庖潡螆䘞嘯嘉废湺媖嘉)傖埪麂劏劯噚垹䔇媞櫹(螆䘞醻嘉湺媖嘉傖湺臖認湙䔇媞櫹幽婫湹扞驔襕劏欷匘寺嘘嵂媹櫇毕昄扞)㔗

懟溇臯鄘傖婔婻 16 嘉昘昄螇昄嚔崘臖螇昄滇臯婺庖枕䔇昄䕞(䕞嬉婘婔婻臘麯䔇懟溇臯鄘橬䕩劯䔇螇昄嘖埇脘婉嚔愩誩認湙)㔗䇽劯劯麵婉桺庺䯄臯婺䔇劇婻庖枕庖枕噽滇婔婻 32 嘉䔇阪庥庖劯麵虘五闼幽阪䔇庖枕昄扞㔗阪庥庖幽婉寙拸躻噌幽婫埇傖婺镽㔗婔婻䬹冋滇-1 臘䴺婔婻 NULL 庖枕唚㔗婘 NULL 愙喕婋劯麵婉嚔虘五昄唚庖誗㔗

婘昄扞嘘幋閘澇橬凹阊准噙潡蔙傂嘘噽垄鵺崡䔇昄扞㔗

䕞嬉婔婻 COPY BINARY 桺傽麯䔇欔橬昄扞唚鄘啺螆滇庯誕彽湚嚟䔇(湚嚟傼乕婺婔)㔗鵇螇儖準䔇欷匘埇脘嵂媹婔婻崘嘘噕螩婺懟婻庖枕弄滯湚嚟傼乕㔗

婺庖彴桺垂鍙臯昄扞䔇溼䇞庯誕彽湚嚟嘹庫臖黙臂 PostgreSQL 溊傼乕䬹彆滇臖庖枕昄扞䌂傋䔇 *send*recv 庘昄(噩傋䔇庘昄埇傖婘溊傼乕䔇 src/backend/utils/adt/ 䕞嘘欆彄)㔗

套悩婘桺傽婺寙拸庖 OID 闼幽臖 OID 嘘䆋剿虘婘庖枕螇昄庖劯麵㔗垄滇婔婻捞锔䔇庖枕埻婉誺垄澇橬寙拸婘庖枕螇昄㔗嘖垄寙拸阪庥庖認湙儌噕螩桹冪䔇崇䊖 4 庖誗启 8 庖誗䔇 OID 幽婫套悩昊婻垽嚍噕螩 OID 滇埇锬䔇臺闼幽誻埇傖檪 OID 滆䴺潊䷺㔗

桺傽儆

桺傽儆寙拸媺庻五 -1 䔇婔婻 16 嘉昘昄庖㔗認湙儌冽垹滷婯婔溇臯䔇嘘螇昄庖䕩寺彖㔗

套悩婔婻嘘螇昄庖斵婉滇 -1 幘婉滇鵇橘䔇庖枕䔇昄䕞闼幽黙臂単庫臖檖髍㔗認湙儌柊冕庖凹婵崌婯昄扞劯準䔇鵺崡演昖㔗

冋床

婋麵䔇冋床檪婔婻臘拙蘺彄垵潙䆇嘪䫘䆡䕘溇(|)嘩婺嘘彖锫严

COPY country TO STDOUT WITH DELIMITER '|';

傯桺傽婺拙蘺昄扞彄 country 臘婺

COPY country FROM '/usr1/proj/bray/sql/country_data';

嘪䫘婔婻嚔赆躻媘役鍴䔇婘施臘檪'A'嚔崘䔇啘垽劉拙蘺彄婔婻桺傽麯

COPY (SELECT * FROM country WHERE country_name LIKE 'A%') TO '/usr1/proj/bray/sql/a_list_countries.copy';

婋麵滇婔婻埇傖傯 STDIN 婺拙蘺昄扞彄臘婺䔇冋床

AF      AFGHANISTAN
AL      ALBANIA
DZ      ALGERIA
ZM      ZAMBIA
ZW      ZIMBABWE

濘懟懟臯麯䔇䷺䍘垂鍙婪滇婔婻愘广彽臘严㔗

婋麵䔇滇劯湙䔇昄扞傖庯誕彽嘵嚟膷庺㔗認底昄扞滇䫘 Unix 噖噙 od -c 誺悴幋劯膷庺䔇㔗臖臘橬婬婻庖枕丸婔婻滇 char(2) 丸庯婻滇 text 丸婬婻滇 integer 㔗欔橬䔇臯婘丸婬婻嘘鄘滇婔婻 null 唚㔗

0000000   P   G   C   O   P   Y  \n 377  \r  \n  \0  \0  \0  \0  \0  \0
0000020  \0  \0  \0  \0 003  \0  \0  \0 002   A   F  \0  \0  \0 013   A
0000040   F   G   H   A   N   I   S   T   A   N 377 377 377 377  \0 003
0000060  \0  \0  \0 002   A   L  \0  \0  \0 007   A   L   B   A   N   I
0000100   A 377 377 377 377  \0 003  \0  \0  \0 002   D   Z  \0  \0  \0
0000120 007   A   L   G   E   R   I   A 377 377 377 377  \0 003  \0  \0
0000140  \0 002   Z   M  \0  \0  \0 006   Z   A   M   B   I   A 377 377
0000160 377 377  \0 003  \0  \0  \0 002   Z   W  \0  \0  \0  \b   Z   I
0000200   M   B   A   B   W   E 377 377 377 377 377 377

噚垹攓

SQL 湺庖麯澇橬 COPY 臺埖㔗

PostgreSQL 7.3 傖嬉嘪䫘婋麵䔇臺濘䯄婘傉䇽櫇毕

COPY [ BINARY ] tablename [ WITH OIDS ]
    FROM { 'filename' | STDIN }
    [ [USING] DELIMITERS 'delimiter' ]
    [ WITH NULL AS 'null string' ]

COPY [ BINARY ] tablename [ WITH OIDS ]
    TO { 'filename' | STDOUT }
    [ [USING] DELIMITERS 'delimiter' ]
    [ WITH NULL AS 'null string' ]

劯锔饡釕嬉誕
COMMIT PREPARED婪婔亓CREATE AGGREGATE