COPY [ BINARY ] table [ WITH OIDS ] FROM { 'filename' | stdin } [ [USING] DELIMITERS 'delimiter' ] [ WITH NULL AS 'null string' ] COPY [ BINARY ] table [ WITH OIDS ] TO { 'filename' | stdout } [ [USING] DELIMITERS 'delimiter' ] [ WITH NULL AS 'null string' ]
×¢Ò⣺¶ÔÓÚ¿½±´È루copy in£©£¬ÈκÎÆ¥ÅäÕâ¸ö×Ö´®µÄ×Ö´®½«±»´æ´¢Îª NULL Öµ£¬ËùÒÔÄãÓ¦¸ÃÈ·±£ÄãÓõÄ×Ö´®ºÍ¿½±´³ö£¨copy out£©Ïàͬ¡£
ȱʡµØ£¬Îı¾¿½±´Ê¹Óà tab £¨"\t"£©×Ö·û×÷Ϊ·Ö¸ô·û£®·Ö¸ô·ûÈÔÈ»¿ÉÒÔÓùؼü×Ö USING DELIMITERS ¸Ä³ÉÈκÎÆäËüµÄ×Ö·û£®ÔÚÊý¾ÝÖÐÅöÇÉÓë·Ö¸ô·ûÏàͬµÄ×Ö·û½«ÓÃÒýºÅÒýÆð£®
Äã¶ÔÈκÎÒª COPY ³öÀ´µÄÊý¾Ý±ØÐëÓÐselectȨÏÞ£¬¶ÔÈκÎÒª COPY ÈëÊý¾ÝµÄ±í±ØÐëÓÐinserºÍupdateȨÏÞ£®Ê¹Óà COPY ʱºó¶ËͬÑùÐèÒªÊʵ±µÄ¶ÔÎļþ²Ù×÷µÄ Unix ȨÏÞ£®
¹Ø¼ü×Ö USING DELIMITERS ÉùÃ÷Ò»¸ö×÷ΪËùÓÐÁеķָô·ûµÄ×Ö·û£®Èç¹ûÔÚ·Ö¸ô·û×Ö´®ÀïÉùÃ÷Á˶à¸ö×Ö·û£¬Ö»Ê¹ÓõÚÒ»¸ö×Ö·û£®
С¼¼ÇÉ£º ²»Òª°Ñ COPY ºÍ psql µÄÃüÁî\copy »ìÏý£®COPY ²»»á¼¤»î¹æÔò£¬Ò²²»»á´¦Àí×Ö¶Îȱʡֵ¡£²»¹ýËüµÄÈ·¼¤»î´¥·¢Æ÷¡£
COPY ÔÚµÚÒ»¸ö´íÎó´¦Í£ÏÂÀ´£®ÕâЩÔÚ COPY FROM Öв»Ó¦¸Ãµ¼ÖÂÎÊÌ⣬µ«ÔÚ COPY TO ʱĿµÄ±í»á²¿·Ö¸Ä±ä£®Ó¦¸ÃÔÚÒ»´Îʧ°ÜµÄ¿½±´ºóÓà VACUUM ²éѯ×öһЩÇå³ý¹¤×÷£®
ÒòΪ Postgres ºó¶ËµÄ¹¤×÷Ŀ¼ͨ³£ºÍÓû§µÄ¹¤×÷Ŀ¼²»Ò»Ñù£¬±¾µØÓû§ÏòÒ»¸öÎļþ"foo"£¨Ã»Óи½¼ÓµÄ·¾¶ÐÅÏ¢£©¿ÉÄÜ»á²úÉú²»¿ÉÔ¤¼ûµÄ½á¹û£®Õâʱ£¬foo ½«Éú³ÉÔÚ $PGDATA/foo£® ͨ³££¬ÉùÃ÷¿½±´ÎļþʱҪ¼ÓÉÏÏà¶Ôºó¶Ë·þÎñÆ÷µÄȫ·¾¶£®
×÷Ϊ COPY ²ÎÊýÉùÃ÷µÄÎļþÃû±ØÐë´æÔÚÓëÊý¾Ý¿â·þÎñÆ÷¿É·ÃÎʵĵط½£¬²»¹ÜÊÇÔÚ±¾µØÓ²ÅÌ»¹ÊÇÔÚÍøÂçÎļþϵͳÉÏ£®
Èç¹ûʹÓÃÁËÒ»¸ö´Óһ̨»úÆ÷µ½Áíһ̨»úÆ÷µÄ TCP/IP Á¬½Ó£¬¶øÇÒÉùÃ÷ÁËÄ¿±êÎļþ£¬ÄÇôĿ±êÎļþ½«»áдµ½ºó¶ËÔËÐеĻúÆ÷ÉÏ£¬¶ø²»ÊÇÓû§µÄ»úÆ÷ÉÏ£®
ÿ¸ö¼Ç¼µÄʵ¼Ê¸ñʽÊÇ
<attr1><separator><attr2><separator>...<separator><attrn><newline>Èç¹ûÉùÃ÷ÁË WITH OIDST£¬Ëü½«±»·ÅÔÚÿÐеĿªÍ·£®
Èç¹û COPY ½«ËüµÄÊä³öÊä³öµ½±ê×¼Êä³ö¶ø²»ÊÇÒ»¸öÎļþ£¬ÔÚ¿½±´½áÊøʱ£¬Ëü½«ÔÚÒ»¸öÐÂÐÐÉÏÊä³öÒ»¸ö·´Ð±¸Ü£¨"\"£©ºÍÒ»¸ö¾äµã£¨"."£©£¬×îºóÊÇÒ»¸ö»»Ðзû×öΪÎļþ½áÊø·û£®ÀàËÆ£¬Èç¹û COPY ´Ó±ê×¼ÊäÈë¶ÁÈëÊý¾Ý£¬Ëü½«°ÑÒ»ÐпªÍ·µÄÓÉÒ»¸ö·´Ð±¸Ü£¨"\"£©ºÍÒ»¸ö¾äµã£¨"."£©ºÍÒ»¸ö»»Ðзû×é³ÉµÄÕâÈý¸öÁ¬Ðø×Ö·û×÷ΪÎļþ½áÊø·û£®²»¹ý£¬Èç¹ûÔÚÕâÈý¸ö×Ö·û×éºÏ֮ǰÅöµ½Ò»¸öÕæµÄEOF£¨Îļþ½áÊø·û£© COPY ½«½áÊø terminate £¨½ÓמÍÊǺó¶Ë×ÔÉí£©£®
б¸ÜÓÐÆäËûµÄº¬Ò壮NULLÊôÐÔÊä³öΪ"\N"£® Ò»¸ö·´Ð±¸Ü×Ö·ûÊä³ö³ÉÁ½¸öÁ¬ÐøµÄ·´Ð±¸Ü £¨"\\"£©Ò»¸ötab×Ö·ûÓÃÒ»¸ö·´Ð±¸ÜºóÃæ¸úÒ»¸ötab´ú±í£® Ò»¸öÐÂÐÐ×Ö·ûÓÃÒ»¸ö·´Ð±¸ÜºÍÒ»¸öÐÂÐдú±í£®µ±×°Ôز»ÊÇÓÉPostgres Éú³ÉµÄÎļþʱ£¬ÄãÐèÒª½«·´Ð±¸Ü×Ö·û £¨"\"£©×ª»»³ÉË«·´Ð±¸Ü£¨"\\"£©ÒÔ±£Ö¤ÕýÈ·×°ÔØ£®£
ÎļþÖÐÿһʵÀýµÄ¸ñʽÈçÏÂ±í£®Òª×¢Òâ±¾¸ñʽһ¶¨Òª ÍêÈ« ·ûºÏ£®ÎÞ·ûºÅµÄËÄ×Ö½ÚÕûÊýÊýÁ¿ÔÚϱíÖгÆ×ö uint32 £®
Îļþ¿ªÊ¼ | |
uint32 | ¼Ç¼¸öÊý |
ÿÌõ¼Ç¼ | |
uint32 | ¼Ç¼Êý¾Ý×ܳ¤ |
uint32 | oid £¨Èç¹ûÉùÃ÷ÁË£© |
uint32 | null ×ֶεĸöÊý |
[uint32,...,uint32] | ×ֶθöÊý£¨attribute numbers of attributes£©£¬ ´Ó0¿ªÊ¼ |
- | <×Ö¶ÎÊý¾Ý> |
COPY country TO stdout USING DELIMITERS '|';´ÓÒ»¸ö Unix ÎļþÖп½±´Êý¾Ýµ½±í "country"£º
COPY country FROM '/usr1/proj/bray/sql/country_data';ÕâÀïÊÇһЩ¿ÉÒÔ´Ó±ê×¼ÊäÈë stdin ÊäÈëµÄÊý¾ÝµÄÀý×Ó£¨ËùÒÔÔÚ×îºóÓнáÊø·û£©£º
AF AFGHANISTAN AL ALBANIA DZ ALGERIA ... ZM ZAMBIA ZW ZIMBABWE \.ͬÑùµÄÊý¾Ý£¬Êä³öµ½Ò»¸öLinux/i586»úÆ÷µÄ¶þ½øÖÆÎļþÖÐÈ¥£®Êý¾ÝÊÇÓà Unix Ó¦Óà od -c ÏÔʾµÄ£®±íÀïÓÐÈý¸öÓò£»µÚÒ»¸öÊÇchar(2) µÚ¶þ¸öÊÇ text£®ËùÓмǼÔÚµÚÈý×Ö¶ÎÓпգ¨null£©Öµ£®×¢Òâ char(2) ×Ö¶ÎÊÇÈçºÎÓÿգ¨null£©²¹Æë³ÉËĸö×Ö½ÚµÄÒÔ¼°text×Ö¶ÎÊÇÈçºÎÇ°Ãæ²¹³¤¶ÈµÄ£º
355 \0 \0 \0 027 \0 \0 \0 001 \0 \0 \0 002 \0 \0 \0 006 \0 \0 \0 A F \0 \0 017 \0 \0 \0 A F G H A N I S T A N 023 \0 \0 \0 001 \0 \0 \0 002 \0 \0 \0 006 \0 \0 \0 A L \0 \0 \v \0 \0 \0 A L B A N I A 023 \0 \0 \0 001 \0 \0 \0 002 \0 \0 \0 006 \0 \0 \0 D Z \0 \0 \v \0 \0 \0 A L G E R I A ... \n \0 \0 \0 Z A M B I A 024 \0 \0 \0 001 \0 \0 \0 002 \0 \0 \0 006 \0 \0 \0 Z W \0 \0 \f \0 \0 \0 Z I M B A B W E