psql
psql ¡ª
PostgreSQL
½»»¥ÖÕ¶Ë
Óï·¨
psql [ options ] [ dbname [ user ] ]
¸ÅÊö
psql ÊÇÒ»¸öÒÔ»ùÓÚÖն˵Ä
PostgreSQL
Ç°¶Ë¡£ËüÔÊÐíÄã½»»¥µØÊäÈë²éѯ£¬½«ËüÃÇÌá½»¸ø
PostgreSQL
È»ºóÔĶÁ²éѯ½á¹û£®ÊäÈëÒ²¿ÉÒÔÀ´×ÔÒ»¸öÎļþ¡£ÁíÍ⣬Ëü»¹ÌṩһЩרÓÐÃüÁmeta-commands£©ºÍÐí¶àÀàËÆ
shell ·ç¸ñµÄÌØÐÔ¹©ÄãÊéд½Å±¾ºÍÍê³É·Ç³£¹ã·ºÈÎÎñµÄ×Ô¶¯»¯¹¤×÷¡£
ÃèÊö
ÓëÒ»¸öÊý¾Ý¿âÁª½Ó
psql ÊÇÒ»¸öÆÕͨµÄ
Postgres
¿Í»§¶ËÓ¦Óá£ÎªÁËÓëÒ»¸öÊý¾Ý¿âÁª½Ó£¬ÄãÐèÒªÖªµÀÄãµÄÄ¿±êÊý¾Ý¿â£¬·þÎñÆ÷µÄÖ÷»úÃûºÍ¶Ë¿ÚºÅÒÔ¼°ÄãÏ£ÍûÒÔÄĸöÓû§µÄÉí·Ý½øÐÐÁª½ÓµÈÐÅÏ¢¡£ÎÒÃÇ¿ÉÒÔͨ¹ýÃüÁîÐвÎÊý¸æËß
psql
ÕâЩÐÅÏ¢£¬·Ö±ðÊÇ
-d£¬
-h£¬
-p£¬ºÍ
-U¡£Èç¹ûÓиö²ÎÊý²»ÊôÓÚÈκÎÑ¡Ï¹Ø£¬ÄÇôËü»á±»½âÊͳÉÊý¾Ý¿âÃû£¨»òÕßÊÇÓû§Ãû£Èç¹ûÊý¾Ý¿âÃû³ÆÒ²¸ø³öÁË£®£©¡£²»ÊÇËùÓÐÕâЩѡÏÊDZØÐëµÄ£¬È±Ê¡µÄÒ²¿ÉÒÔ¡£Èç¹ûÄãÊ¡ÂÔÖ÷»úÃû£¬psql
½«Í¨¹ýÓòÌ×½Ó×ÖÓë±¾µØÖ÷»úµÄ·þÎñÆ÷ÏàÁª¡£È±Ê¡µÄ¶Ë¿ÚºÅÊDZàÒëʱȷ¶¨µÄ¡£ÒòΪÊý¾Ý¿â·þÎñÆ÷ʹÓÃͬÑùµÄȱʡֵ£¬ËùÒÔÔÚ´ó¶àÊýÉèÖÃÏ£¬Äã¿ÉÄܲ»ÐèÒªÉùÃ÷¶Ë¿ÚºÅ¡£È±Ê¡µÄÓû§ÃûÊÇÄãµÄ
Unix Óû§Ãû£¬ÓëÊý¾Ý¿âͬÃû¡£Òª×¢ÒâµÄÊÇÄã²»ÄÜÓÃÈÎÒâÓû§ÃûÓëÈκÎÊý¾Ý¿âÏàÁª¡£ÄãµÄÊý¾Ý¿â¹ÜÀíÔ±Ó¦¸Ã¸æËßÄãÄãµÄ·ÃÎÊȨÏÞ¡£Äã¿ÉÒÔͨ¹ýÉèÖü¸¸ö»·¾³±äÁ¿
PGDATABASE£¬
PGHOST£¬
PGPORT£¬
PGUSER
Ϊ¶ÔÓ¦µÄÖµµÄ·½·¨½ÚÔ¼¼¸´ÎÇû÷¡£
Èç¹ûÒòΪÈκÎÔÒò¶øÎÞ·¨ÓëÊý¾Ý¿âÏàÁª£¨ÀýÈ磬ȨÏÞ²»¹»£¬postmaster ûÓÐÔËÐеȣ©£¬psql
½«·µ»ØÒ»¸ö´íÎó²¢Í˳ö¡£
ÊäÈë²éѯ
ͨ³£×´¿öÏ£¬
psql Ìṩһ¸ö´øÓÐ
psql
ÕýÔÚÓëÖ®Áª½ÓµÄ½ÓÊý¾Ý¿âÃûµÄ£¬ºó׺ "=>" µÄÌáʾ·û£®ÀýÈ磬
$ psql testdb
Welcome to psql, the PostgreSQL interactive terminal.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help on internal slash commands
\g or terminate with semicolon to execute query
\q to quit
testdb=>
Óû§¿ÉÒÔÔÚÕâ¸öÌáʾ·ûϼüÈë
SQL ²éѯ£®Í¨³££¬ÊäÈëµÄÐн«ÔÚ²éѯÖÕÖ¹·ÖºÅ³öÏÖʱË͵½ºó¶Ë£®Ò»ÐеÄÖÕÖ¹²¢²»½áÊø²éѯ£¡Òò´Ë²éѯ¿ÉÒÔÒòÇåÎúÆð¼û¿çÔ½ºÃ¼¸ÐС£Èç¹û²éѯ·¢ËͳöÈ¥¶øÇÒûÓдíÎ󣬲éѯ½á¹û»áÏÔʾÔÚÆÁÄ»ÉÏ¡£
µ±²éѯÕýÔÚ½øÐÐʱ£¬psql ͬÑù»¹ÂÖѯÓÉ
LISTEN
ºÍ NOTIFY Éú³ÉµÄÒ첽֪ͨÐźţ®
psql רÓÐÃüÁî
ÄãÔÚ
psql ÀïÊäÈëµÄÈκÎÒÔ²»´øÒýºÅµÄ·´Ð±¸Ü£¨'\'£©¿ªÍ·µÄ¶«Î÷¶¼ÊÇ
psql
רÓÐÃüÁÕâЩÃüÁîÊÇÓÉ
psql ×Ô¼º´¦ÀíµÄ¡£ÕâЩÃüÁîÒ²ÊÇÁî
psql¿ÉÓÃÓÚ¹ÜÀí»òÊéд½Å±¾µÄÔÒò¡£×¨ÓÐÃüÁî¸ü³£¼ûµÄ½Ð·¨ÊÇб¸Ü»ò·´Ð±¸ÜÃüÁî¡£
Ò»¸ö psql ÃüÁîµÄ¸ñʽÊÇ·´Ð±¸ÜºóÃæ½ô¸úÒ»¸öÃüÁ´Ê£¬È»ºóÊÇÈÎÒâ²ÎÊý£®²ÎÊýÓëÃüÁ´ÊºÍÆäËû²ÎÊýÒÔÈÎÒâ¸ö¿Õ°××Ö·û¼ä¸ô£®
ÒªÔÚ²ÎÊýÀïÃæ°üº¬¿Õ°×£¬Äã±ØÐëÓõ¥ÒýºÅ°ÑËü°üΧÆðÀ´¡£ÒªÔÚÕâÑùµÄ²ÎÊýÀï°üº¬µ¥ÒýºÅ£¬Ç°Ãæ¼ÓÒ»¸ö·´Ð±¸Ü¡£Èκΰüº¬ÔÚµ¥ÒýºÅÀïµÄ¶«Î÷»á±»½øÒ»²½½øÐÐÀà
C µÄÌæ»»£¬°Ñ \n £¨ÐÂÐУ©£¬\t £¨tab£©£¬
\digits£¬\0digits
ºÍ \0xdigits £¨¸ø³öµÄÊ®½øÖÆ£¬°Ë½øÖÆ£¬»òÊ®Áù½øÖÆÂëµÄ×Ö·û£©Ìæ»»µô¡£
Èç¹ûÒ»¸ö²»´øÒýºÅµÄ²ÎÊýÒÔðºÅ£¨:£©¿ªÍ·£¬Ëü»á±»µ±×÷Ò»¸ö±äÁ¿£¬²¢ÇҸñäÁ¿µÄÖµ»á×îÖÕ³ÉΪÕæÕýµÄ²ÎÊýÖµ¡££¨Òë×¢£ºÀàËÆǶÈëSQLµÄ±äÁ¿Ó÷¨¡££©
Óá°·´¹´ºÅ¡± £¨backticks£¨`£©£©ÒýÆðµÄÄÚÈݱ»µ±×÷Ò»¸öÃüÁîÐд«Èë
shell¡£¸ÃÃüÁîµÄÊä³ö£¨É¾³ýÁ˽áβµÄÐÂÐУ©±»µ±×÷²ÎÊýÖµ¡£ÉÏÃæÃèÊöµÄתÒ⣨×Ö·û£©ÐòÁÐÔÚ·´¹´ºÅÀïÒ²ÉúЧ¡££¨Òë×¢£ºÓë
shell ³ÌÐòÀàËÆ£©
ÓÐЩÃüÁîÒÔÒ»¸ö SQL ±êʶµÄÃû³Æ£¨È磬һ¸ö±íÃû£©Îª²ÎÊý¡£ÕâЩ²ÎÊý×ñÑSQL
Óï·¨¹ØÓÚË«ÒýºÅµÄ¹æÔò£º²»´øË«ÒýºÅµÄ±êʶǿÖƳÉСд¡£¶ÔÓÚËùÓÐÆäËûÃüÁ˫ÒýºÅûÓÐÌØÊ⺬Òå²¢ÇÒ½«±»µ±³É²ÎÊýµÄÒ»²¿·Ö¡£
¶Ô²ÎÊýµÄ·ÖÎöÔÚÅöµ½ÁíÒ»¸ö²»´øÒýºÅµÄ·´Ð±¸Üʱֹͣ¡£ÕâÀï»áÈÏΪÊÇÒ»¸öеÄרÓÐÃüÁîµÄ¿ªÊ¼¡£ÌØÊâÐòÁÐ
\\
£¨Ë«·´Ð±¸Ü£©±êʶ²ÎÊýµÄ½áβ²¢½«¼ÌÐø·ÖÎöºóÃæµÄSQL
²éѯ£¨Èç¹û´æÔڵĻ°£©¡£ÕâÑù SQL ºÍ psql
ÃüÁî¿ÉÒÔ×ÔÓɵÄÔÚÒ»ÐÐÀïÃæ»ìºÏ¡£µ«ÊÇÔÚÈκÎÇé¿öÏ£¬Ò»ÌõרÓÐÃüÁîµÄ²ÎÊý²»ÄÜÑÓÐø³¬¹ýÐÐβ¡£
ÏÂÁÐרÓÐÃüÁîÊÇÒѶ¨ÒåµÄ£º
-
\a
-
Èç¹ûÄ¿Ç°µÄ±íÊä³ö¸ñʽÊDz»¶ÔÆëµÄ£¬Çл»³É¶ÔÆëµÄ¡£Èç¹ûÊǶÔÆëµÄ£¬Çл»³É²»¶ÔÆë¡£ÕâÌõÃüÁîÊÇΪÁËÏòºó¼æÈÝ¡£²ÎÔÄ
\pset
»ñÈ¡Ò»¸öͨÓõĽâ¾ö·½·¨¡£
-
\C [ title ]
-
°ÑÕýÔÚ´òÓ¡µÄ±íµÄ±êÌâÉèÖÃΪһ¸ö²éѯµÄ½á¹û»òÕßÈ¡ÏûÕâÑùµÄÉèÖá£ÕâÌõÃüÁîµÈЧÓÚ
\pset
title title¡££¨ÕâÌõÃüÁîµÄÃû³ÆÔ´ÓÚ¡°caption¡±£¬ÒòΪÒÔÇ°Ö»ÊÇÓÃÓÚÔÚÒ»¸öHTML
±íÀïÃæÉèÖñêÌâ¡££©
-
\connect (or \c) [ dbname [ username
] ]
-
ÓëÒ»¸öеÄÊý¾Ý¿â½¨Á¢Ò»¸öÁª½Ó£¬Ê¹ÓÃ/²»ÓÃÒ»¸öÓû§Ãû¡£Ç°ÃæµÄÁª½Ó½«¹Ø±Õ¡£Èç¹û
dbname
ÊÇ -£¬ÄÇô¾Í¼ÙÉèÊǵ±Ç°Êý¾Ý¿âÃû³Æ¡£
Èç¹ûÊ¡ÂÔ username£¬Ôò¼ÙÉèÊǵ±Ç°Óû§Ãû¡£
×÷ΪһÌõÌØÊâ¹æÔò£¬²»´øÈκβÎÊýÔËÐÐ \connect ½«ÒÔȱʡÓû§Éí·ÝÓëȱʡÊý¾Ý¿âÁ¬½Ó£¨ÕýÈçÄã²»´øÈκβÎÊýÔËÐÐpsql
Ò»Ñù¡££©
Èç¹ûÁª½Óʧ°Ü£¨Óû§Ãû´í£¬·ÃÎʾܾøµÈ£©£¬ÄÇô½«±£ÁôÇ°ÃæµÄÁª½Ó--½ö½öÊÇÔÚpsql
´¦ÓÚ½»»¥Ä£Ê½ÏÂÈç´Ë¡£Èç¹ûÔËÐеÄÊǷǽ»»¥µÄ½Å±¾£¬´¦Àí»áÂíÉÏÍ£Ö¹£¬²¢·µ»ØÒ»¸ö´íÎó¡£Ñ¡ÔñÕâÑùµÄÇø±ðÊÇÒ»·½ÃæΪÓû§Ê¹Ó÷½±ã¿¼ÂÇ£¬ÁíÒ»·½ÃæΪ±£Ö¤½Å±¾²»»áÅöÇɲÙ×÷ÁË´íÎóµÄÊý¾Ý¿âµÄ°²È«»úÖÆ¿¼Âǵġ£
-
\copy table [ with oids ] { from
| to } filename | stdin | stdout [ with delimiters
'characters' ] [ with null as 'string'
]
-
Ö´ÐÐÇ°¶Ë£¨¿Í»§¶Ë£©¿½±´£®ÕâÊÇÒ»¸öÔËÐÐ SQLCOPY
ÃüÁîµÄ²Ù×÷£¬²»Í¬µÄÊÇ SQL COPY ÊǺó¶ËÔÚ¶ÁдָÃ÷µÄÎļþ£¬¶ÔÓ¦µØÐèÒª·ÃÎʺó¶ËºÍÌØÊâµÄÓû§È¨ÏÞ£¬ÒÔ¼°Êܵ½ºó¶Ë¶ÔÎļþϵͳµÄ·ÃÎÊȨÏÞµÄÏÞÖÆ£¬¶øÔÚ´ËÃüÁîÖÐ psql
¶ÁдÎļþ²¢Í¨¹ýÒ»¸ö±¾µØµÄÎļþϵͳ·ÓÉ´Óºó¶ËÖÐÈ¡³ö»òдÈëµÄÊý¾Ý£®
ÕâÌõÃüÁîµÄÓï·¨ÊÇÄ£ÄâSQL COPY ÃüÁîµÄ£¬²Î¿¼ËüµÄÃèÊö»ñȡϸ½Ú¡£Òª×¢ÒâµÄÊÇÓɴ˶øÀ´£¬ÓÐһЩÌØÊâµÄ·ÖÎö¹æÔòÓ¦ÓÃÓÚ
\copy
ÃüÁî¡£ÓÈÆäÊDZäÁ¿Ìæ»»¹æÔòºÍ·´Ð±¸Ü´ú»»¹æÔò²»Æð×÷Óá£
С¼¼ÇÉ£º´Ë²Ù×÷²»Ïó SQLCOPY
ÃüÁîÕâÑù¸ßЧ£¬ÒòΪËùÓÐÊý¾Ý±ØÐëͨ¹ý£¨¿Í»§/·þÎñÆ÷)£©client/server IP »òÌ×½Ó×ÖÁª½Ó£®¶ÔÓÚ´óÊý¾ÝÁ¿µÄ²Ù×÷£¬ÁíÒ»ÖÖ·½·¨¸ü¿ÉÐС£
×¢Ò⣺עÒâÔÚÇ°¶ËºÍºó¶Ë¿½±´Ê±¶Ô stdin
ºÍ stdout µÄ½âÊ͵ÄÇø±ð£ºÔÚÇ°¶Ë¿½±´Ê±£¬ÕâЩ×ÜÊÇÖ¸psql
µÄÊäÈëºÍÊä³öÁ÷¡£ÔÚºó¶Ë¿½±´Ê± stdin À´×Ô COPY ±¾ÉíµÄ±ê×¼ÊäÈ루±ÈÈ磬һ¸ö´øÓÐ-f
Ñ¡ÏîµÄ½Å±¾£©£¬¶ø stdout Ö¸µÄÊDzéѯÊä³öÁ÷£¨²ÎÔÄÏÂÃæµÄ \o
רÓÐÃüÁ¡£
-
\copyright
-
ÏÔʾ PostgreSQL µÄ°æȨºÍ°æ±¾ÐÅÏ¢¡£
-
\d relation
-
ÏÔʾ relation £¨¿ÉÒÔÊÇ±í£¬ÊÓͼ£¬Ë÷Òý»òÐòÁУ©µÄËùÓÐÁУ¬Èç¹û´æÔڵػ°£¬ËüÃǵÄÀàÐͺʹæÔÚµÄÈκÎÌØÊâÊôÐÔ£¨Ïó
NOT
NULL »òȱʡµÈ£©Ò²ÏÔʾ³öÀ´¡£Èç¹ûʵ¼ÊÉÏÕâ¸ö¹ØϵÊÇÒ»¸ö±í£¬ÈκÎÒѶ¨ÒåµÄË÷ÒýÒ²»áÁгöÀ´¡£Èç¹û¸Ã¹ØϵÊÇÒ»¸öÊÓͼ£¬ÊÓͼµÄ¶¨ÒåÒ²»áÏÔʾ³öÀ´¡£
´Ó \d+ À´µÄÃüÁîÒ²ÊÇÒ»ÑùµÄ£¬Ö»²»¹ý»¹ÏÔʾÓë±íµÄÁйØÁªµÄ×¢½â¡£
×¢Ò⣺Èç¹û²»´øÈκβÎÊýµ÷Óà \d£¬µÈЧÓÚ
\dtvs£¬½«ÏÔʾһ¸öËùÓÐ±í£¬ÊÓͼºÍÐòÁеÄÁÐ±í¡£ÕâÍêÈ«ÊdzöÓÚ·½±ãµÄ¿¼ÂÇ¡£
-
\da [ pattern ]
-
ÁгöËùÓпÉÓþۼ¯º¯Êý£¬ÒÔ¼°ËüÃDzÙ×÷µÄÊý¾ÝÀàÐÍ¡£Èç¹ûÉùÃ÷ÁË pattern
£¨Ò»¸ö¹æÔò±í´ïʽ£©£¬ÄÇôֻÏÔʾƥÅ䣨¹æÔò±í´ïʽ£©µÄ¾Û¼¯º¯Êý¡£
-
\dd [ object ]
-
ÏÔʾ¶Ô object £¨¿ÉÒÔÊÇÒ»¸ö¹æÔò±í´ïʽ£©µÄÃèÊö£¬Èç¹ûûÓиø³ö²ÎÊý£¬ÏÔʾËùÓжÔÏó¡££¨¡°¶ÔÏó¡±°üÀ¨¾Û¼¯£¬º¯Êý£¬²Ù×÷·û£¬ÀàÐÍ£¬¹Øϵ£¨±í£¬ÊÓͼ£¬Ë÷Òý£¬ÐòÁУ¬´ó¶ÔÏ󣩣¬¹æÔòºÍ´¥·¢Æ÷¡££©ÀýÈ磺
=> \dd version
Object descriptions
Name | What | Description
---------+----------+---------------------------
version | function | PostgreSQL version string
(1 row)
¿ÉÒÔÓÃ COMMENT ONSQL
ÃüÁîÉú³É¶Ô¶ÔÏóµÄÃèÊö¡£
×¢Ò⣺PostgreSQL
ÔÚ pg_description ϵͳ±íÀï´æ´¢¶ÔÏóÃèÊö¡£
-
\df [ pattern ]
-
ÁгöËùÓпÉÓú¯Êý£¬ÒÔ¼°ËüÃǵIJÎÊýºÍ·µ»ØµÄÊý¾ÝÀàÐÍ¡£Èç¹ûÉùÃ÷ÁË pattern
£¨Ò»¸ö¹æÔò±í´ïʽ£©£¬ÄÇôֻÏÔʾƥÅ䣨¹æÔò±í´ïʽ£©µÄº¯Êý¡£Èç¹ûʹÓÃÁË \df+
µÄÐÎʽ£¬Ã¿¸öº¯ÊýµÄ¸½¼ÓÐÅÏ¢£¬°üÀ¨ÓïÑÔºÍÃèÊöÒ²»áÏÔʾ³öÀ´¡£
-
\distvS [ pattern ]
-
Õâ²»ÊÇÒ»¸öʵ¼ÊÉϵÄÃüÁîÃû³Æ£º×Öĸ i£¬s£¬t£¬v£¬S ·Ö±ð´ú±íË÷Òý£¨index£©£¬ÐòÁУ¨sequence£©£¬±í£¨table£©£¬ÊÓͼ£¨view£©ºÍϵͳ±í£¨system
table£©¡£Äã¿ÉÒÔÒÔÈÎÒâ˳ÐòÉùÃ÷ÈÎÒâ»òÕßËùÓÐÕâЩ×Öĸ»ñµÃÕâЩ¶ÔÏóµÄÒ»¸öÁÐ±í£¬ÒÔ¼°ËüÃǵÄËùÓÐÕß¡£
Èç¹ûÉùÃ÷ÁË pattern£¬ËüÊÇÒ»¸ö¹æÔò±í´ïʽ°ÑÊä³öÏÞÖÆÔÚÄÇЩƥÅäµÄÌõÄ¿ÉÏ¡£Èç¹ûÎÒÃÇÔÚÃüÁîÃû³ÆºóÃæ¼ÓÒ»¸ö "+"
£¬ÄÇôÿ¸ö¶ÔÏó´æÔÚµÄÏà¹ØÃèÊöÒ²»áÏÔʾ³öÀ´¡£
-
\dl
-
ÕâÊÇ \lo_list µÄ±ðÃû£¬ÏÔʾһ¸ö´ó¶ÔÏóµÄÁÐ±í¡£
-
\do [ name ]
-
ÁгöËùÓпÉÓòÙ×÷·û£¬ÒÔ¼°ËüÃǵIJÙ×÷ÊýºÍ·µ»ØµÄÊý¾ÝÀàÐÍ¡£Èç¹ûÉùÃ÷ÁË pattern
£¬ÄÇôֻÏÔʾƥÅäµÄ²Ù×÷·û¡££
-
\dp [ pattern ]
-
ÕâÊÇÒ»¸ö \z µÄ±ðÃû£¬°üÀ¨ËüÊÇΪÁ˱£ÁôÆä¾Þ´óµÄ¼ÇÒäÐÔ¼ÛÖµ£¨ÏÔʾȨÏÞ"display
permissions"£©¡£\dT [ pattern ]
-
ÁгöËùÓÐÊý¾ÝÀàÐÍ»òÄÇЩƥÅä pattern µÄ¡£ÕâÌõÃüÁîµÄ \dT+
ÐÎʽÏÔʾ¸ü¶àÐÅÏ¢¡£
-
\edit (or \e) [ filename ]
-
Èç¹ûÉùÃ÷ÁË filename£¬Ôò±à¼´ËÎļþ²¢ÇÒÔÚ±à¼Æ÷Í˳öºó½«ÆäÄÚÈÝ¿½±´»Ø²éѯ»º³åÇø¡£Èç¹ûûÓиø³ö²ÎÊý£¬Ôò°Ñµ±Ç°²éѯ»º³åÇøÄÚÈÝ¿½±´µ½Ò»¸öÁÙʱÎļþÈ»ºóÒÔÏàͬ·½Ê½±à¼¡£
È»ºó¸ù¾ÝÒ»°ãµÄpsql ¹æÔòÖØзÖÎö²éѯ»º³åÇø£¬ÕâʱÕû¸ö»º³åÇøµ±×÷Ò»¸öµ¥ÐС££¨Òò´ËÄãÎÞ·¨ÓÃÕâ¸ö·½·¨ÖÆ×÷¡°½Å±¾¡±£¬ÓÃ
\i
×ö½Å±¾¡££©Õ⻹Òâζ×ÅÈç¹û¸Ã²éѯÒԷֺŽá⣨»òÕß°üº¬·ÖºÅ£©£¬Ëü¾Í»áÂíÉϱ»Ö´ÐС£·ñÔòËüÖ»ÊÇÔÚ²éѯ»º³åÇøÀïµÈ´ý¡£
С¼¼ÇÉ£ºpsql
ËÑË÷»·¾³±äÁ¿ PSQL_EDITOR£¬EDITOR ºÍ VISUAL£¨ÒÔ´Ë˳Ðò£©²éÕÒÒªÓõ½Äĸö±à¼Æ÷¡£Èç¹ûÉÏÃæµÄ¶¼Ã»ÓÐÉèÖã¬Ê¹ÓÃ
/bin/vi¡£
-
\echo text [ ... ]
-
Ïò±ê×¼Êä³ö´òÓ¡²ÎÊý£¬ÓÃÒ»¸ö¿Õ¸ñ·Ö¸ô²¢ÇÒ×îºó¸ú×ÅÒ»¸öÐÂÐС£Õâ¸öÌØÐÔÔÚÏÔʾ½Å±¾µÄÊä³öʱ»áÓÐÓá£ÀýÈ磺
=> \echo `date`
Tue Oct 26 21:40:57 CEST 1999
Èç¹ûµÚÒ»¸ö²ÎÊýÊÇÒ»¸öÎÞÒýºÅµÄ -n£¬ÄÇô²»»áд³ö½áβµÄÐÂÐС£
С¼¼ÇÉ£ºÈç¹ûÄãʹÓà \o ÃüÁîÖض¨ÏòÄãµÄ²éѯµÄÊä³ö£¬Äã¿ÉÄÜ»áÓÃ
\qecho
È¡´úÕâÌõÃüÁî¡£
-
\encoding [ encoding ]
-
Èç¹ûÄãʹÓöà×Ö½Ú±àÂ룬ÉèÖÿͻ§¶Ë±àÂ뷽ʽ¡£²»´ø²ÎÊýʱ£¬ÕâÌõÃüÁîÏÔʾµ±Ç°µÄ±àÂ뷽ʽ¡£
-
\f [ string ]
-
Ϊ²»¶ÔÆëµÄ²éѯÊä³öÉèÖÃÓò·Ö¸ô·û¡£È±Ê¡Ê±ÊÇ¡°|¡±£¨Ò»¸ö¡°¹ÜµÀ¡±·ûºÅ£©¡£²ÎÔÄ
\pset
»ñÈ¡ÉèÖÃÊä³öÑ¡ÏîµÄͨÓ÷½·¨¡£
-
\g [ { filename | |command } ]
-
°Ñµ±Ç°µÄ²éѯÊäÈ뻺³åÇøµÄÄÚÈÝ·¢Ë͸øºó¶Ë²¢ÇÒ°ÑÊä³öÊä³öµ½¿ÉÑ¡µÄ filename
»òÕß°ÑÊä³ö¶¨Ïòµ½Ò»¸ö¶ÀÁ¢µÄ Unix shell Ö´ÐÐ command¡£µ¥¶ÀÒ»¸ö
\g
ʵ¼ÊÉϵÈЧÓÚÒ»¸ö·ÖºÅ¡£Ò»¸ö´øÓвÎÊýµÄ \g ÊÇ¡°Ò»´ÎÐÔ¡±µÄ
\o
ÃüÁîµÄ´úÓÃÆ·¡£
-
\help (or \h) [ command ]
¸ø³öÖ¸¶¨ SQL ÃüÁîµÄÓï·¨°ïÖú¡£Èç¹ûûÓиø³ö
command£¬ÄÇôpsql
½«Áгö¿É»ñµÃÓï·¨°ïÖúµÄËùÓÐÃüÁî¡£Èç¹û
command ÊÇÒ»¸öÐǺţ¨"*"£©£¬ÔòÏÔʾËùÓÐSQLÃüÁîµÄÓï·¨°ïÖú¡£
×¢Ò⣺Ϊ¼ò»¯Çû÷£¬°üº¬¶à¸öµ¥×ÖµÄÃüÁî²»ÐèÒªÒýÆð¡£Òò´Ë¼üÈë
\help
alter table ÊÇÕýÈ·µÄ¡£
-
\H
-
´ò¿ª HTML ²éѯÊä³ö¸ñʽ¡£Èç¹û HTML
¸ñʽÒѾ´ò¿ª£¬ÔòÇл»»ØȱʡµÄ¶ÔÆëµÄÎı¾¸ñʽ¡£Õâ¸öÃüÁîÊÇΪÁ˼æÈݺͷ½±ã£¬²ÎÔÄ
\pset
»ñÈ¡ÉèÖÃÆäËûÊä³öÑ¡ÏîµÄÄÚÈÝ¡£
-
\i filename
´ÓÎļþ filename ÖжÁÈ¡²¢°ÑÆäÄÚÈݵ±×÷´Ó¼üÅÌÊäÈëµÄÄÇÑùÖ´Ðвéѯ¡£
×¢Ò⣺Èç¹ûÄãÏëÔÚÆÁÄ»ÉÏ¿´µ½¶ÁÈëµÄÐУ¬Äã±ØÐë¶ÔËùÓÐÐÐÉèÖñäÁ¿
ECHO
¡£
-
\l (or \list)
Áгö·þÎñÆ÷ÉÏËùÓÐÊý¾Ý¿âºÍËüÃǵÄËùÓÐÕß¡£ÔÚÃüÁîÃû³ÆºóÃæ¼ÓÒ»¸ö "+"
»¹¿ÉÒÔ¿´µ½¶ÔÊý¾Ý¿âµÄÈκÎÃèÊö¡£Èç¹ûÄãµÄPostgres
½ÚµãÊÇ´ø×Ŷà×Ö½ÚÖ§³Ö±àÒëµÄ£¬»¹¿ÉÒÔ¿´µ½Ã¿¸öÊý¾Ý¿âµÄ±àÂ뷽ʽ¡£
-
\lo_export loid filename
-
´ÓÊý¾Ý¿âÀï¶ÁÈ¡ OID Ϊ loid
µÄ´ó¶ÔÏó²¢°ÑËýдµ½ filename Àï¡£×¢ÒâÕâ¸ö¹¦ÄÜÓë·þÎñÆ÷º¯Êý
lo_export
ÓÐЩ΢СµÄÇø±ð£¬ lo_export ÔËÐÐʱ´ø×ÅÔËÐÐÊý¾Ý¿â·þÎñÆ÷µÄÓû§È¨ÏÞ£¬¶øÇÒÊÇÔÚ·þÎñÆ÷µÄÎļþϵͳÉÏ¡£
С¼¼ÇÉ£ºÊ¹Óà \lo_list ²é¿´´ó¶ÔÏóµÄ OID¡£
×¢Ò⣺²ÎÔıäÁ¿ LO_TRANSACTION
µÄÃèÊö»ñÈ¡¹ØÓÚËùÓдó¶ÔÏó²Ù×÷µÄÖØÒªÐÅÏ¢¡£
-
\lo_import filename [ comment
]
-
°ÑÎļþ´æ´¢ÎªÒ»¸ö PostgreSQL ¡°´ó¶ÔÏ󡱡£¿ÉÒÔ´ø×ÅÒ»¸ö¸Ã¶ÔÏóµÄ×¢½âÑ¡Ïî¡£ÀýÈ磺
foo=> \lo_import '/home/peter/pictures/photo.xcf' 'a picture of me'
lo_import 152801
ÏìÓ¦±íÃ÷´Ë´ó¶ÔÏóµÃµ½Ò»¸ö¶ÔÏó±êʶ 152801£¬Èç¹ûÄ㻹Ïë·ÃÎʸöÔÏ󣬾ÍÓ¦¸Ã°ÑÕâ¸ö¶ÔÏó±êʶ¼Çס¡£Òò´Ë£¬ÎÒÃǽ¨Òé×ÜÊǸøÿ¸ö¶ÔÏó¹ØÁªÒ»¸öÈËÀà¿É¶ÁµÄ×¢½â¡£ÄÇÑù¾Í¿ÉÒÔÓÃ
\lo_list
ÃüÁî¿´µ½ÕâЩע½â¡£
×¢ÒâÕâÌõÃüÁîÓë·þÎñÆ÷¶ËµÄ lo_import ÓÐһЩÇø±ð£¬ÒòΪÕâÌõÃüÁîÊDZ¾µØÓû§ÔÚ±¾µØÎļþϵͳÉϲÙ×÷£¬¶ø²»ÊÇÒÔ·þÎñÆ÷Óû§ÔÚ·þÎñÆ÷ÎļþϵͳÉϲÙ×÷¡£
×¢Ò⣺²ÎÔıäÁ¿ LO_TRANSACTION
µÄÃèÊö»ñÈ¡¹ØÓÚËùÓдó¶ÔÏó²Ù×÷µÄÖØÒªÐÅÏ¢¡£
-
\lo_list
-
ÏÔʾһ¸öÄ¿Ç°´æ´¢ÔÚ¸ÃÊý¾Ý¿âÀïµÄËùÓÐ PostgreSQL
¡°´ó¶ÔÏ󡱺ÍËüÃǵÄËùÓÐÕßµÄÁÐ±í¡£
-
\lo_unlink loid
´ÓÊý¾Ý¿âÀïɾ³ý OID
ÊÇ loid µÄ´ó¶ÔÏó¡£
С¼¼ÇÉ£ºÊ¹Óà \lo_list ²éÕÒ´ó¶ÔÏóµÄ OID¡£
×¢Ò⣺²ÎÔıäÁ¿ LO_TRANSACTION
µÄÃèÊö»ñÈ¡¹ØÓÚËùÓдó¶ÔÏó²Ù×÷µÄÖØÒªÐÅÏ¢¡£
-
\o [ {filename | |command} ]
°ÑºóÃæµÄ²éѯ½á¹û±£´æµ½Îļþ filename Àï»òÕ߰ѺóÃæµÄ²éѯ½á¹û¶¨Ïòµ½Ò»¸ö¶ÀÁ¢µÄ
Unix shell Ö´ÐÐ command¡£Èç¹ûûÓÐÉùÃ÷²ÎÊý£¬²éѯÊä³öÖØÖÃΪ
stdout¡£
¡°²éѯ½á¹û¡±°üÀ¨ËùÓÐ±í£¬ÃüÁîÏìÓ¦ºÍ´ÓÊý¾Ý¿â·þÎñÆ÷À´µÄÌáʾ£¬Í¬Ñù»¹Óи÷ÖÖ¸÷Ñù²éѯÊý¾Ý¿âµÄ·´Ð±¸ÜÃüÁîµÄÊä³ö£¨Èç
\d£©£¬µ«ÊÇûÓдíÎóÐÅÏ¢¡£
С¼¼ÇÉ£ºÒª·ÖÉ¢²éѯ½á¹ûÖ®¼äµÄÊä³ö£¬Óà \qecho¡£
-
\p
-
´òÓ¡µ±Ç°²éѯ»º³åÇøµ½±ê×¼Êä³ö£®
-
\pset parameter [ value ]
ÕâÌõÃüÁîÉèÖÃÓ°Ïì²éѯ½á¹û±íÊä³öµÄÑ¡Ïî¡£parameter ÃèÊöÒªÉèÖõÄÑ¡ÏîÊÇÄÄÒ»¸ö¡£value
µÄÓïÒâҲȡ¾öÓÚËü¡£
¿Éµ÷½ÚµÄ´òÓ¡Ñ¡ÏîÓУº
-
format
ÉèÖÃÊä³ö¸ñʽΪ unaligned£¬aligned£¬html »ò
latex
Ö®Ò»¡£ÔÊÐíʹÓÃΨһµÄËõд¡££¨ÕâÒ²Òâζ×ÅÒ»¸ö×Öĸ¾Í¹»ÁË¡££©
¡°Unaligned¡± £¨²»¶ÔÆ룩°ÑÒ»Ìõ¼Ç¼µÄËùÓÐÓò¶¼¶¼Êä³öµ½Ò»ÐУ¬Óõ±Ç°ÓÐЧµÄÓò·Ö¸ô·û·Ö¸ô¡£ÕâÖ÷ÒªÓÃÓÚÉú³ÉÄÇЩҪ±»ÆäËû³ÌÐò¶ÁÈ¡µÄÊä³ö£¨tab·Ö¸ô£¬¶ººÅ·Ö¸ô£©¡£¡°Aligned¡±£¨¶ÔÆ룩ģʽÊDZê×¼µÄ£¬ÈËÀà¿É¶ÁµÄ£¬¸ñʽ»¯ºÃÁ˵ÄÎı¾Êä³ö£¬Ò²ÊÇȱʡ¡£¡°HTML¡±
ºÍ¡°LaTeX¡± ģʽ°Ñ±íÊä³öΪ¿ÉÓÃÓÚÎĵµÀïµÄ¶ÔÓ¦±ê¼ÇÓïÑÔ¡£ËüÃÇ»¹²»ÊÇÍêÕûµÄÎĵµ£¡£¨¿ÉÄܶÔÓÚHTML
±ä»¯»¹²»ÊÇÌ«´ó£¬µ«ÊÇÔÚ LaTeX ÀÄã±ØÐëÓÐÒ»¸öÍêÕûµÄÎĵµ°ü×°Æ÷¡££©
-
border
µÚ¶þ¸ö²ÎÊý±ØÐëÊÇÒ»¸öÊý×Ö¡£Í¨³££¬Êý×ÖÔ½´ó£¬±í¾ÍÓÐÔ½¿íµÄ±ß½çºÍÔ½¶àµÄÏߣ¬µ«ÊÇÕâ¸ö²ÎÊýÈ¡¾öÓÚʵ¼ÊµÄ¸ñʽ¡£ÔÚHTML
ģʽÀÕâ¸ö²ÎÊý»áÖ±½Ó·Òë³É border=... ÊôÐÔ£¬ÔÚÆäËûµÄģʽÀֻÓÐÖµ
0 £¨Îޱ߽磩£¬1 £¨ÄÚ²¿·Ö¸ôÏߣ©ºÍ 2 £¨±í¿ò¼Ü£©ÓÐÒâÒå¡£
-
expanded (or x)
ÔÚÕý³£ºÍÀ©Õ¹¸ñʽ֮¼äÇл»¡£µ±´ò¿ªÀ©Õ¹¸ñʽʱ£¬ËùÓеÄÊä³ö¶¼ÊÇÁ½ÁУ¬ÓòÃû³ÆÔÚ×ó£¬Êý¾ÝÔÚÓÒ¡£Õâ¸öģʽÔÚÊý¾ÝÎÞ·¨·Å½øͨ³£µÄ¡°Ë®Æ½¡±Ä£Ê½µÄÆÁĻʱºÜÓÐÓá£
ËùÓÐËÄÖÖÊä³öģʽ¶¼Ö§³ÖÀ©Õ¹Ä£Ê½¡£
-
null
µÚ¶þ¸ö²ÎÊýÊÇÒ»¸ö×Ö´®£¬ÓÃÒÔ´ú±íÓòµÄֵΪ null ´òÓ¡¡£È±Ê¡ÊÇʲô¶¼²»´ò£¬ÕâÑùºÜÈÝÒ׺ÍÀàËÆÒ»¸ö¿Õ×Ö´®»ìÏý¡£Òò´Ë£¬ÎÒÃÇ¿ÉÄÜÑ¡Ôñ
\pset
null "(null)"¡£
-
fieldsep
ÉùÃ÷ÔڷǶÔÆëģʽʱµÄÓò·Ö¸ô·û¡£ÕâÑùÎÒÃǾͿÉÒÔ´´½¨ÆäËû³ÌÐòÏ£ÍûµÄ tab-
»ò¶ººÅ·Ö¸ôµÄÊä³ö¡£ÒªÉèÖà tab Óò·Ö¸ô·û£¬¼üÈë \pset fieldsep "\t"¡£È±Ê¡Óò·Ö¸ô·ûÊÇ¡°|¡±
£¨Ò»¸ö¡°¹ÜµÀ¡±·ûºÅ£©¡£
-
recordsep
ÉùÃ÷ÔڷǶÔÆëģʽʱµÄ¼Ç¼·Ö¸ô·û¡£È±Ê¡ÊÇÐÂÐÐ×Ö·û¡£
-
tuples_only (or t)
ÔÚÍêÈ«ÏÔʾºÍÖ»ÏÔʾ¼Ç¼֮¼äÇл»¡£ÍêÈ«ÏÔʾ½«ÏÔʾÏóÁÐÍ·£¬±êÌâºÍ¸÷ÖÖ½Å×¢µÈÐÅÏ¢¡£Ö»ÏÔʾ¼Ç¼ģʽ½«Ö»ÏÔʾʵ¼ÊµÄ±íÊý¾Ý¡£
-
title [ text ]
ΪÈκÎËæºó´òÓ¡µÄ±íÉèÖñêÌâ¡£Õâ¸ö²ÎÊý¿ÉÒÔÓÃÓÚ¸øÄãµÄÊä³öÒ»¸öÃèÊöÐÔ±ê¼Ç¡£Èç¹û²»´ø²ÎÊý£¬ÖØÖñêÌâ¡£
×¢Ò⣺ÒÔÇ°Õâ¸ö²ÎÊýÖ»Ó°ÏìHTML
ģʽ£¬ÏÖÔÚÄã¿ÉÒÔÔÚÈκÎÊä³öģʽÀïÉèÖñêÌâ¡£
-
tableattr (or T) [ text ]
ÔÊÐíÄãÉùÃ÷·ÅÔÚ HTML table
±ê¼ÇÀïµÄÈκÎÊôÐÔ¡£ÀýÈ磬¿ÉÒÔÊÇ cellpadding »òÕß bgcolor¡£×¢ÒâÄã¿ÉÄܲ»ÐèÒªÔÚÕâÀïÉùÃ÷
border£¬ÒòΪÒѾÔÚ
\pset
border ÀïÓùýÁË¡£
-
pager
¼¤»î·ÖÒ³Æ÷½øÐбíÊä³ö¡£Èç¹ûÉèÖÃÁË»·¾³±äÁ¿ PAGER£¬Êä³ö±»¶¨Ïòµ½Ö¸¶¨³ÌÐò£¬·ñÔòʹÓÃ
more¡£
²»¹ÜÔõÑù£¬psql Ö»ÔÚËüÈÏΪÐèÒªµÄʱºòʹÓ÷ÖÒ³Æ÷¡£ÕâÒâζ×ÅÊä³öÊǵ½ÖÕ¶ËÈ¥µÄ¶øÄǸö±íºÜ¿ÉÄÜÎÞ·¨ÓëÆÁĻƥÅä¡£ÒòΪ´òÓ¡¹ý³ÌµÄÄ£¿é»¯ÌìÐÔ£¬ÎÒÃDz»¿ÉÄÜÿ´Î¶¼×¼È·Ô¤¼Æ³öʵ¼Ê´òÓ¡µÄÐÐÊý¡£Òò´Ëpsql
ÔÚ¾ö¶¨ºÎʱ·Öҳʱ¿ÉÄÜÏԵò»ÊǺÜÓÐʶ±ðÁ¦¡£
¿ÉÒÔÔÚ Examples
½Ú¿´µ½ÕâЩ²»Í¬¸ñʽÊä³öµÄʾÀý¡£
С¼¼ÇÉ£ºÓкܶàÓÃÓÚ \pset µÄ¿ìËÙÃüÁî¡£²ÎÔÄ
\a£¬\C£¬\H£¬\t£¬\T
ºÍ \x¡£
×¢Ò⣺ÎÞ²ÎÊýÔËÐÐ \pset ÊÇ´íÎóµÄ¡£ÒÔºóÕâÑùµ÷Óý«ÏÔʾµ±Ç°´òÓ¡Ñ¡Ïî״̬¡£
-
\q
-
Í˳ö psql ³ÌÐò£®
-
\qecho text [ ... ]
-
ÕâÌõÃüÁîµÈЧÓÚ \echo£¬Çø±ðʹËùÓÐÊä³ö½«Ð´ÈëÓÉ \o ÉèÖõÄÊä³öͨµÀ¡£
-
\r
-
ÖØÖã¨Çå¿Õ£©²éѯ»º³åÇø¡£
-
\s [ filename ]
-
½«ÃüÁîÐÐÀúÊ·´òÓ¡³ö»òÊÇ´æ·Åµ½ filename¡£Èç¹ûÊ¡ÂÔ filename£¬ÀúÊ·½«Êä³öµ½±ê×¼Êä³ö¡£Õâ¸öÑ¡ÏîÖ»ÓÐÔÚpsql
ÅäÖóÉʹÓà GNU ÀúÊ·¿âºó²ÅÉúЧ¡£
×¢Ò⣺¶ÔÓÚ psql
v7.0£¬Õâ¸ö£¨ GNU ÀúÊ·¿â£©²»ÔÙÊDZØÐëµÄÁË£¬Êµ¼ÊÉÏ£¬ÔÚ³ÌÐò½áÊøʱ×Ô¶¯±£´æÃüÁîÐÐÀúÊ·¡£Ã¿´Îpsql
Æô¶¯¶¼»á×°ÔØÃüÁîÐÐÀúÊ·¡£
-
\set [ name [ value [ ... ]]]
-
ÉèÖÃÄÚ²¿±äÁ¿ name Ϊ value »ò×ÅÈç¹û¸ø³öÁ˶àÓÚÒ»¸öÖµ£¬ÉèÖÃΪËùÓÐÕâЩֵµÄÁª½Ó½á¹û¡£Èç¹ûûÓиø³öµÚ¶þ¸ö²ÎÊý£¬Ö»Éè±äÁ¿²»ÉèÖµ¡£ÒªÖØÖÃÒ»¸ö±äÁ¿£¬Ê¹ÓÃ
\unset
ÃüÁî¡£
ÓÐЧµÄ±äÁ¿Ãû¿ÉÒÔ°üº¬×Ö·û£¬Êý×ÖºÍÏ»®Ïß¡£²ÎÔĹØÓÚpsql
±äÁ¿µÄÕ½ڻñȡϸ½Ú¡£
¾¡¹ÜÄã¿ÉÒÔÉèÖÃÈκαäÁ¿ÎªÈÎÒâÖµ£¬psql
¶ÔһЩ±äÁ¿ÌØÊâ¶Ô´ý¡£ËüÃÇÔÚ¹ØÓÚ±äÁ¿µÄ½ÚÀïÃæÓÐÎĵµ¡£
-
×¢Ò⣺ÕâÌõÃüÁîÊÇÍêÈ«ºÍ SQL ÃüÁî
SET²»Ò»ÑùµÄ¡£
-
\t
-
Çл»Êä³öµÄÁÐ/×Ö¶ÎÃûµÄÐÅϢͷºÍÐмÇÊý½Å×¢¡£ÕâÌõÃüÁîµÈЧÓÚ \pset tuples_only£¬ÌṩÖ÷ҪΪÁË·½±ã¡£
-
\T table_options
-
ÔÊÐíÄãÔÚʹÓà HTML Êä³öģʽʱÉùÃ÷·ÅÔÚ
table
±ê¼ÇÀïµÄÑ¡Ïî¡£ÕâÌõÃüÁîµÈЧÓÚ \pset tableattr table_options¡£
-
\w {filename | |command}
-
½«µ±Ç°²éѯ»º³åÇøÊä³öµ½Îļþ filename »òÕ߶¨Ïòµ½ Unix ÃüÁî
command¡£
-
\x
-
Çл»À©Õ¹Ðиñʽ£®µÈЧÓÚ \pset expanded¡£
-
\z [ pattern ]
-
Éú³ÉÒ»¸ö´øÓзÃÎÊȨÏÞÁбíµÄÊý¾Ý¿âÖÐËùÓбíµÄÁÐ±í¡£Èç¹û¸ø³öÈκβÎÊý£¬Ôò±»µ±³ÉÒ»¸ö¹æÔò±í´ïʽ£¬°ÑÁбíÊä³öÏÞÖÆΪÄÇЩ¿ÉÒÔÆ¥ÅäµÄ±í¡£
test=> \z
Access permissions for database "test"
Relation | Access permissions
----------+-------------------------------------
my_table | {"=r","joe=arwR", "group staff=ar"}
(1 row )
Òâ˼ÈçÏ£º
"=r": PUBLIC ÓµÓжԴ˱íµÄ¶Á£¨SELECT£©È¨ÏÞ¡£
"joe=arwR": Óû§ joe ÓµÓжÁ£¬Ð´£¨UPDATE£¬DELETE£©£¬¡°×·¼Ó¡±£¨INSERT£©È¨ÏÞ£¬ÒÔ¼°ÔÚ±íÉÏ´´½¨¹æÔòµÄȨÏÞ¡£
-
"group staff=ar": ×é staff ÓµÓÐ SELECT ºÍ INSERT
ȨÏÞ¡£
ÃüÁî GRANT ºÍ REVOKE
ÓÃÓÚÉèÖ÷ÃÎÊȨÏÞ¡£
-
\! [ command ]
-
·µ»Øµ½Ò»¸ö¶ÀÁ¢µÄ Unix shell »òÕßÖ´ÐÐ Unix ÃüÁî command¡£²ÎÊý²»»á±»½øÒ»²½½âÊÍ£¬shell
½«¿´µ½È«²¿²ÎÊý¡£
-
\?
-
»ñµÃ¹ØÓÚ·´Ð±¸Ü ("\") ÃüÁîµÄ°ïÖúÐÅÏ¢¡£
ÃüÁîÐÐÑ¡Ïî
Èç¹ûÅäÖúÃÁË£¬
psql Àí½â±ê×¼µÄ Unix ¶ÌÑ¡ÏîºÍ
GNU
·ç¸ñµÄ³¤Ñ¡Ïî¡£ºóÕß²»ÊÇÔÚËùÓÐϵͳÉ϶¼ÄÜ»ñµÃ¡£
-
-a, --echo-all
-
ÔÚ¶ÁÈ¡ÐÐʱÏëÆÁÄ»´òÓ¡ËùÓÐÄÚÈÝ¡£Õâ¸öÑ¡ÏîÔڽű¾´¦Àíʱ±È½»»¥Ä£Ê½Ê±¸üÓÐÓá£Õâ¸öÑ¡ÏîµÈЧÓÚÉèÖñäÁ¿
ECHO
Ϊ all¡£
-
-A, --no-align
-
Çл»Îª·Ç¶ÔÆëÊä³öģʽ¡££¨È±Ê¡Êä³öģʽÊǶÔÆëµÄ¡££©
-
-c, --command query
-
ÉùÃ÷ psql ½«Ö´ÐÐÒ»Ìõ²éѯ×Ö´®£¬query£¬È»ºóÍ˳ö£®ÕâÒ»µãÔÚ
shell ½Å±¾ÀïºÜÓÐÓá£
query ±ØÐëÊÇÒ»ÌõÍêÈ«¿ÉÒÔ±»ºó¶Ë·ÖÎöµÄ²éѯ×Ö´®£¨Ò²¾ÍÊÇ˵£¬Ëü²»°üº¬psql
ÌØÓеÄÌØÐÔ£©£¬»òÕßÊÇÒ»¸ö·´Ð±¸ÜÃüÁî¡£ÕâÑùÄã¾Í²»»á»ìºÏSQL
ºÍ psql רÓÐÃüÁî¡£ÒªÏë»ìºÏʹÓã¬Äã¿ÉÒÔ°Ñ×Ö´®¶¨Ïòµ½psql
ÀÏóÕâÑù£ºecho "\x \\ select * from foo;" | psql¡£
-
-d, --dbname dbname
-
ÉùÃ÷ÏëÒªÁª½ÓµÄÊý¾Ý¿âÃû³Æ£®µÈЧÓÚÔÚÃüÁîÐÐÐÐÉÏ°Ñ dbname ÉùÃ÷ΪµÚÒ»¸öÎÞÑ¡Ïî²ÎÊý.
-
-e, --echo-queries
-
ÉùÃ÷ÒªÁª½ÓµÄÊý¾Ý¿âÃû£®µÈЧÓڰѱäÁ¿ ECHO ÉèÖÃΪ queries¡£
-
-E, --echo-hidden
-
»ØÏÔÓÉ \d ºÍÆäËû·´Ð±¸ÜÃüÁîÉú³ÉµÄʵ¼Ê²éѯ¡£Èç¹ûÄãÏ£ÍûÔÚÄã×Ô¼ºµÄ³ÌÐòÀï°üº¬ÀàËƵŦÄÜ£¬Äã¾Í¿ÉÒÔʹÓÃÕâ¸öÑ¡Ïî¡£ÕâµÈЧÓÚÔÚpsql
ÀïÉèÖñäÁ¿ ECHO_HIDDEN¡£
-
-f, --file filename
-
ʹÓà filename ×÷Ϊ²éѯµÄÓï¾äÔ´¶ø²»Êǽ»»¥Ê½¶ÁÈë²éѯ¡£ÔÚ´¦ÀíÍêÎļþºó£¬psql
½áÊø¡£Õâ¸öÑ¡ÏîÔںܶ෽ÃæµÈЧÓÚÄÚ²¿ÃüÁî \i¡£
ʹÓÃÕâ¸öÑ¡ÏîÓëÓà psql < filename ÓÐ΢СµÄÇø±ð¡£Í¨³££¬Á½Õ߶¼»Ø°´ÕÕÄãÔ¤ÆÚÄÇÑùÔËÐУ¬µ«ÊÇʹÓÃ
-f
´ò¿ªÁËһЩºÜºÃµÄÌØÐÔ£¬±ÈÈç´øÐкŵĴíÎóÐÅÏ¢¡£¶øÇÒ£¬Ê¹ÓÃÕâ¸öÑ¡ÏÓпÉÄÜÓмõСÆô¶¯¸ººÉµÄ»ú»á¡£ÁíÒ»·½Ã棬Èç¹ûÄã°ÑËùÓÐÄÚÈÝÊÖ¹¤ÊäÈ룬ʹÓÃ
shell ÊäÈ붨ÏòµÄ·½Ê½£¨ÀíÂÛÉÏ£©Äܱ£Ö¤Éú³ÉºÍÄãÒѾµÃµ½µÄÍêÈ«Ò»ÑùµÄÊä³ö£¨Òë×¢£ºÖظ´ÔËÐÐÃüÁ¡£
-
-F, --field-separator separator
-
ʹÓà separator ×÷ΪÓò·Ö¸ô·û£®µÈЧÓÚ \pset fieldsep
»ò \f¡£
-
-h, --host hostname
-
ÉùÃ÷ÕýÔÚÔËÐÐ postmaster µÄÖ÷»úÃû£®Èç¹ûûÓдËÑ¡Ï½«Ê¹Óñ¾µØµÄUnixÓòÌ×½Ó×Ö½øÐÐͨѶ£®
-
-H, --html
-
´ò¿ª HTML ¸ñʽÊä³ö¡£µÈЧÓÚ \pset
format html »ò \H ÃüÁî¡£
-
-l, --list
-
ÁгöËùÓпÉÓõÄÊý¾Ý¿â£¬È»ºóÍ˳ö£®ÆäËû·ÇÁª½ÓÑ¡Ï±»ºöÂÔ£®ÀàËÆÓÚÄÚ²¿ÃüÁî
\list¡£
-
-o, --output filename
-
½«ËùÓвéѯÊä³ö¶¨Ïòµ½Îļþ filename¡£Õâ¸öÑ¡ÏîµÈЧÓÚÃüÁî \o¡£
-
-p, --port port
-
ÉùÃ÷±» postmaster ÓÃÓÚÕìÌýµÄ TCP/IP
¶Ë¿Ú»òʹÓõÄȱʡ±¾µØUnixÖ÷¿ØÌ×½Ó×ÖÎļþ¾ä±ú£®È±Ê¡µÄÊÇ»·¾³±äÁ¿ PGPORT
µÄÖµ£¬Èç¹ûûÓÐÉèÖõĻ°ÊDZàÒëÊÇÉùÃ÷µÄ¶Ë¿Ú£¬Í¨³£ÊÇ5432¡£
-
-P, --pset assignment
-
ÔÊÐíÄãÔÚÃüÁîÐÐÉÏÒÔ \pset µÄ·ç¸ñÉèÖôòÓ¡Ñ¡ÏҪעÒâµÄÊÇÄãÔÚÕâÀïÓõȺŷָîÃû³ÆºÍÖµ£¬¶ø²»ÄÜÓÿոñ¡£Òò´ËÒª°ÑÊä³ö¸ñʽÉèÖÃΪ
LaTeX£¬Äã¿ÉÒÔÇÃÈë -P format=latex¡£
-
-q
-
ÉùÃ÷ psql ½«"°²¾²µØ"Ö´Ðд¦ÀíÈÎÎñ£®È±Ê¡Ê±psql½«´òÓ¡»¶ÓºÍÐí¶àÆäËûÊä³öÐÅÏ¢¡£Èç¹ûʹÓÃÁË´ËÑ¡ÏÕâЩ¶¼²»³öÏÖ¡£ÕâÔÚºÍ -c
Ñ¡ÏîÒ»ÆðʹÓÃʱºÜÓÐЧ£®ÔÚ psql ÀÄã¿ÉÒÔͨ¹ýÉèÖÃ
QUIET
±äÁ¿ÊµÏÖͬÑùЧ¹û¡£
-
-R, --record-separator separator
-
ʹÓà separator ×öΪ¼Ç¼·Ö¸ô·û¡£µÈЧÓÚ \pset recordsep
ÃüÁî¡£
-
-s, --single-step
-
½øÈëµ¥²½Ä£Ê½ÔËÐС£Òâζ×Åÿ¸ö²éѯÔÚ·¢Íùºó¶Ë֮ǰ¶¼ÒªÌáʾÓû§£¬ÓÃÕâ¸öÑ¡ÏîÒ²¿ÉÒÔÈ¡ÏûÖ´ÐС£´ËÑ¡ÏîÖ÷ÒªÓÃÓÚµ÷ÊԽű¾¡£
-
-S, --single-line
½øÈëµ¥ÐÐÔËÐÐģʽ£¬Õâʱÿ¸ö²éѯ¶¼½«ÓÉ»»Ðзû½áÊø£¬Ïó·ÖºÅÄÇÑù¡£
×¢Ò⣺עÒâÕâ¸öģʽÊǸøÄÇЩ¼á³ÖÒªÕâ¸öÌØÐÔµÄÈ˵ģ¬ÎÒÃDz»¹ÄÀøÄãÕâôÓá£Êµ¼ÊÉÏ£¬Èç¹ûÄãÔÚÒ»ÐÐÀï»ìºÏʹÓÃSQL
ºÍרÓÐÃüÁִÐеÄ˳Ðò¶Ô²»ÊìÁ·µÄÓû§¶øÑÔ²»×ÜÊÇÇåÎúµÄ¡£
-
-t, --tuples-only
-
¹Ø±Õ´òÓ¡ÁÐÃû³ÆºÍ½á¹ûÐмÆÊý½Å×¢µÈÐÅÏ¢¡£ÍêÈ«µÈЧÓÚ \t¡£
-
-T, --table-attr table_options
-
ÔÊÐíÄãÉùÃ÷·ÅÔÚ HTML table ±ê¼ÇÀïµÄÑ¡Ïî¡£²ÎÔÄ
\pset
»ñȡϸ½Ú¡£
-
-u
-
Èà psql ÔÚºÍÊý¾Ý¿âÁª½ÓÖ®ÌáʾÊäÈëÓû§µÄÓû§ÃûºÍ¿ÚÁî¡£
ÎÒÃDz»ÔÞ³ÉʹÓÃÕâ¸öÑ¡ÏÒòΪËüÔÚ¸ÅÄîÉÏÓЩ¶´¡££¨ÌáʾÊäÈë·ÇȱʡÓû§ÃûºÍÌáʾÊäÈëºó¶ËÒªÇóµÄ¿ÚÁîÊÇÍêÈ«Á½ÂëÊ¡££©ÎÒÃǹÄÀøÄãÓÃ-U
ºÍ -W Ñ¡ÏîÈ¡´ú¡£
-
-U, --username username
-
ÒÔÓû§ username ´úÌæȱʡÓû§ÓëÊý¾Ý¿âÁª½Ó¡££¨µ±È»£¬Äã±ØÐëÓÐÕâô×öµÄȨÏÞ¡££©
-
-v, --variable, --set assignment
-
½øÐÐÒ»´Î±äÁ¿·ÖÅ䣬ÏóÄÚ²¿ÃüÁî \set ÄÇÑù¡£×¢Ò⣬Èç¹ûÓбäÁ¿ÃûºÍÖµµÄ»°£¬Äã±ØÐëÔÚÃüÁîÐÐÉÏÓõȺŷָôËüÃÇ¡£ÒªÖØÖÃÒ»¸ö±äÁ¿£¬È¥µôµÈºÅ¡£Õâ¸ö·ÖÅäÊÇÔÚÆô¶¯µÄºÜÔçµÄ½×¶Î½øÐеģ¬ËùÒÔΪÄÚ²¿Ê¹Óñ£ÁôµÄ±äÁ¿¿ÉÄܱ»Ôٴθ²¸Ç¡£
-
-V, --version
-
ÏÔʾ psql °æ±¾¡£
-
-W, --password
-
ÒªÇó psql ÔÚÓëÒ»¸öÊý¾Ý¿âÁª½ÓÇ°ÌáʾÊäÈë¿ÚÁî¡£Õâ¸öÑ¡ÏÔÚÕû¸ö»á»°¹ý³ÌÖÐÓÐЧ£¬¼´Ê¹ÄãÓÃרÓÐÃüÁî
\connect
¸Ä±äÁËËùÁª½ÓµÄÊý¾Ý¿â¡£
¶ÔÓÚ°æ±¾7.0£¬Èç¹ûºó¶ËÒªÇó¿ÚÁîÈÏÖ¤£¬psql
×Ô¶¯Ìá³öÒ»¸ö¿ÚÁîÌáʾ·û¡£ÒòΪĿǰÕâ¸öÌØÐÔÊÇÒÔÒ»¸ö¡°hack¡±Îª»ù´¡£¬×Ô¶¯Ê¶±ðÓпÉÄÜÉñÃصØʧЧ£¬Òò´ËÓÃÕâ¸öÑ¡ÏîÇ¿ÖÆÒ»¸öÌáʾ·û¡£Èç¹ûûÓÐÉùÃ÷¿ÚÁîÌáʾ·û¶øºó¶ËÒªÇó¿ÚÁîÈÏÖ¤£¬ÄÇôÁª½ÓÆóͼ½«Ê§°Ü¡£
-
-x, --expanded
-
´ò¿ªÀ©Õ¹Ðиñʽģʽ£®µÈЧÓÚ \x¡£
-
-X, --no-psqlrc
-
²»¶ÁÈ¡Æô¶¯Îļþ ~/.psqlrc¡£
-
-?, --help
ÏÔʾ¹ØÓÚ psql ÃüÁîÐвÎÊýµÄ°ïÖú¡£
¸ß¼¶ÌØÐÔ
±äÁ¿
psql ÌṩÀàËÆͨ³£ Unix ÃüÁî shell ÄÇÑùµÄ±äÁ¿Ìæ»»ÌØÐÔ¡£Õâ¸öÌØÐÔÊÇÐÂÒýÈëµÄ»¹²»ÊǺܸ´ÔÓ£¬µ«ÊÇÎÒÃǼƻ®ÔÚ½ñºóÀ©Õ¹Ëü¡£±äÁ¿Ö»ÊǼòµ¥µÄÃû³Æ/ÖµµÄ¶Ô£¬ÕâÀïµÄÖµ¿ÉÒÔÊÇÈκγ¤¶ÈµÄÈκÎÖµ¡£ÒªÉèÖÃÒ»¸ö±äÁ¿£¬Ê¹ÓÃ
psql
רÓÐÃüÁî
\set£º
testdb=> \set foo bar
°Ñ±äÁ¿¡°foo¡± ÉèÖÃΪֵ¡°bar¡±¡£Òª¼ìË÷±äÁ¿µÄÄÚÈÝ£¬ÔÚ±äÁ¿ÃûÇ°Ãæ·ÅÉÏðºÅÈ»ºó°ÑËüÓÃÔÚÈÎÒâб¸ÜÃüÁîÀ
testdb=> \echo :foo
bar
×¢Ò⣺\set µÄ²ÎÊý·þ´ÓºÍÆäËûÃüÁîÒ»ÑùµÄÌæ»»¹æÔò¡£Òò´ËÄã¿ÉÒÔ¹¹ÔìÓÐȤµÄÒýÓã¬Ïó
\set
:foo 'something' ÕâÑù£¬»ñµÃ·Ö±ðÏóPerl
»ò PHPÄÇÑùÓÐÃûµÄ¡°ÈíÁ´½Ó¡±£¨¡°soft
links¡±£©»ò¡°±äÁ¿ ±äÁ¿¡±£¨¡°variable variables¡±£©¡£²»ÐÒµÄÊÇ£¨»òÕß ÍòÐҵģ¿£©£¬ÓÃÕâЩ¹¹Ôì²»ÄÜ×öÈκÎÓÐÓõÄÊÂÇé¡£ÁíÒ»·½Ã棬\set
bar :foo ÊÇÒ»¸ö·Ç³£ÓÐЧµÄ¿½±´±äÁ¿µÄ·½·¨¡£
Èç¹ûÄã²»´øµÚ¶þ¸ö²ÎÊýµ÷ÓÃ
\set£¬ÄÇôֻÊÇÉèÖÃÕâ¸ö±äÁ¿¶øûÓÐÖµ¡£ÒªÖØÖ㨻òɾ³ý£©Ò»¸ö±äÁ¿£¬Ê¹ÓÃÃüÁî
\unset¡£
psql µÄÄÚ²¿±äÁ¿¿ÉÒÔ°üÀ¨ÈÎÒâ˳Ðò£¬ÈÎÒâÊýÁ¿µÄ×Öĸ£¬Êý×ÖºÍÏ»®Ïß¡£ÓÐһЩ³£ÓñäÁ¿±»psql
ÁíÑÛÏà´ý¡£ËüÃÇÊÇһЩѡÏîÉèÖã¬ÕâЩѡÏîÔÚÔËÐÐʱ¿ÉÒÔͨ¹ý¸Ä±ä±äÁ¿µÄÖµ»òÕ߸ıäһЩӦÓõıíÏÖ״̬¶ø¸Ä±ä¡£¾¡¹ÜÄã¿ÉÒÔ°ÑÕâЩ±äÁ¿ÓÃÓÚÆäËûÓÃ;£¬µ«ÊÇÎÒÃDz»¹ÄÀøÕâô×ö£¬ÒòΪ³ÌÐòµÄÌØÐÔ¿ÉÄÜ»áºÜ¿ì±äµÃ·Ç³£Ææ¹Ö¡£Í¨³££¬ËùÓÐÌØÊâ¶Ô´ýµÄ±äÁ¿¶¼ÊÇÓÉ´óд×Öĸ×é³É£¨¿ÉÄÜ»¹ÓÐÊý×ÖºÍÏ»®Ïߣ©¡£ÎªÁ˱£Ö¤ºÍδÀ´µÄ×î´óÏ޶ȵļæÈÝÐÔ£¬Çë±ÜÃâʹÓÃÕâÑùµÄ±äÁ¿¡£ÏÂÃæÊÇÒ»¸öËùÓÐÌØÊâ¶Ô´ýµÄ±äÁ¿ÁÐ±í¡£
-
DBNAME
-
ÄãÕýÔÚÁª½Ó×ŵÄÊý¾Ý¿âÃû³Æ¡£Ã¿´ÎÄãÓëÒ»¸öÊý¾Ý¿âÁª½á¶¼»áÉèÖÃÕâ¸öÖµ£¨°üÀ¨³ÌÐòÆô¶¯£©£¬µ«ÊÇ¿ÉÒÔɾ³ý¡£
-
ECHO
-
Èç¹ûÖÃΪ¡°all¡±£¬ÊäÈëµÄ»òÕßÀ´×ÔÒ»¸ö½Å±¾µÄËùÓÐÐÐÔÚ·ÖÎö»òÖ´ÐÐÇ°¶¼Ð´µ½±ê×¼Êä³ö¡£ÒªÔÚ³ÌÐòÆô¶¯Ê±ÉùÃ÷ÕâЩ£¬Ê¹ÓÃ-a
¿ª¹Ø¡£Èç¹ûÉèÖÃΪ¡°queries¡±£¬psql
Ö»ÊÇÔÚ²éѯ·¢Ë͸øºó¶Ë֮ǰ´òÓ¡³öÀ´¡£ÊµÏÖÕâ¸ö¹¦ÄܵÄÃüÁîÐÐÑ¡ÏîÊÇ-e¡£
-
ECHO_HIDDEN
-
µ±ÉèÖÃÁËÕâ¸ö±äÁ¿²¢ÇÒÒ»¸ö·´Ð±¸ÜÃüÁî²éѯÊý¾Ý¿âʱ£¬Ê×ÏÈÏÔʾ²éѯ¡£ÕâÑùÄã¿ÉÒÔѧϰPostgreSQL
ÄÚ²¿µÄ¶«Î÷²¢ÇÒÔÚÄã×Ô¼ºµÄ³ÌÐòÀïÌṩÀàËƹ¦ÄÜ¡£Èç¹ûÄãÉèÖøñäÁ¿µÄֵΪ¡°noexec¡±£¬²éѯֻÊÇÏÔʾ³öÀ´µ«ÊÇʵ¼ÊÉϲ»·¢Ë͵½ºó¶ËºÍÖ´ÐС£
-
ENCODING
-
µ±Ç°µÄ¿Í»§¶Ë¶à×Ö½Ú±àÂ뷽ʽ¡£Èç¹ûÄãûÓÐÉèÖÃʹÓöà×Ö½Ú×Ö·û£¬Õâ¸ö±äÁ¿½«×ÜÊÇ°üº¬¡°SQL_ASCII¡±¡£
-
HISTCONTROL
-
Èç¹ûÕâ¸ö±äÁ¿ÉèÖÃΪ ignorespace£¬ÒÔ¿Õ¸ñ¿ªÊ¼µÄÐн«²»»á½øÈëÀúÊ·ÁÐ±í¡£Èç¹ûÉèÖÃΪ±äÁ¿
ignoredups£¬ÓëÒÔÇ°ÀúÊ·¼Ç¼ÀïÆ¥ÅäµÄÐÐÒ²²»»á½øÈëÀúÊ·¼Ç¼¡£Öµ
ignoreboth
ÊÇÉÏÃæÁ½¸öµÄ½áºÏ¡£Èç¹ûɾ³ý´Ë±äÁ¿»òÕßÆäֵΪÈκÎÓëÉÏÃæµÄÖµ²»Í¬µÄ¶«Î÷£¬ËùÓн»»¥Ä£Ê½¶ÁÈëµÄÐж¼±»±£´æÈëÀúÊ·ÁÐ±í¡£
-
×¢Ò⣺Õâ¸öÌØÐÔÊÇÎÞ³ÜµØ´Ó bash
ÀïØâÇÔÀ´µÄ¡££¨Òë×¢£ºÀÏÐÖ£¬Ì«¿ÍÆøÁË°É£¬Òª²»freesoftÓкÎÒâÒ壿£¡£º£©
-
HISTSIZE
´æÔÚÃüÁîÀúÊ·ÀïµÄÃüÁîµÄ¸öÊý¡£È±Ê¡ÖµÊÇ 500¡£
-
×¢Ò⣺Õâ¸öÌØÐÔÊÇÎÞ³ÜµØ´Ó bash
ÀïØâÇÔÀ´µÄ¡££º-£©
-
HOST
-
µ±Ç°ÄãÕýÁª½ÓµÄÊý¾Ý¿â·þÎñÆ÷Ö÷»ú¡£ÕâÊÇÔÚÿ´ÎÄãÓëÊý¾Ý¿âÁª½Óʱ£¨°üÀ¨³ÌÐòÆô¶¯£©ÉèÖõģ¬µ«ÊÇ¿ÉÒÔɾ³ý¡£
-
IGNOREEOF
-
Èç¹ûɾ³ý´Ë±äÁ¿£¬ÏòÒ»¸ö½»»¥µÄ psql
»á»°·¢ËÍÒ»¸ö EOF ×Ö·û£¨Í¨³£ÊÇ Control-D£©½«ÖÕÖ¹Ó¦Óá£Èç¹ûÉèÖÃΪһ¸öÊý×ÖÖµ£¬ÄÇôÔÚÓ¦ÓÃÖÕֹǰ¸ÃÊýÖµµÄ
EOF ×Ö·û½«±»ºöÂÔ¡£Èç¹ûÉèÖÃÁ˴˱äÁ¿µ«ÊÇûÓÐÊý×ÖÖµ£¬È±Ê¡ÊÇ 10¡£
-
×¢Ò⣺Õâ¸öÌØÐÔÊÇÎÞ³ÜµØ´Ó bash
ÀïØâÇÔÀ´µÄ¡£
-
LASTOID
-
×îºóÓ°ÏìµÄ oid Öµ£¬¼´Îª´ÓÒ»Ìõ INSERT »ò lo_insert ÃüÁî·µ»ØµÄÖµ¡£´Ë±äÁ¿Ö»±£Ö¤ÔÚÏÂÒ»Ìõ SQL
ÃüÁîµÄ½á¹ûÏÔʾ֮ǰÓÐЧ¡£
-
LO_TRANSACTION
Èç¹ûÄãʹÓà PostgreSQL ´ó¶ÔÏó½Ó¿Ú´æ´¢ÎÞ·¨·Å½øÒ»Ìõ¼Ç¼ÀïµÄÌØÊâÊý¾Ý£¬ËùÓвÙ×÷±ØÐë°üº¬ÔÚÒ»¸öÊÂÎñ¿éÀïÃæ¡££¨²ÎÔĹØÓÚ´ó¶ÔÏó½Ó¿ÚµÄÎĵµ»ñÈ¡¸ü¶àÐÅÏ¢¡££©ÒòΪpsql
ÔÚÄãµ÷ÓÃËüµÄÄÚ²¿ÃüÁî \lo_export£¬\lo_import£¬\lo_unlink
֮һʱÎÞ·¨¸ú×ÙÄãÊÇ·ñÓÐÒ»¸öÕýÔÚ´¦ÀíµÄÊÂÎñ£¬ËùÒÔËü±ØÐë²ÉȡһЩÈÎÒâµÄ¶¯×÷¡£Õâ¸ö¶¯×÷¿ÉÄÜÊǻؾíÈκÎÕýÔÚ´¦ÀíµÄÊÂÎñ£¬»òÕßÌá½»ÕâÑùµÄÊÂÎñ£¬»òÕßʲôҲ²»×ö¡£¶ÔÓÚºóÃæÒ»ÖÖÇé¿ö£¬Äã±ØÐëÌá½»Äã×Ô¼ºµÄ
BEGIN
TRANSACTION/COMMIT ¿é·ñÔò½á¹û½«ÊDz»¿ÉÔ¤Áϵģ¨Í¨³£µ¼ÖÂÔÚÈκÎÇé¿öÏÂÏ£ÍûµÄ¶¯×÷¶¼²»»á·¢Éú£©¡£
ҪѡÔñÄãÏ£Íû×öµÄÊ£¬Äã¿ÉÒ԰Ѵ˱äÁ¿ÉèÖÃΪ¡°rollback¡±£¬¡°commit¡±»ò¡°nothing¡±Ö®Ò»¡£È±Ê¡ÊǻؾíÊÂÎñ¡£Èç¹ûÄãÖ»ÊÇÏ£Íû×°ÔØÒ»¸ö»òÕßÉÙÊý¼¸¸ö¶ÔÏó£¬Õâ¸ö·½·¨ºÜºÃ¡£µ«ÊÇÈç¹ûÄãÏ£Íû´«ÊäÐí¶à´ó¶ÔÏó£¬ÎÒÃǽ¨Òé¸øËùÓÐÃüÁîÌṩһ¸öÏÔʽµÄÊÂÎñ¿é¡£
-
ON_ERROR_STOP
-
ȱʡʱ£¬Èç¹û·Ç½»»¥µÄ½Å±¾Åöµ½Ò»¸ö´íÎó£¬ÏóÒ»Ìõ´íÎóµÄSQL
²éѯ»òÕßÄÚ²¿×¨ÓÐÃüÁ´¦Àí»á¼ÌÐø½øÐС£ÕâÊÇpsql
µÄ´«Í³ÌØÐÔ£¬µ«ÊÇÓÐʱºòÎÒÃDz»Ì«Ï£ÍûÕâÑù¡£Èç¹ûÉèÖÃÁËÕâ¸ö±äÁ¿£¬½Å±¾´¦Àí½«ÂíÉÏÍ£Ö¹¡£Èç¹û¸Ã½Å±¾ÊÇ´ÓÁíÍâÒ»¸ö½Å±¾µ÷Óõģ¬ÄǸö½Å±¾Ò²»á°´Í¬ÑùµÄ·½Ê½Í£Ö¹¡£Èç¹û×îÍâ²ãµÄ½Å±¾²»ÊÇ´ÓÒ»´Î½»»¥µÄpsql
»á»°Öе÷ÓõĶøÊÇÓà -f Ñ¡Ïîµ÷Óõģ¬psql
½«·µ»Ø´íÎó´úÂë 3£¬ÒÔʾÕâ¸öÇé¿öÓëÖÂÃü´íÎóÌõ¼þµÄÇø±ð£¨´íÎó´úÂë 1£©¡£
-
PORT
-
µ±Ç°ÄãÕýÔÚÁª½ÓµÄÊý¾Ý¿â·þÎñÆ÷µÄ¶Ë¿Ú¡£ÕâÊÇÔÚÿ´ÎÄãÓëÊý¾Ý¿âÁª½Óʱ£¨°üÀ¨³ÌÐòÆô¶¯£©ÉèÖõģ¬µ«ÊÇ¿ÉÒÔɾ³ý¡£
-
PROMPT1, PROMPT2, PROMPT3
ÕâЩָÃ÷ psql ÏÔʾµÄÌáʾ·û¿´ÉÏÈ¥Ïóʲô¡£²ÎÔÄÏÂÃæµÄ "Ìáʾ£¨·û£©"
¡£
-
QUIET
-
Õâ¸ö±äÁ¿µÈЧÓÚÃüÁîÐÐÑ¡Ïî -q¡£¿ÉÄÜÔÚ½»»¥Ä£Ê½ÏÂûÓÐʲôÓá£
-
SINGLELINE
-
Õâ¸ö±äÁ¿µÈЧÓÚÉèÖÃÃüÁîÐÐÑ¡Ïî -S¡£Äã¿ÉÒÔÔÚÔËÐÐʱɾ³ý»òÉèÖÃËü¡£
-
SINGLESTEP
-
Õâ¸ö±äÁ¿µÈЧÓÚÃüÁîÐÐÑ¡Ïî -s¡£
-
USER
-
µ±Ç°ÄãÕýÓÃÓÚÁª½ÓµÄÊý¾Ý¿âÓû§¡£ÕâÊÇÔÚÿ´ÎÄãÓëÊý¾Ý¿âÁª½Óʱ£¨°üÀ¨³ÌÐòÆô¶¯£©ÉèÖõģ¬µ«ÊÇ¿ÉÒÔɾ³ý/ÖØÖá£
SQL Interpolation
Ò»¸ö¸½¼ÓµÄ
psql ±äÁ¿µÄÓÐÓÃÌØÐÔÊÇÄã¿ÉÒÔ°ÑËüÃÇÌæ»»£¨¡°¸Äд¡±£©³ÉÕý¹æµÄ
SQL
Óï¾ä¡£ÕâÑù×öµÄÓ﷨ͬÑù»¹ÊDZäÁ¿ÃûÇ°Ãæ¼ÓÒ»¸öðºÅ£¨£º£©¡£
testdb=> \set foo 'my_table'
testdb=> SELECT * FROM :foo;
½«»á²éѯ±í
my_table¡£±äÁ¿µÄÖµÊÇÖð×Ö¿½±´µÄ£¬ËùÒÔËüÉõÖÁ¿ÉÒÔ°üº¬²»¶Ô³ÆµÄÒýºÅ»ò·´Ð±¸ÜÃüÁî¡£Äã±ØÐë±£Ö¤ÄãÊäÈëµÄ¶«Î÷ÊÇÓÐÒâÒåµÄ¡£±äÁ¿Ìæ»»½«²»»áÔÚÒýÆðÀ´µÄ
SQL
Óï¾äÀïÃæ·¢Éú¡£
ÀûÓÃÕâ¸ö¹¦ÄܵÄÒ»¸öʱ÷ÖµÄÓ¦ÓÃÊÇͨ¹ýʹÓÃÒ»¸öËæºóµÄÓï¾äÖÐ×îºó²åÈëµÄOID
½¨Á¢Ò»¸öÍâ¼ü£¨scenario £¿£©¡£ÁíÒ»¸ö¿ÉÄÜÓõ½Õâ¸ö»úÖƵĵط½ÊÇ°ÑÒ»¸öÎļþµÄÄÚÈÝ¿½±´µ½Ò»¸öÓòÀïÃæÈ¥¡£Ê×ÏÈ°ÑÎļþ×°Ôص½Ò»¸ö±äÁ¿È»ºóÏëÉÏÃæÄÇÑù´¦Àí¡£
testdb=> \set content '\'' `cat my_file.txt` '\''
testdb=> INSERT INTO my_table VALUES (:content);
ÕâÑù´¦ÀíµÄÒ»¸ö¿ÉÄÜÎÊÌâÊÇ
my_file.txt ¿ÉÄÜ°üº¬µ¥ÒýºÅ¡£ÕâЩÐèÒª±»×ªÒâÒÔÃâÔÚ´¦ÀíµÚÈýÐÐʱ²»»áµ¼ÖÂÓï·¨´íÎ󡣿ÉÒÔʹÓóÌÐò
sed
À´×öÕâ¸ö´¦Àí£º
testdb=> \set content `sed -e "s/'/\\\\\\'/g" < my_file.txt`
¹Û²ìÕýÈ·ÊýÁ¿µÄ·´Ð±¸Ü£¨6£©£¡Äã¿ÉÒÔÕâÑù½âÊÍËü£ºÔÚ
psql
·ÖÎöÍêÕâÐкó£¬Ëü°Ñ
sed -e "s/'/\\\'/g" < my_file.txt ´«µÝ¸ø
shell¡£shell ½«¶ÔË«ÒýºÅÀïµÄ¶«Î÷×öÆä´¦ÀíÈ»ºóÓòÎÊý
-e ºÍ
s/'/\\'/g
Ö´ÐÐ
sed¡£µ±
sed
·ÖÎöÕâЩʱËü½«°ÑË«·´Ð±¸ÜÌ滻Ϊµ¥¸ö·´Ð±¸ÜÈ»ºó½øÐÐÌæ»»¡£¿ÉÄÜÓÐʱºòÄãÈÏΪËùÓÐ
Unix ÃüÁîʹÓÃͬһ¸öתÒâ×Ö·ûÊǸöºÃÊ¡£µ«¾ßÓзí´ÌÒâζµÄÊÂʵÊÇÄã¿ÉÄܲ»µÃ²»×ªÒâËùÓз´Ð±¸Ü£¬ÒòΪ
SQL
Îı¾³£Á¿Í¬ÑùÒ²²ÒÔâÕâÖÖ½âÊÍ¡£ÕâÖÖÇé¿öÏÂÄã¿ÉÄÜ×îºÃÔÚÍⲿ׼±¸Îļþ¡£
ÒòΪðºÅÒ²¿ÉÒԺϷ¨µÄ³öÏÖÔÚ²éѯÀ±ãÓÐÏÂÃæ¹æÔòµÄÓ¦ÓãºÈç¹ûûÓÐÉèÖñäÁ¿£¬×Ö·ûÐòÁС°Ã°ºÅ+Ãû³Æ¡±²»»á±»¸Ä±ä¡£ÔÚÈκÎÇé¿öÏÂÄ㶼¿ÉÒÔÓ÷´Ð±¸ÜתÒâðºÅÒÔ±£»¤ËüÃâÓÚ±»½âÊÍ¡££¨±äÁ¿µÄðºÅÓï·¨ÊÇSQL
ÓÃÓÚǶÈë²éѯÓïÑԵıê×¼£¬Èç ecpg¡£ÓÃÓÚÊý×éƬ¶ÎºÍÀàÐÍת»»µÄðºÅÓï·¨ÊÇPostgreSQL
À©Õ¹£¬Òò´ËÓгåÍ»¡££©
Ìáʾ£¨·û£©
psql ʹÓõÄÌáʾ·û¿ÉÒÔ¸ù¾ÝÄãµÄϲºÃ¿Í»§»¯¡£Èý¸ö±äÁ¿
PROMPT1£¬
PROMPT2
ºÍ
PROMPT3 °üº¬ÃèÊöÌáʾ·ûµÄÍâ¹ÛµÄ×Ö´®ºÍÌØÊâתÒâÐòÁС£Prompt 1
ÊÇ
psql ÇëÇóÒ»¸öвéѯʱµÄʹÓõÄÕý³£Ìáʾ·û¡£Prompt
2 ÊÇÔÚÒ»¸ö²éѯÊäÈëÆÚ´ý¸ü¶àÊäÈëʱ£¨ÒòΪ²éѯûÓÐÓÃÒ»¸ö·ÖºÅ½áÊø»òÕßÒýºÅûÓйرգ©ÏÔʾµÄÌáʾ·û¡£Prompt
3 ÔÚÄãÔËÐÐÒ»¸ö
SQL COPY ÃüÁîºÍµÈ´ýÄãÔÚÖÕ¶ËÉϼüÈë¼Ç¼ʱʹÓá£
ÏàÓ¦µÄÌáʾ·û±äÁ¿µÄÖµÊÇ°´×ÖÃæ´òÓ¡µÄ£¬³ý·ÇÅöµ½Ò»¸ö°Ù·ÖºÅ£¨¡°%¡±£©¡£ÕâʱijЩÆäËûµÄÎı¾±»Ìæ»»£¬Ì滻ΪºÎÎïÈ¡¾öÓÚÏÂÒ»¸ö×Ö·û¡£ÒѶ¨ÒåµÄÌæ»»ÊÇ£º
-
%M
-
Êý¾Ý¿â·þÎñÆ÷µÄÖ÷»úÃû£¨»òÕßÊÇ¡°localhost¡±Èç¹ûʹÓõÄÊÇ Unix ÓòÌ×½Ó×Ö£©¡£
-
%m
-
Êý¾Ý¿â·þÎñÆ÷µÄÖ÷»úÃûɾȥµÚÒ»¸öµãºóÃæµÄ²¿·ÖʣϵĶ«Î÷¡££¨Òë×¢£º¶ÌÓòÃû£©
-
%>
-
Êý¾Ý¿â·þÎñÆ÷ÕýÔÚÕìÌýµÄ¶Ë¿ÚºÅ¡£
-
%n
-
ÄãÁª½ÓʹÓõÄÓû§Ãû£¨²»ÊÇÄãµÄ±¾µØϵͳÓû§Ãû£©¡£
-
%/
-
µ±Ç°Êý¾Ý¿âÃû³Æ¡£
-
%~
-
ÀàËÆ %/£¬µ«Èç¹ûÊý¾Ý¿âÊÇÄãµÄȱʡÊý¾Ý¿âÊä³öÊÇ¡°~¡± £¨²¨ÀËÏߣ¨tilde£©£©¡£
-
%#
-
Èç¹ûµ±Ç°Óû§ÊÇÊý¾Ý¿â³¬¼¶Óû§£¬Ê¹Óá°#¡±£¬·ñÔòÓá°>¡±¡£
-
%R
¶ÔÓÚ prompt 1 ͨ³£ÊÇ¡°=¡±£¬µ«ÊÇÈç¹ûÊǵ¥ÐÐģʽÔòÊÇ¡°^¡±£¬¶øÈç¹û»á»°ÓëÊý¾Ý¿â¶Ï¿ª£¨Èç¹û
\connect
ʧ°Ü¿ÉÄÜ·¢Éú£©ÊÇ¡°!¡±¡£¶ÔÓÚ prompt 2 ¸ÃÐòÁб»¡°-¡±£¬¡°*¡±£¬Ò»¸öµ¥ÒýºÅ»òÕßÒ»¸öË«ÒýºÅ´úÌ棬ÕâÈ¡¾öÓÚpsql
ÊÇ·ñµÈ´ý¸ü¶àµÄÊäÈ루ÒòΪ²éѯûÓÐÖÕÖ¹£¬»ò×ÅÕýÔÚÒ»¸ö /* ... */ ×¢ÊÍÀïÃ棬»òÕßÒòΪÄãÔÚÒýºÅÀïÃ棩¡£¶ÔÓÚ
prompt 3 ¸ÃÐòÁв»½âÊͳÉÈκζ«Î÷¡£
-
%digits
Èç¹û digits ÒÔ 0x ¿ªÍ·£¬ÄÇôÆäÓà×Ö·û±»½âÊͳÉÒ»¸öÊ®Áù½øÖÆÊý×Ö²¢ÇÒÌ滻Ϊ¶ÔÓ¦£¨Ê®Áù½øÖÆÂ룩µÄ×Ö·û¡£Èç¹ûµÚÒ»¸öÊý×ÖÊÇ
0
£¬¸Ã×Ö·û±»½âÊͳÉÒ»¸ö°Ë½øÖÆÊý×Ö²¢ÇÒÌ滻Ϊ¶ÔÓ¦µÄ£¨°Ë½øÖÆÂ룩µÄ×Ö·û¡£·ñÔòÈÏΪÊÇÒ»¸öÊ®½øÖÆÊý×Ö¡£
-
%:name:
psql ±äÁ¿ name µÄÖµ¡£²ÎÔÄ "±äÁ¿"
½Ú»ñȡϸ½Ú¡£
-
%`command`
command µÄÊä³ö£¬ÀàËÆÓÚͨ³£µÄ·´¹´ºÅ£¨¡°back-tick¡±£©Ìæ»»¡£
ÒªÔÚÌáʾ·ûÀï²åÈë°Ù·ÖºÅ£¬¼üÈë %%¡£È±Ê¡Ìáʾ·ûµÈЧÓÚ
'%/%R%#
' ÓÃÓÚ prompts 1 ºÍ 2£¬ÒÔ¼° '>> ' ÓÃÓÚ prompt 3¡£
×¢Ò⣺Õâ¸öÌØÐÔÊÇÎÞ³ÜµØ´Ó tcsh
ÀïØâÇÔÀ´µÄ¡£
ÔÓÏî
psql Õý³£½áÊøʱÏò shell ·µ»Ø 0£¬·¢Éú×ÔÉíÖÂÃü´íÎó£¨ÓùâÄڴ棬ÎļþûÓÐÕÒµ½£©Ê±·µ»Ø
1£¬Óëºó¶ËÁª½Ó³ö´íºÍ»á»°²»Êǽ»»¥µÄʱºò·µ»Ø 2£¬Èç¹ûÔÚÒ»¸ö½Å±¾ÀïÃæ·¢Éú´íÎó»òÕß±äÁ¿
ON_ERROR_STOP
±»ÉèÖÃÁË·µ»Ø 3¡£
ÔÚÆô¶¯Ö®Ç°£¬psql ÊÔͼ¶ÁÈ¡²¢Ö´ÐÐÎļþ
$HOME/.psqlrc
ÀïµÄÃüÁî¡£Õâ¸öÌØÐÔ¿ÉÒÔÓÃÀ´°´¿ÚζÉèÖÿͻ§¶Ë»òÕß·þÎñÆ÷£¨ÓÃ
\set
ºÍ
SET
ÃüÁ¡£
GNU readline
psql ΪÁ˱༺ͼìË÷ÃüÁîÐеķ½±ãÖ§³Ö readline
ºÍÀúÊ·¿â¡£ÃüÁîÀúÊ·´æ·ÅÔÚÄãµÄ¼ÒĿ¼µÄÒ»¸ö½Ð
.psql_history µÄÎļþÀ²¢ÇÒµ±
psql
Æô¶¯µÄʱºò»á×°ÔؽøÀ´¡£Tab-²¹ÆëͬÑùÒ²±»Ö§³Ö£¬¾¡¹Ü¸Ã²¹ÆëÂß¼²¢²»ÊÇÒ»¸ö
SQL
·ÖÎöÆ÷±Ø±¸µÄ¡£Èç¹û¿ÉÄÜ£¬
psql »á×Ô¶¯ÖÆ×÷³ÉʹÓÃÕâЩÌØÐÔ¡£Èç¹ûÒòijЩÔÒòÄ㲻ϲ»¶
tab ²¹Æ룬Äã¿ÉÒÔ°ÑÏÂÃ漸ÐзÅÔÚÄãµÄ¼ÒĿ¼µÄÒ»¸ö½Ð
.inputrc µÄÎļþÀï¹Ø±ÕÕâ¸öÌØÐÔ£º
$if psql
set disable-completion on
$endif
£¨Õâ²»ÊÇ
psql µÄÌØÐÔ£¬ÊÇ
readline
µÄ¡£²Î¿¼ËüµÄÎĵµ»ñÈ¡¸ü¶àϸ½Ú¡££©
Èç¹ûÄã°²×°ÁËÐжÁ£¨readline£©¿â£¬µ«ÊÇ psql
ºÃÏóûÓÐʹÓÃËü£¬Äã±ØÐëÈ·±£ PostgreSQL
µÄ¶¥¼¶ configure ½Å±¾¿ÉÒÔÕÒµ½¸Ã¿â¡£configure ÐèÒªÄܹ»ÔÚºÏÊʵÄĿ¼ÀïÕÒµ½¿â
libreadline.a
£¨»òÕßÒ»¸öµÈЧµÄ¹²Ïí¿â£©ºÍ Í·Îļþ readline.h ºÍ history.h
£¨»òÕß readline/readline.h ºÍ
readline/history.h£©¡£Èç¹ûÄãµÄ¿âºÍÍ·Îļþ°²×°ÔÚij¸öÒõ°µµÄ½ÇÂ䣬Äã±ØÐë¸æËß
configure
ËüÃÇÔÚÄÄÀÀýÈ磺
$ ./configure --with-includes=/opt/gnu/include --with-libs=/opt/gnu/lib ...
È»ºóÄã²»µÃ²»ÖØбàÒë
psql £¨²»±ØÖØбàÒëÕû¸ö´úÂëÊ÷£©¡£
GNU ÐжÁ¿â¿ÉÒÔ´Ó GNU
¼Æ»®µÄ FTP ·þÎñÆ÷¡¡ftp://ftp.gnu.org
µÃµ½¡£
Àý×Ó
×¢Ò⣺±¾½ÚÖ»ÊÇÏÔʾÁË psql
ÉÙÊý¼¸¸öÀý×Ó¡£Èç¹ûÄãÏ£Íûѧϰ SQL »òÕßÊìϤ Postgres£¬Äã¿ÉÄÜÔ¸ÒâÔĶÁһϰüº¬ÔÚÕâ¸ö°æ±¾ÀïµÄ½Ì³Ì¡£
µÚÒ»¸öÀý×ÓÑÝʾÁËÈçºÎ°ÑÒ»¸ö²éѯ·Ö³É¶à¸öÐнøÐÐÊäÈë¡£×¢ÒâÌáʾ·ûµÄ±ä»¯¡£
testdb=> CREATE TABLE my_table (
testdb-> first integer not null default 0,
testdb-> second text
testdb-> );
CREATE
ÏÖÔÚÔÙ¿´¿´±í¶¨Ò壺
testdb=> \d my_table
Table "my_table"
Attribute | Type | Modifier
-----------+---------+--------------------
first | integer | not null default 0
second | text |
ÕâÀïÄã¾ö¶¨°ÑÌáʾ·û±ä³É¸üÓÐȤµÄ¶«Î÷£º
testdb=> \set PROMPT1 '%n@%m %~%R%# '
peter@localhost testdb=>
¼ÙÉèÄãÓÃÊý¾ÝÌî³äÁË±í²¢ÇÒÏë¿´Ò»ÑÛ£º
peter@localhost testdb=> SELECT * FROM my_table;
first | second
-------+--------
1 | one
2 | two
3 | three
4 | four
(4 rows)
×¢Òâ int4 ÁÐÊÇÔõÑùÓÒ¶ÔÆëµÄÒÔ¼° text ÁÐÊÇÈçºÎ×ó¶ÔÆëµÄ¡£Äã¿ÉÒÔÓÃ
\pset
ÃüÁîÈÃÕâ¸ö²éѯ¿´ÆðÀ´²»Ò»Ñù¡£
peter@localhost testdb=> \pset border 2
Border style is 2.
peter@localhost testdb=> SELECT * FROM my_table;
+-------+--------+
| first | second |
+-------+--------+
| 1 | one |
| 2 | two |
| 3 | three |
| 4 | four |
+-------+--------+
(4 rows)
peter@localhost testdb=> \pset border 0
Border style is 0.
peter@localhost testdb=> SELECT * FROM my_table;
first second
----- ------
1 one
2 two
3 three
4 four
(4 rows)
peter@localhost testdb=> \pset border 1
Border style is 1.
peter@localhost testdb=> \pset format unaligned
Output format is unaligned.
peter@localhost testdb=> \pset fieldsep ","
Field separator is ",".
peter@localhost testdb=> \pset tuples_only
Showing only tuples.
peter@localhost testdb=> SELECT second, first FROM my_table;
one,1
two,2
three,3
four,4
»¹¿ÉÒÔÓọ̈¨Ëõд£©ÃüÁ
peter@localhost testdb=> \a \t \x
Output format is aligned.
Tuples only is off.
Expanded display is on.
peter@localhost testdb=> SELECT * FROM my_table;
-[ RECORD 1 ]-
first | 1
second | one
-[ RECORD 2 ]-
first | 2
second | two
-[ RECORD 3 ]-
first | 3
second | three
-[ RECORD 4 ]-
first | 4
second | four
¸½Â¼
벡ºÍÉùÃ÷
һЩ psql µÄÔçÆÚ°æ±¾ÔÊÐíµÚÒ»¸ö²ÎÊý£¨µ¥×Öĸ£©Ö±½Ó¸úÔÚÃüÁîºóÃæ¡£³öÓÚ¼æÈÝÐÔÔÒò£¬Õâ¸öÌØÐÔÈÔÈ»ÔÚijЩ³Ì¶ÈÉϱ»Ö§³Ö£¬µ«ÊÇÎÒ²»×¼±¸ÔÚÕâÀïÏêϸ½âÊÍ£¬ÒòΪÎÒ²»¹ÄÀøÕâÑùʹÓᣲ»¹ýÈç¹ûÄãÊÕµ½ÄªÃûÆäÃîµÄÐÅÏ¢£¬ÏëÏëÕâ¸öÓ÷¨¡£ÀýÈç
testdb=> \foo
Field separator is "oo".
¿ÉÄܲ»ÊÇÄãÏëÒªµÄ¶«Î÷¡£
psql Ö»ÄÜÓëͬ°æ±¾µÄ·þÎñÆ÷ƽÎȵع¤×÷¡£Õâ²»Òâζ×ÅÆäËû×éºÏ»áÍêȫʧ°Ü£¬µ«ÊÇ¿ÉÄÜÓÐ΢СµÄ»òÕß²»ÄÇô΢СµÄÎÊÌâ¡£
ÔÚÒ»¸ö¡°¿½±´È롱£¨Êý¾Ý·¢Ë͸ø·þÎñÆ÷£©¹ý³ÌÖа´Ï Control-C ²¢²»ÏÔʾ³ö×îµäÐ͵ÄÌØÕ÷¡£Èç¹ûÄãÊÕµ½Ò»ÌõÀàËÆÓÚÏÂÃæÕâÑùµÄÐÅÏ¢¡°PQexec:
you gotta get out of a COPY state yourself¡±£¬Ö»ÐèÒªÊäÈë \c - -
ÖØÖÃÁª½Ó¼´¿É¡£