psql

Name

psql --  PostgreSQL ½»»¥ÖÕ¶Ë

Synopsis

psql [options] [dbname [user]]

ÃèÊö

psql ÊÇÒ»¸öÒÔÖÕ¶ËΪ»ù´¡µÄ PostgreSQL Ç°¶Ë¡£ËüÔÊÐíÄã½»»¥µØ¼üÈë²éѯ£¬°ÑËüÃÇ·¢³ö¸ø PostgreSQL£¬ È»ºó¿´¿´²éѯµÄ½á¹û¡£ÁíÍ⣬ÊäÈë¿ÉÒÔÀ´×ÔÒ»¸öÎļþ¡£»¹ÓУ¬ËüÌṩÁË Ò»Ð©ÔªÃüÁîºÍ¶àÖÖÀà shell µØÌØÐÔÀ´ÊµÏÖÊéд½Å±¾ÒÔ¼°¶Ô´óÁ¿ÈÎÎñµÄ ×Ô¶¯»¯¡£

Ñ¡Ïî

-a
--echo-all

ÔÚ¶ÁÈ¡ÐÐʱÏòÆÁÄ»´òÓ¡ËùÓÐÄÚÈÝ¡£ Õâ¸öÑ¡ÏîÔڽű¾´¦Àíʱ±È½»»¥Ä£Ê½Ê±¸üÓÐÓá£Õâ¸öÑ¡ÏîµÈЧÓÚÉèÖñäÁ¿ ECHO Ϊ all¡£

-A
--no-align

Çл»Îª·Ç¶ÔÆëÊä³öģʽ¡££¨È±Ê¡Êä³öģʽÊǶÔÆëµÄ¡££©

-c query
--command query

ÉùÃ÷ psql ½«Ö´ÐÐÒ»Ìõ²éѯ×Ö´®£¬query £¬È»ºóÍ˳ö£®ÕâÒ»µãÔÚ shell ½Å±¾ÀïºÜÓÐÓá£

query ±ØÐëÊÇÒ»ÌõÍêÈ«¿ÉÒÔ±»ºó¶Ë·ÖÎöµÄ²éѯ×Ö´®£¨ Ò²¾ÍÊÇ˵£¬Ëü²»°üº¬ psqlÌØÓеÄÌØÐÔ£©£¬ »òÕßÊÇÒ»¸ö·´Ð±¸ÜÃüÁî¡£ÕâÑùÄã¾Í ²»»á»ìºÏ SQL ºÍ psql ÔªÃüÁî¡£ÒªÏë»ìºÏʹÓã¬Äã¿ÉÒÔ°Ñ×Ö´®¶¨Ïòµ½ psqlÀÏóÕâÑù£º echo "\x \\ select * from foo;" | psql¡£

-d dbname
--dbname dbname

ÉùÃ÷ÏëÒªÁª½ÓµÄÊý¾Ý¿âÃû³Æ£®µÈЧÓÚÔÚÃüÁîÐÐÐÐÉÏ°Ñ dbname ÉùÃ÷ΪµÚÒ»¸ö·ÇÑ¡Ïî²ÎÊý¡£

-e
--echo-queries

ÏÔʾËùÓÉ·¢Ë͸øºó¶ËµÄ²éѯ£® µÈЧÓڰѱäÁ¿ ECHO Ϊ queries¡£

-E
--echo-hidden

»ØÏÔÓÉ \d ºÍÆäËû·´Ð±¸ÜÃüÁîÉú³ÉµÄʵ¼Ê²éѯ¡£ Èç¹ûÄãÏ£ÍûÔÚÄã×Ô¼ºµÄ³ÌÐòÀï°üº¬ÀàËƵŦÄÜ£¬ Äã¾Í¿ÉÒÔʹÓÃÕâ¸öÑ¡Ïî¡£ÕâµÈЧÓÚ ÔÚpsqlÀïÉèÖñäÁ¿ECHO_HIDDEN¡£

-f filename
--file filename

ʹÓà filename ×÷Ϊ²éѯµÄÓï¾äÔ´¶ø²»Êǽ»»¥Ê½¶ÁÈë²éѯ¡£ ÔÚ´¦ÀíÍêÎļþºó£¬psql ½áÊø¡£Õâ¸öÑ¡ÏîÔںܶ෽ÃæµÈЧÓÚÄÚ²¿ÃüÁî \i¡£

Èç¹û filename ÊÇ - (Á¬×Ö·û)£¬Ôò´Ó±ê×¼ÊäÈë¶ÁÈ¡£®

ʹÓÃÕâ¸öÑ¡ÏîÓëÓà psql < filename ÓÐ΢СµÄÇø±ð¡£Í¨³££¬Á½Õ߶¼»Ø°´ÕÕÄãÔ¤ÆÚÄÇÑùÔËÐУ¬ µ«ÊÇʹÓà -f´ò¿ªÁËһЩºÜºÃµÄÌØ ÐÔ£¬±ÈÈç´øÐкŵĴíÎóÐÅÏ¢¡£¶øÇÒ£¬Ê¹ÓÃÕâ¸öÑ¡ÏÓпÉÄÜÓмõСÆô¶¯¸ººÉµÄ»ú»á¡£ ÁíÒ»·½Ã棬Èç¹ûÄã°ÑËùÓÐÄÚÈÝÊÖ¹¤ÊäÈ룬ʹÓà shell ÊäÈ붨ÏòµÄ·½Ê½£¨ÀíÂÛÉÏ£©Äܱ£Ö¤Éú³ÉºÍÄãÒѾ­µÃµ½µÄÍêÈ«Ò»ÑùµÄÊä³ö £¨Òë×¢£ºÖظ´ÔËÐÐÃüÁ¡£

-F separator
--field-separator separator

ʹÓà separator ×÷ΪÓò·Ö¸ô·û£®µÈЧÓÚ \pset fieldsep »ò \f¡£

-h hostname
--host hostname

ÉùÃ÷ÕýÔÚÔËÐÐ postmaster µÄÖ÷»úÃû£® Èç¹ûÖ÷»úÃûÒÔб¿¸¿ªÍ·£¬ÔòËü±»ÓÃ×öµ½ Unix ÓòÌ×½Ó×ֵķ¾¶£®

-H
--html

´ò¿ªHTML¸ñʽÊä³ö¡£µÈЧÓÚ \pset format html»ò \H ÃüÁî¡£

-l
--list

ÁгöËùÓпÉÓõÄÊý¾Ý¿â£¬È»ºóÍ˳ö£®ÆäËû·ÇÁª½ÓÑ¡Ï±»ºöÂÔ£®ÀàËÆÓÚÄÚ²¿ÃüÁî \list¡£

-o filename
--output filename

½«ËùÓвéѯÊä³ö¶¨Ïòµ½Îļþ filename ¡£Õâ¸öÑ¡ÏîµÈЧÓÚÃüÁî \o¡£

-p port
--port port

ÉùÃ÷±» postmaster ÓÃÓÚÕìÌýµÄ TCP/IP ¶Ë¿Ú»òʹÓõÄȱʡ±¾µØ Unix Ö÷¿ØÌ×½Ó×ÖÎļþ¾ä±ú£® ȱʡµÄÊÇ»·¾³±äÁ¿PGPORTµÄÖµ£¬Èç¹û ûÓÐÉèÖõĻ°ÊDZàÒëÊÇÉùÃ÷µÄ¶Ë¿Ú£¬Í¨³£ÊÇ 5432¡£

-P assignment
--pset assignment

ÔÊÐíÄãÔÚÃüÁîÐÐÉÏÒÔ \psetµÄ·ç¸ñÉèÖôòÓ¡Ñ¡Ïî¡£ ҪעÒâµÄÊÇÄãÔÚÕâÀïÓõȺŷָîÃû³ÆºÍÖµ£¬¶ø²»ÄÜÓÿոñ¡£ Òò´ËÒª°ÑÊä³ö¸ñʽÉèÖÃΪ LaTeX£¬Äã¿ÉÒÔÇÃÈë -P format=latex¡£

-q
--quiet

ÉùÃ÷ psql ½«"°²¾²µØ"Ö´Ðд¦ÀíÈÎÎñ£® ȱʡʱpsql½«´òÓ¡»¶Ó­ºÍÐí¶àÆäËûÊä³öÐÅÏ¢¡£ Èç¹ûʹÓÃÁË´ËÑ¡ÏÕâЩ¶¼²»³öÏÖ¡£ÕâÔÚºÍ -c Ñ¡ÏîÒ»ÆðʹÓÃʱºÜÓÐЧ£®ÔÚ psql ÀÄã¿ÉÒÔͨ¹ýÉèÖà QUIET ±äÁ¿ÊµÏÖͬÑùЧ¹û¡£

-R separator
--record-separator separator

ʹÓà separator ×öΪ¼Ç¼·Ö¸ô·û¡£ µÈЧÓÚ\pset recordsepÃüÁî¡£

-s
--single-step

½øÈëµ¥²½Ä£Ê½ÔËÐС£Òâζ×Åÿ¸ö²éѯÔÚ·¢Íùºó¶Ë֮ǰ¶¼ÒªÌáʾÓû§£¬ ÓÃÕâ¸öÑ¡ÏîÒ²¿ÉÒÔÈ¡ÏûÖ´ÐС£´ËÑ¡ÏîÖ÷ÒªÓÃÓÚµ÷ÊԽű¾¡£

-S
--single-line

½øÈëµ¥ÐÐÔËÐÐģʽ£¬Õâʱÿ¸ö²éѯ¶¼½«ÓÉ»»Ðзû½áÊø£¬Ïó·ÖºÅÄÇÑù¡£

×¢Òâ: ×¢ÒâÕâ¸öģʽÊǸøÄÇЩ¼á³ÖÒªÕâ¸öÌØÐÔµÄÈ˵ģ¬ÎÒÃDz»¹ÄÀøÄãÕâôÓᣠʵ¼ÊÉÏ£¬Èç¹ûÄãÔÚÒ»ÐÐÀï»ìºÏʹÓà SQL ºÍ ÔªÃüÁִÐеÄ˳Ðò¶Ô²»ÊìÁ·µÄÓû§¶øÑÔ²»×ÜÊÇÇåÎúµÄ¡£

-t
--tuples-only

¹Ø±Õ´òÓ¡ÁÐÃû³ÆºÍ½á¹ûÐмÆÊý½Å×¢µÈÐÅÏ¢¡£ÍêÈ«µÈЧÓÚ ÔªÃüÁî\t¡£

-T table_options
--table-attr table_options

ÔÊÐíÄãÉùÃ÷·ÅÔÚ HTML table ±ê¼ÇÀïµÄÑ¡Ïî¡£ ²ÎÔÄ \pset »ñȡϸ½Ú¡£

-u

Èà psql ÔÚºÍÊý¾Ý¿âÁª½ÓÖ®ÌáʾÊäÈëÓû§µÄÓû§ÃûºÍ¿ÚÁî¡£

ÎÒÃDz»ÔÞ³ÉʹÓÃÕâ¸öÑ¡ÏÒòΪËüÔÚ¸ÅÄîÉÏÓЩ¶´¡£ £¨ÌáʾÊäÈë·ÇȱʡÓû§ÃûºÍÌáʾÊäÈëºó¶ËÒªÇóµÄ¿ÚÁîÊÇÍêÈ«Á½ÂëÊ¡££©ÎÒÃÇ¹Ä ÀøÄãÓà -U ºÍ -W Ñ¡ÏîÈ¡´ú¡£

-U username
--username username

ÒÔÓû§ username ´úÌæȱʡÓû§ÓëÊý¾Ý¿âÁª½Ó¡££¨µ±È»£¬Äã±ØÐëÓÐÕâô×öµÄȨÏÞ¡££©

-v assignment
--set assignment
--variable assignment

½øÐÐÒ»´Î±äÁ¿·ÖÅ䣬ÏóÄÚ²¿ÃüÁî \set ÄÇÑù¡£ ×¢Ò⣬Èç¹ûÓбäÁ¿ÃûºÍÖµµÄ»°£¬Äã±ØÐëÔÚÃüÁîÐÐÉÏÓõȺŷָôËüÃÇ¡£ÒªÖØÖÃÒ»¸ö±äÁ¿£¬ È¥µôµÈºÅ¡£Õâ¸ö·ÖÅäÊÇÔÚÆô¶¯µÄºÜÔçµÄ½×¶Î½øÐеģ¬ ËùÒÔΪÄÚ²¿Ê¹Óñ£ÁôµÄ±äÁ¿¿ÉÄܱ»Ôٴθ²¸Ç¡£

-V
--version

ÏÔʾpsql°æ±¾¡£

-W
--password

ÒªÇó psql ÔÚÓëÒ»¸öÊý¾Ý¿âÁª½ÓÇ°ÌáʾÊäÈë¿ÚÁî¡£ Õâ¸öÑ¡ÏÔÚÕû¸ö»á»°¹ý³ÌÖÐÓÐЧ£¬¼´Ê¹ÄãÓÃÔªÃüÁî \connect ¸Ä±äÁËËùÁª½ÓµÄÊý¾Ý¿â¡£

ÔÚµ±Ç°°æ±¾ÀÈç¹ûºó¶ËÒªÇó¿ÚÁîÈÏÖ¤£¬psql ×Ô¶¯Ìá³öÒ»¸ö¿ÚÁîÌáʾ·û¡£ÒòΪĿǰÕâ¸öÌØÐÔÊÇÒÔÒ»¸ö¡°hack¡±Îª»ù´¡£¬ ×Ô¶¯Ê¶±ðÓÐ ¿ÉÄÜÉñÃصØʧЧ£¬Òò´ËÓÃÕâ¸öÑ¡ÏîÇ¿ÖÆÒ»¸öÌáʾ·û¡£ Èç¹ûûÓÐÉùÃ÷¿ÚÁîÌáʾ·û¶øºó¶ËÒªÇó¿ÚÁîÈÏÖ¤£¬ÄÇôÁª½ÓÆóͼ½«Ê§°Ü¡£

-x
--expanded

´ò¿ªÀ©Õ¹Ðиñʽģʽ£®µÈЧÓÚ \x¡£

-X,
--no-psqlrc

²»¶ÁÈ¡Æô¶¯Îļþ ~/.psqlrc¡£

-?
--help

ÏÔʾ¹ØÓÚpsqlÃüÁîÐвÎÊýµÄ°ïÖú¡£

²»ÊÇÔÚËùÓÐƽ̨É϶¼ÄÜÓó¤Ñ¡Ïî¡£

Í˳ö״̬

Èç¹ûÕý³£½áÊø£¬ÄÇô psql Ïò shell ·µ»Ø 0£¬Èç¹û×ÔÉí·¢ÉúÖÂÃü´íÎó£¬Ôò·µ»Ø 1£¨ÄÚ´æÓþ¡£¬Î´ÕÒµ½ÎļþµÈ£©£¬ Èç¹ûºÍÊý¾Ý¿âµÄÁ¬½ÓʧЧ¶øÇһỰ²»ÔÙ»îÔ¾Ôò·µ»Ø 2£¬Èç¹û½Å±¾ÖÐ ·¢Éú´íÎó²¢ÇÒÉèÖÃÁË ON_ERROR_STOP Ôò·µ»Ø 3¡£

Ó÷¨

ÓëÒ»¸öÊý¾Ý¿âÁª½Ó

psql ÊÇÒ»¸öÆÕͨµÄ PostgreSQL ¿Í»§¶ËÓ¦Óá£ÎªÁËÓëÒ»¸öÊý¾Ý¿âÁª½Ó£¬ÄãÐèÒªÖªµÀÄãµÄÄ¿±êÊý¾Ý¿â£¬ ·þÎñÆ÷µÄÖ÷»úÃûºÍ¶Ë¿ÚºÅÒÔ¼°ÄãÏ£ÍûÒÔ ÄĸöÓû§µÄÉí·Ý½øÐÐÁª½ÓµÈÐÅÏ¢¡£ÎÒÃÇ¿ÉÒÔͨ¹ýÃüÁîÐвÎÊý¸æËß psql ÕâЩÐÅÏ¢£¬·Ö±ðÊÇ -d£¬ -h£¬-p£¬ºÍ -U ¡£ Èç¹ûÓиö²ÎÊý²»ÊôÓÚÈκÎÑ¡ Ï¹Ø£¬ÄÇôËü»á±»½âÊͳÉÊý¾Ý¿âÃû £¨»òÕßÊÇÓû§Ãû£­Èç¹ûÊý¾Ý¿âÃû³ÆÒ²¸ø³öÁË£®£©¡£ ²»ÊÇËùÓÐÕâЩѡÏÊDZØÐëµÄ£¬È±Ê¡µÄÒ²¿ÉÒÔ¡£Èç ¹ûÄãÊ¡ÂÔÖ÷»úÃû£¬ psql ½«Í¨¹ý Unix ÓòÌ×½Ó×ÖÓë±¾µØÖ÷»úµÄ·þÎñÆ÷ÏàÁª¡£ ȱʡµÄ¶Ë¿ÚºÅÊDZàÒëʱȷ¶¨µÄ¡£ÒòΪÊý¾Ý¿â·þÎñÆ÷ʹÓÃͬÑùµÄȱʡֵ£¬ ËùÒÔÔÚ´ó¶àÊýÉèÖÃÏ£¬Äã¿ÉÄܲ»ÐèÒªÉùÃ÷¶Ë¿ÚºÅ¡£ ȱʡµÄÓû§ÃûÊÇÄãµÄ Unix Óû§Ãû£¬ÓëÊý¾Ý¿âͬÃû¡£ ҪעÒâµÄÊÇÄã²»ÄÜÓÃÈÎÒâÓû§ÃûÓë ÈκÎÊý¾Ý¿âÏàÁª¡£ÄãµÄÊý¾Ý¿â¹ÜÀíÔ±Ó¦¸Ã¸æËßÄãÄãµÄ·ÃÎÊȨÏÞ¡£ Äã¿ÉÒÔͨ¹ýÉèÖü¸¸ö»·¾³±äÁ¿ PGDATABASE£¬ PGHOST£¬PGPORT ºÍ PGUSER Ϊ¶ÔÓ¦µÄÖµµÄ·½·¨½ÚÔ¼¼¸´ÎÇû÷¡£

Èç¹ûÒòΪÈκÎÔ­Òò¶øÎÞ·¨ÓëÊý¾Ý¿âÏàÁª £¨ÀýÈ磬ȨÏÞ²»¹»£¬postmaster ûÓÐÔËÐеȣ©£¬ psql ½«·µ»ØÒ»¸ö´íÎó²¢Í˳ö¡£

ÊäÈë²éѯ

ͨ³£×´¿öÏ£¬psql Ìṩһ¸ö´øÓÐ psql ÕýÔÚÓëÖ®Áª½ÓµÄ½ÓÊý¾Ý¿âÃûµÄ£¬ºó׺ =>µÄÌáʾ·û£®ÀýÈ磬

$ psql testdb
Welcome to psql 7.3, 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 ÃüÁîµÄ¸ñʽÊÇ·´Ð±¸Ü ºóÃæ½ô¸úÒ»¸öÃüÁ´Ê£¬È»ºóÊÇÈÎÒâ²ÎÊý£® ²ÎÊýÓëÃüÁ´ÊºÍÆäËû²ÎÊýÒÔÈÎÒâ¸ö¿Õ°××Ö·û¼ä¸ô£®

ÒªÔÚ²ÎÊýÀïÃæ°üº¬¿Õ°×£¬Äã±ØÐëÓõ¥ÒýºÅ°ÑËü°üΧÆðÀ´¡£ ÒªÔÚÕâÑùµÄ²ÎÊýÀï°üº¬µ¥ÒýºÅ£¬Ç°Ãæ¼ÓÒ»¸ö·´Ð±¸Ü¡£ Èκΰüº¬ÔÚµ¥ÒýºÅÀïµÄ¶«Î÷ »á±»½øÒ»²½½øÐÐÀà C µÄÌæ»»£¬°Ñ \n £¨ÐÂÐУ©£¬\t £¨tab£©£¬\digits£¬ \0digitsºÍ \0xdigits £¨¸ø³öµÄÊ®½øÖÆ£¬°Ë½øÖÆ£¬»òÊ®Áù½øÖÆÂëµÄ×Ö·û£©Ìæ»»µô¡£

Èç¹ûÒ»¸ö²»´øÒýºÅµÄ²ÎÊýÒÔðºÅ£¨:£© ¿ªÍ·£¬Ëü»á±»µ±×÷Ò»¸öpsql ±äÁ¿£¬²¢ÇҸñäÁ¿µÄÖµ»á×îÖÕ³ÉΪÕæÕýµÄ²ÎÊýÖµ¡£ £¨Òë×¢£ºÀàËÆ ecpg ºÍ pl/pgsql µÄ±äÁ¿Ó÷¨¡££©

Óá°·´¹´ºÅ¡± £¨"backticks" `£© ÒýÆðµÄÄÚÈݱ»µ±×÷Ò»¸öÃüÁîÐд«Èë shell¡£ ¸ÃÃüÁîµÄÊä³ö£¨É¾³ýÁ˽áβµÄÐÂÐУ©±»µ±×÷²ÎÊýÖµ¡£ÉÏÃæÃèÊö µÄÌÓÒÝ£¨×Ö·û£©ÐòÁÐÔÚ·´¹´ºÅÀïÒ²ÉúЧ¡££¨Òë×¢£ºÓë shell ³ÌÐòÀàËÆ£©

ÓÐЩÃüÁîÒÔÒ»¸ö SQL ±êʶµÄÃû³Æ£¨È磬һ¸ö±íÃû£©Îª²ÎÊý¡£ ÕâЩ²ÎÊý×ñÑ­ SQL Óï·¨¹ØÓÚË«ÒýºÅµÄ¹æÔò£º ²»´øË«ÒýºÅµÄ±êʶǿÖƳÉСд¡£ ¶ÔÓÚËùÓÐÆäËûÃüÁ˫ÒýºÅûÓÐÌØÊ⺬Òå²¢ÇÒ½«±»µ±³É²ÎÊýµÄÒ»²¿·Ö¡£

¶Ô²ÎÊýµÄ·ÖÎöÔÚÅöµ½ÁíÒ»¸ö²»´øÒýºÅµÄ·´Ð±¸Üʱֹͣ¡£ ÕâÀï»áÈÏΪÊÇÒ»¸öеÄÔªÃüÁîµÄ¿ªÊ¼¡£ÌØÊâÐòÁÐ \\£¨Ë«·´Ð±¸Ü£©±êʶ²ÎÊýµÄ½áβ²¢½«¼ÌÐø·ÖÎöºóÃæµÄ SQL ²éѯ£¨Èç¹û´æÔڵĻ°£©¡£ÕâÑù SQL ºÍ psqlÃüÁî¿ÉÒÔ×ÔÓɵÄÔÚÒ»ÐÐÀïÃæ»ìºÏ¡£ µ«ÊÇÔÚÈκÎÇé¿öÏ£¬Ò»ÌõÔªÃüÁîµÄ²ÎÊý²»ÄÜÑÓÐø³¬¹ýÐÐβ¡£

ÏÂÁÐÔªÃüÁîÊÇÒѶ¨ÒåµÄ£º

\a

Èç¹ûÄ¿Ç°µÄ±íÊä³ö¸ñʽÊDz»¶ÔÆëµÄ£¬Çл»³É¶ÔÆëµÄ¡£ Èç¹ûÊǶÔÆëµÄ£¬Çл»³É²»¶ÔÆë¡£ÕâÌõÃüÁîÊÇΪÁËÏòºó¼æÈÝ¡£²ÎÔÄ \pset »ñÈ¡Ò» ¸öͨÓõĽâ¾ö·½·¨¡£

\cd [directory]

°Ñµ±Ç°¹¤×÷Ŀ¼¸Ä±äµ½ directory£® ûÓвÎÊýÊÇÔò¸Ä±äµ½µ±Ç°Óû§µÄ¼ÒĿ¼£®

¼¼ÇÉ: Òª´òÓ¡³öÄãµÄµ±Ç°¹¤×÷Ŀ¼£¬Ê¹Óà \!pwd£®

\C [ title ]

°ÑÕýÔÚ´òÓ¡µÄ±íµÄ±êÌâÉèÖÃΪһ¸ö²éѯµÄ½á¹û»òÕßÈ¡ÏûÕâÑùµÄÉèÖᣠÕâÌõÃüÁîµÈЧÓÚ \pset title title. £¨ÕâÌõÃüÁîµÄÃû³ÆÔ´ÓÚ "caption"£¬ÒòΪÒÔÇ°Ö»ÊÇÓÃÓÚÔÚÒ»¸ö HTML ±íÀïÃæÉèÖñêÌâ¡££©

\connect (or \c) [ dbname [ username ] ]

ÓëÒ»¸öеÄÊý¾Ý¿â½¨Á¢Ò»¸öÁª½Ó£¬Ê¹ÓÃ/²»ÓÃÒ»¸öÓû§Ãû¡£ Ç°ÃæµÄÁª½Ó½«¹Ø±Õ¡£Èç¹û dbname ÊÇ - £¬ÄÇô¾Í¼ÙÉèÊǵ±Ç°Êý¾Ý¿âÃû³Æ¡£

Èç¹ûÊ¡ÂÔ username£¬ Ôò¼ÙÉèÊǵ±Ç°Óû§Ãû¡£

×÷ΪһÌõÌØÊâ¹æÔò£¬²»´øÈκβÎÊýÔËÐÐ\connect ½«ÒÔȱʡÓû§Éí·ÝÓëȱʡÊý¾Ý¿âÁ¬½Ó£¨ÕýÈçÄã²»´øÈκβÎÊýÔËÐÐ psql Ò»Ñù¡££©

Èç¹ûÁª½Óʧ°Ü£¨Óû§Ãû´í£¬·ÃÎʾܾøµÈ£©£¬ÄÇô½«±£ÁôÇ°ÃæµÄÁª½Ó--µ±ÇÒ½öµ±ÔÚ psql ´¦ÓÚ½»»¥Ä£Ê½ÏÂÈç´Ë¡£ Èç¹ûÔËÐеÄÊǷǽ»»¥µÄ½Å ±¾£¬´¦Àí»áÂíÉÏÍ£Ö¹£¬²¢·µ»ØÒ»¸ö´íÎó¡£ Ñ¡ÔñÕâÑùµÄÇø±ðÊÇÒ»·½ÃæΪÓû§Ê¹Ó÷½±ã¿¼ÂÇ£¬ ÁíÒ»·½ÃæΪ±£Ö¤½Å±¾²»»áÅöÇɲÙ×÷ÁË´íÎó µÄÊý¾Ý¿âµÄ°²È«»úÖÆ¿¼Âǵġ£

\copy table [ ( column_list ) ] { from | to } filename | stdin | stdout [ with ] [ oids ] [ delimiter [as] 'character' ] [ null [as] 'string' ]

Ö´ÐÐÇ°¶Ë£¨¿Í»§¶Ë£©¿½±´£®ÕâÊÇÒ»¸öÔËÐÐ SQL COPY ÃüÁîµÄ²Ù×÷£¬ ²»Í¬µÄÊÇ SQL COPY ÊǺó¶ËÔÚ¶ÁдָÃ÷µÄÎļþ£¬¶ø psql ¶ÁдÎļþ²¢×÷Ϊ±¾µØµÄÎļþϵͳ ºÍºó¶ËÖ®¼äµÄ·ÓÉÈ¡³ö»òдÈëÊý¾Ý£® ÕâÒâζ×ÅÎļþ·ÃÎÊÐÔºÍȨÏÞ¶¼ÊDZ¾µØÓû§µÄ£¬¶ø²»ÊÇ·þÎñÆ÷µÄ£¬Òò´Ë ²»ÐèÒª SQL ³¬¼¶Óû§È¨ÏÞ¡£

ÕâÌõÃüÁîµÄÓï·¨ÊÇÄ£Äâ SQL COPY ÃüÁîµÄ£¬²Î¿¼ËüµÄÃèÊö»ñȡϸ½Ú¡£ ҪעÒâµÄÊÇÓɴ˶øÀ´£¬ÓÐһЩÌØÊâµÄ·ÖÎö¹æÔòÓ¦ÓÃÓÚ \copy ÃüÁî¡£ ÓÈÆäÊDZäÁ¿Ìæ»»¹æÔòºÍ·´Ð±¸Ü´ú»»¹æÔò²»Æð×÷Óá£

¼¼ÇÉ: ´Ë²Ù×÷²»Ïó SQL COPY ÃüÁîÕâÑù¸ßЧ£¬ ÒòΪËùÓÐÊý¾Ý±ØÐëͨ¹ý£¨¿Í»§/·þÎñÆ÷)£©client/server IP »òÌ×½Ó×ÖÁª½Ó£®¶ÔÓÚ´óÊý¾ÝÁ¿µÄ²Ù×÷£¬ÁíÒ»ÖÖ·½·¨¸ü¿ÉÐС£

×¢Òâ: ×¢ÒâÔÚÇ°¶ËºÍºó¶Ë¿½±´Ê±¶Ô stdin ºÍ stdout µÄ½âÊ͵ÄÇø±ð£ºÔÚÇ°¶Ë¿½±´Ê±£¬ÕâЩ×ÜÊÇÖ¸ psqlµÄÊäÈëºÍÊä³öÁ÷¡£ÔÚºó¶Ë¿½±´Ê± stdin À´×Ô COPY ±¾ÉíµÄ±ê×¼ÊäÈ루±ÈÈ磬һ¸ö´øÓÐ -f Ñ¡ÏîµÄ½Å ±¾£©£¬¶ø stdout Ö¸µÄÊDzéѯÊä³öÁ÷£¨²ÎÔÄÏÂÃæµÄ \o ÔªÃüÁ¡£

\copyright

ÏÔʾ PostgreSQL µÄ°æȨºÍ°æ±¾ÐÅÏ¢¡£

\d pattern

¶ÔÓÚÿ¸öÆ¥ÅäpatternµÄ¹Øϵ£¨±í£¬ÊÓͼ£¬Ë÷Òý»òÕßÐòÁУ©£¬ ÏÔʾËùÓÐÁУ¬ËüÃǵÄÀàÐÍ£¬ºÍÈκÎÌØÊâÊôÐÔ£¬ÏóNOT NULL»òȱʡµÈ£­£­Ö»Òª´æÔÚ¡£ Èç¹ûʵ¼ÊÉÏÕâ¸ö¹ØϵÊÇÒ»¸ö±í£¬ÈκÎÒѶ¨ÒåµÄË÷Òý£¬Ö÷¼ü£¬Î¨Ò»Ô¼Êø Ïà¹ØµÄË÷Òý£¬¹æÔò£¬Ô¼Êø£¬ºÍ´¥·¢Æ÷ҲͬÑùÏÔʾ³öÀ´£¬Èç¹û¹ØϵÊÇÒ»¸ö ÊÓͼ£¬»¹ÏÔʾÊÓͼµÄ¶¨Òå¡£ £¨"Æ¥Åäģʽ"ÔÚÏÂÃ涨Òå¡££©

´Ó \d+ À´µÄÃüÁîÒ²ÊÇÒ»ÑùµÄ£¬ Ö»²»¹ý»¹ÏÔʾÓë±íµÄÁйØÁªµÄ×¢½â¡£

×¢Òâ: Èç¹ûÈç¹û²»´øÈκÎpatternµ÷Óà \d£¬µÈЧÓÚ \dtvs £¬½«ÏÔʾһ¸öËùÓÐ±í£¬ÊÓͼºÍÐòÁеÄÁÐ±í¡£ ÕâÍêÈ«ÊdzöÓÚ·½±ãµÄ¿¼ÂÇ¡£

\da [ pattern ]

ÁгöËùÓпÉÓþۼ¯º¯Êý£¬ÒÔ¼°ËüÃDzÙ×÷µÄÊý¾ÝÀàÐÍ¡£Èç¹ûÉùÃ÷ÁË pattern £¨Ò»¸öÕýÔò±í´ïʽ£©£¬ÄÇôֻÏÔʾƥÅ䣨ÕýÔò±í´ïʽ£©µÄ¾Û¼¯º¯Êý¡£

\dd [ pattern ]

ÏÔʾËùÓÐÆ¥Åä pattern µÄÃèÊö£¬Èç¹ûûÓиø³ö²ÎÊý£¬ÏÔʾËùÓпÉÊÓ¶ÔÏó¡£ µ«ÊDz»¹ÜÔõÑù£¬Ö»ÓÐÄÇЩÓÐÃèÊöÄÚÈݵĶÔÏó²ÅÏÔʾ³öÀ´¡£ £¨"¶ÔÏó"°üÀ¨¾Û¼¯£¬º¯Êý£¬²Ù×÷·û£¬ÀàÐÍ£¬ ¹Øϵ£¨±í£¬ÊÓͼ£¬Ë÷Òý£¬ÐòÁУ¬´ó¶ÔÏ󣩣¬¹æÔòºÍ´¥·¢Æ÷¡££©ÀýÈ磺

=> \dd version
                     Object descriptions
   Schema   |  Name   |  Object  |        Description
------------+---------+----------+---------------------------
 pg_catalog | version | function | PostgreSQL version string
(1 row)

¿ÉÒÔÓÃCOMMENT ON SQL ÃüÁîÉú³É¶Ô¶ÔÏóµÄÃèÊö¡£

×¢Òâ: PostgreSQL ÔÚpg_descriptionϵͳ±íÀï´æ´¢¶ÔÏóÃèÊö¡£

\dD [ pattern ]

ÁгöËùÓпÉÓÃÓò(ÑÜÉúÀàÐÍ)£®Èç¹û ÉùÃ÷ÁË pattern £¬ÄÇôֻÏÔʾƥÅäµÄÓò£®

\df [ pattern ]

ÁгöËùÓпÉÓú¯Êý£¬ÒÔ¼°ËüÃǵIJÎÊýºÍ·µ»ØµÄÊý¾ÝÀàÐÍ¡£Èç¹ûÉùÃ÷ÁË pattern £¬ÄÇôֻÏÔʾƥÅ䣨ÕýÔò±í´ï ʽ£©µÄº¯Êý¡£Èç¹ûʹÓÃÁË \df+ µÄÐÎʽ£¬Ã¿¸öº¯ÊýµÄ¸½¼ÓÐÅÏ¢£¬ °üÀ¨ÓïÑÔºÍÃèÊöÒ²»áÏÔʾ³öÀ´¡£

×¢Òâ: ΪÁ˼õÉÙ»ìÂÒ£¬\df ²¢²»ÏÔʾÊý¾ÝÀàÐ굀 I/O º¯Êý¡£ ÕâÑùÊÇͨ¹ýºöÂÔÄÇЩ½ÓÊÜ»òÕß·µ»ØÀàÐÍ cstring µÄº¯ÊýʵÏֵġ£

\distvS [ pattern ]

Õâ²»ÊÇÒ»¸öʵ¼ÊÉϵÄÃüÁîÃû³Æ£º×Öĸ i£¬s£¬t£¬v£¬S ·Ö±ð´ú±íË÷Òý£¨index£©£¬ ÐòÁУ¨sequence£©£¬±í£¨table£©£¬ÊÓͼ£¨view£©ºÍϵ ͳ±í£¨system table£©¡£ Äã¿ÉÒÔÒÔÈÎÒâ˳ÐòÉùÃ÷ÈÎÒâ»òÕßËùÓÐÕâЩ×Öĸ»ñµÃÕâЩ¶ÔÏóµÄÒ»¸öÁÐ±í¡£ ×ÖÄ» S °ÑÁбíÏÞÖÆÓÚϵͳ¶ÔÏó£»Èç¹ûûÓÐ S£¬ÔòÖ»ÏÔʾ·Çϵͳ¶ÔÏó¡£ Èç¹ûÔÚÃüÁîÃûÉϸ½¼ÓÁË "+"£¬ÄÇô»¹»áÁгöºÍÿ¸ö¶ÔÏó Ïà¹ØÁªµÄÃèÊö£¬Èç¹ûÓеĻ°¡£

Èç¹ûÉùÃ÷ÁË pattern £¬ÄÇôֻÁгöÆ¥ÅäģʽµÄ¶ÔÏó¡£

\dl

ÕâÊÇ \lo_listµÄ±ðÃû£¬ÏÔʾһ¸ö´ó¶ÔÏóµÄÁÐ±í¡£

\do [ pattern ]

ÁгöËùÓпÉÓòÙ×÷·û£¬ÒÔ¼°ËüÃǵIJÙ×÷ÊýºÍ·µ»ØµÄÊý¾ÝÀàÐÍ¡£ Èç¹ûÉùÃ÷ÁË pattern £¬ÄÇôֻÏÔʾƥÅäģʽµÄ²Ù×÷·û¡£

\dp [ pattern ]

Éú³ÉÒ»ÁпÉÓõıíºÍËüÃÇÏà¹ØµÄȨÏÞ¡£ Èç¹ûÉùÃ÷ÁË pattern£¬ ÄÇôֻÁгöÃû×Ö¿ÉÒÔÆ¥ÅäģʽµÄ±í¡£

ÃüÁî GRANT ºÍ REVOKE ÓÃÓÚÉèÖà ·ÃÎÊȨÏÞ¡£²ÎÔÄ GRANT »ñÈ¡¸ü¶àÐÅÏ¢¡£

\dT [ pattern ]

ÁгöËùÓÐÊý¾ÝÀàÐÍ»òÖ»ÏÔʾÄÇЩƥÅä patternµÄ¡£ÕâÌõÃüÁîµÄ \dT+ ÐÎʽÏÔʾ¸ü¶àÐÅÏ¢¡£

\du [ pattern ]

ÁгöËùÓÐÒÑÅäÖÃÓû§»òÕßÖ»ÁгöÄÇЩƥÅä pattern µÄÓû§£®

\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 »ñÈ¡ÉèÖÃÆäËûÊä³öÑ¡ÏîµÄÄÚÈÝ¡£

\timing

´ò¿ªÏÔʾÿÌõ²éѯʹÓÃʱ¼äÃëÊýµÄÏÔʾ£®

\i filename

´ÓÎļþfilename ÖжÁÈ¡²¢°ÑÆäÄÚÈݵ±×÷´Ó¼üÅÌÊäÈëµÄÄÇÑùÖ´Ðвéѯ¡£

×¢Òâ: Èç¹ûÄãÏëÔÚÆÁÄ»ÉÏ¿´µ½¶ÁÈëµÄÐУ¬Äã±ØÐë¶ÔËùÓÐÐÐÉèÖñäÁ¿ ECHO Ϊ all¡£

\l (»ò \list)

Áгö·þÎñÆ÷ÉÏËùÓÐÊý¾Ý¿âºÍËüÃǵÄËùÓÐÕß¡£ÔÚÃüÁîÃû³ÆºóÃæ¼ÓÒ»¸ö "+" »¹¿ÉÒÔ¿´µ½¶ÔÊý¾Ý¿âµÄÈκÎÃèÊö¡£Èç¹ûÄãµÄ PostgreSQL ½ÚµãÊÇ´ø×Ŷà×Ö½ÚÖ§³Ö±àÒëµÄ£¬»¹¿ÉÒÔ¿´µ½Ã¿¸öÊý¾Ý¿âµÄ±àÂ뷽ʽ¡£

\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

¿ØÖƲéѯºÍpsql°ïÖúÊä³öµÄ·ÖÒ³Æ÷¡£Èç¹ûÉèÖÃÁË»·¾³±äÁ¿ PAGER £¬Êä³ö±»¶¨Ïòµ½Ö¸¶¨³ÌÐò£¬·ñÔòʹÓà ϵͳȱʡ£¨±ÈÈç more£©¡£

Èç¹û¹Ø±ÕÁË·ÖÒ³Æ÷£¬Ôò²»Ê¹ÓÃËü£¬Èç¹û´ò¿ªÁË£¬ ³ÌÐòÖ»ÔÚÐèÒªµÄʱºòʹÓ÷ÖÒ³Æ÷£¬Ò²¾ÍÊÇ˵£¬ Êä³öÊǵ½Öնˣ¬¶øÇÒÄǸö±íºÜ¿ÉÄÜÎÞ·¨ÓëÆÁĻƥÅä¡£ £¨psql ÔÚ¾ö¶¨ºÎʱ·Öҳʱ²»ÊǺÜÍêÃÀ¡££© \pset pager ¿ª¹Ø·ÖÒ³Æ÷¡£ÎÒÃÇÒ²¿ÉÒÔ°Ñ·ÖÒ³Æ÷ ÉèÖÃΪ always£¬µ¼ÖÂÎÒÃÇÔÚÈκÎÇé¿ö϶¼Ê¹Ó÷ÖÒ³Æ÷¡£

¿ÉÒÔÔÚ Àý×Ó ½Ú¿´µ½ÕâЩ²»Í¬¸ñʽÊä³öµÄʾÀý¡£

¼¼ÇÉ: ÓкܶàÓÃÓÚ\psetµÄ¿ìËÙÃüÁî¡£²ÎÔÄ \a£¬\C£¬\H£¬ \t£¬\T£¬ºÍ \x¡£

×¢Òâ: ÎÞ²ÎÊýÔËÐÐ \psetÊÇ´íÎóµÄ¡£ ÒÔºóÕâÑùµ÷Óý«ÏÔʾµ±Ç°´òÓ¡Ñ¡Ïî״̬¡£

\q

Í˳öpsql³ÌÐò£®

\qecho text [ ... ]

ÕâÌõÃüÁîµÈЧÓÚ \echo £¬Çø±ðÊÇËùÓÐÊä³ö½«Ð´ÈëÓÉ \oÉèÖõÄÊä³öͨµÀ¡£

\r

ÖØÖã¨Çå¿Õ£©²éѯ»º³åÇø¡£

\s [ filename ]

½«ÃüÁîÐÐÀúÊ·´òÓ¡³ö»òÊÇ´æ·Åµ½ filename¡£Èç¹ûÊ¡ÂÔ filename£¬ ÀúÊ·½«Êä³öµ½±ê×¼Êä³ö¡£Õâ¸öÑ¡ÏîÖ»ÓÐÔÚ psql ÅäÖóÉʹÓà GNU ÀúÊ·¿âºó²ÅÉúЧ¡£

×¢Òâ: ÔÚµ±Ç°°æ±¾À Õâ¸ö£¨ 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 ]

Éú³ÉÒ»¸ö´øÓзÃÎÊȨÏÞÁбíµÄÊý¾Ý¿âÖÐËùÓбíµÄÁÐ±í¡£ Èç¹û¸ø³öÈκÎpattern£¬Ôò±»µ±³ÉÒ»¸ö¹æÔò±í´ïʽ£¬ Ö»ÏÔʾƥÅäµÄ±í¡£

ÃüÁî GRANT ºÍ REVOKE ÓÃÓÚÉèÖ÷ÃÎÊȨÏÞ¡£ ²ÎÔÄ GRANT »ñÈ¡¸ü¶àÐÅÏ¢¡£

ÕâÊÇ \dp£¨"ÏÔʾȨÏÞ"£©µÄ±ðÃû¡£

\! [ command ]

·µ»Øµ½Ò»¸ö¶ÀÁ¢µÄ Unix shell »òÕßÖ´ÐÐ Unix ÃüÁî command¡£ ²ÎÊý²»»á±»½øÒ»²½½âÊÍ£¬shell ½«¿´µ½È«²¿²ÎÊý¡£

\?

»ñµÃ¹ØÓÚ·´Ð±¸Ü£¨"\"£©ÃüÁîµÄ°ïÖúÐÅÏ¢¡£

¸÷ÖÖ \d ÃüÁ½áÖÜÒ»¸ö pattern ²ÎÊý£¬ÉùÃ÷ÒªÏÔʾµÄ¶ÔÏóÃû×Ö¡£Ä£Ê½µÄ½âÊÍÀàËÆÓÚ SQL ±êʶ·û£¬Ò²¾ÍÊÇ˵ ûÓÐÒýºÅ°üΧµÄ×ÖĸǿÖÆΪСд£¬¶ùË«ÒýºÅ£¨"£©±£»¤×Öĸ²»ÊÜ ´óСдµÄת»»£¬²¢ÇÒÔÊÐíÔÚ±êʶ·ûÖвåÈë¿Õ°×¡£ÔÚË«ÒýºÅÀ³É¶ÔµÄË«ÒýºÅ ÔÚ½á¹ûÃû×ÖÖÐÉú³ÉÒ»¸öË«ÒýºÅ¡£±ÈÈ磬FOO"BAR"BAZ ½âÊÍ³É fooBARbaz£¬¶ø "A weird"" name" ±ä³É A weird" name¡£

¸üÓÐȤµÄÊÇ£¬\d ģʽÔÊÐíʹÓà * ±íʾ "ÈκÎ×Ö·ûÐòÁÐ"£¬¶ø ? ±íʾ "Èκε¥¸ö×Ö·û"¡£ £¨Õâ¸ö±íʾ·¨ºÍ Unix µÄ shell ÎļþÃûģʽ¼æÈÝ¡££©¸ß¼¶Óû§Ò²¿ÉÒÔ ËÀ»îÓÃÕýÔò±í´ïʽ±íʾ·¨£¬±ÈÈç梷ò±í£¬[0-9] ÕâÑùµÄ¶«Î÷ À´Æ¥Åä"ÈÎÒâÊý×Ö"¡£ÒªÈÃÈκÎÕâЩģʽƥÅä×Ö·û¿ÉÒÔ°²×ÖÃ淽ʽ ½âÎö£¬ÄǾÍÓ¦¸ÃÓÃË«ÒýºÅ°üΧËüÃÇ¡£

Ò»¸ö°üº¬£¨ÎÞÒýºÅµÄ£©¾äµãµÄģʽ»á±»½âÎö³ÐÒ»¸öģʽÃûµÄģʽºóÃæ¸ú×ÅÒ»¸ö ¶ÔÏóÃûµÄģʽ¡£±ÈÈ磬 \dt foo*.bar* ÏÔʾËùÓÐÒÔfoo ¿ªÍ·µÄģʽÀïµÄÒÔ bar ¿ªÍ·µÄ±íÃû×Ö¡£Èç¹ûûÓгöÏÖ¾äµã£¬ ÄÇôÕâ¸öģʽֻƥÅäÔÚµ±Ç°Ä£Ê½ËÑË÷·¾¶ÖпɼûµÄ¶ÔÏó¡£

Èç¹ûÍêÈ«Ê¡ÂÔ pattern ²ÎÊý£¬ ÄÇô \d ÃüÁîÏÔʾËùÓÐÔÚµ±Ç°Ä£Ê½ËÑË÷·¾¶ÖпɼûµÄ¶ÔÏó¡£Òª²éÔÄÔÚ Êý¾Ý¿âÖеÄËùÓжÔÏó£¬Ê¹ÓÃģʽ *.*¡£

¸ß¼¶ÌØÐÔ

±äÁ¿

psql ÌṩÀàËÆͨ³£ Unix ÃüÁî shell ÄÇÑùµÄ±äÁ¿Ìæ»»ÌØÐÔ¡£ Õâ¸öÌØÐÔÊÇÐÂÒýÈëµÄ»¹²»ÊǺܸ´ÔÓ£¬µ«ÊÇÎÒÃǼƻ®ÔÚ½ñºóÀ©Õ¹Ëü¡£ ±äÁ¿Ö»ÊǼòµ¥µÄÃû³Æ/ÊýÖµ¶Ô£¬ ÕâÀïµÄÖµ¿ÉÒÔÊÇÈκγ¤¶ÈµÄÈκÎÖµ¡£ÒªÉèÖÃÒ»¸ö±äÁ¿£¬Ê¹Óà psql ÔªÃüÁî \set£º

testdb=> \set foo bar

°Ñ±äÁ¿"foo" ÉèÖÃΪֵ "bar"¡£ Òª¼ìË÷±äÁ¿µÄÄÚÈÝ£¬ÔÚ±äÁ¿ÃûÇ°Ãæ·ÅÉÏðºÅÈ»ºó°ÑËüÓÃÔÚÈÎÒâб¸ÜÃüÁîÀ

testdb=> \echo :foo
bar

×¢Òâ: \set µÄ²ÎÊý·þ´ÓºÍÆäËûÃüÁîÒ»ÑùµÄÌæ»»¹æÔò¡£ Òò´ËÄã¿ÉÒÔ¹¹ÔìÓÐȤµÄÒýÓã¬Ïó \set :foo 'something' ÕâÑù£¬»ñµÃ·Ö±ðÏóPerl»òPHPÄÇÑùÓÐÃûµÄ "ÈíÁ¬½Ó£¨soft links£©"»ò"±äÁ¿ ±äÁ¿" ²»ÐÒµÄÊÇ£¨»òÕß ÍòÐҵģ¿£©£¬ÓÃÕâЩ¹¹Ôì²»ÄÜ×öÈκÎÓÐÓõÄÊÂÇé¡£ÁíÒ»·½Ã棬 \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¡£

Note: Õâ¸öÌØÐÔÊÇÎÞ³ÜµØ´Ó 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 ´ú»»

Ò»¸ö¸½¼ÓµÄ psql ±äÁ¿µÄÓÐÓÃÌØÐÔÊÇÄã¿ÉÒÔ°ÑËüÃÇÌæ»» £¨"´ú»»"£©³ÉÕý¹æµÄ SQL Óï¾ä¡£ÕâÑù×öµÄÓ﷨ͬÑù»¹ÊDZäÁ¿ÃûÇ°Ãæ¼ÓÒ»¸öðºÅ £¨:£©¡£

testdb=> \set foo 'my_table'
testdb=> SELECT * FROM :foo;

½«»á²éѯ±ímy_table¡£±äÁ¿µÄÖµÊÇÖð×Ö¿½±´µÄ£¬ ËùÒÔËüÉõÖÁ¿ÉÒÔ°üº¬²»¶Ô³ÆµÄÒýºÅ»ò·´Ð±¸ÜÃüÁî¡£ Äã±ØÐë±£Ö¤ÄãÊäÈëµÄ¶«Î÷ÊÇÓÐÒâÒå µÄ¡£±äÁ¿Ìæ»»½«²»»áÔÚÒýÆðÀ´µÄ SQL Óï¾äÀïÃæ·¢Éú¡£

ÀûÓÃÕâ¸ö¹¦ÄܵÄÒ»¸öʱ÷ÖµÄÓ¦ÓÃÊÇͨ¹ýʹÓÃÒ»¸öËæºóµÄÓï¾äÖÐ×îºó²åÈëµÄ OID ½¨Á¢Ò»¸öÍâ¼ü·ÂÕ泡¾°¡£ ÁíÒ»¸ö¿ÉÄÜÓõ½Õâ¸ö»úÖƵĵط½ÊÇ°ÑÒ»¸öÎļþµÄÄÚÈÝ¿½±´µ½Ò»¸öÓòÀïÃæÈ¥¡£ Ê×ÏÈ°ÑÎļþ×°Ôص½Ò»¸ö±äÁ¿È»ºóÏóÉÏÃæÄÇÑù´¦Àí¡£

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

Êý¾Ý¿â·þÎñÆ÷Ö÷»úÃûÈ«Ãû(´ø×ÅÓòÃû)£¬Èç¹ûÁª½ÓÊÇͨ¹ý Unix ÓòÌ×½Ó×Ö ½øÐеľÍÊÇ [local]£¬»òÕß Èç¹û Unix ÓòÌ×½Ó×Ö²»ÊDZàÒëµÄȱʡλÖ㬾ÍÊÇ [local:/dir/name]£®

%m

Êý¾Ý¿â·þÎñÆ÷µÄÖ÷»úÃûɾȥµÚÒ»¸öµãºóÃæµÄ²¿·ÖʣϵĶ«Î÷¡£ »òÕßÈç¹ûÁª½ÓÊÇͨ¹ý Unix ÓòÌ×½Ó×Ö£¬¾ÍÊÇ [local]£®

%>

Êý¾Ý¿â·þÎñÆ÷ÕýÔÚÕìÌýµÄ¶Ë¿ÚºÅ¡£

%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 ΪÁ˱༭ºÍ¼ìË÷ÃüÁîÐеķ½±ãÖ§³Ö readline ºÍÀúÊ·¿â¡£ ÃüÁîÀúÊ·´æ·ÅÔÚÄãµÄ¼ÒĿ¼µÄÒ»¸ö½Ð .psql_history µÄÎļþÀ²¢ÇÒµ± psql Æô¶¯µÄʱºò»á×°ÔؽøÀ´¡£ Tab-²¹ÆëͬÑùÒ²±»Ö§³Ö£¬¾¡¹Ü¸Ã²¹ÆëÂß¼­²¢²»ÊÇÒ»¸ö SQL ·ÖÎöÆ÷±Ø±¸µÄ¡£Èç¹û¿ÉÄÜ£¬ psql »á×Ô¶¯ÖÆ×÷³ÉʹÓÃÕâЩÌØÐÔ¡£ Èç¹ûÒòijЩԭÒòÄ㲻ϲ»¶ tab ²¹Æ룬Äã¿ÉÒÔ°ÑÏÂÃ漸ÐзÅÔÚÄãµÄ¼ÒĿ¼µÄÒ»¸ö½Ð .inputrc µÄÎļþÀï¹Ø±ÕÕâ¸öÌØÐÔ£º

$if psql
set disable-completion on
$endif

£¨Õâ²»ÊÇpsql µÄÌØÐÔ£¬ ÊÇ readline µÄ¡£²Î¿¼ËüµÄÎĵµ»ñÈ¡¸ü¶àϸ½Ú¡££©

»·¾³

HOME

³õʼ»¯Îļþ£¨.psqlrc£©ºÍÃüÁîÀúÊ·Îļþ £¨.psql_history£©µÄĿ¼¡£

PAGER

Èç¹û²éѯ½á¹ûÔÚÒ»Ò³Àï·Å²»Ï£¬ÄÇôËüÃDZ»¶¨Ïòµ½Õâ¸öÃüÁî¡£ µäÐ͵ÄÖµÊÇ more »òÕß less¡£ ȱʡµÄÊÇƽ̨Ïà¹ØµÄ¡£ÎÒÃÇ¿ÉÒÔÓà \pset ÃüÁî ¹Ø±Õ·ÖÒ³Æ÷¡£

PGDATABASE

ȱʡÁ¬½ÓµÄÊý¾Ý¿â

PGHOST
PGPORT
PGUSER

ȱʡÁ¬½Ó²ÎÊý

PSQL_EDITOR
EDITOR
VISUAL

\e ÃüÁîʹÓõı༭Æ÷¡£ÕâЩ±äÁ¿ÊÇ°´ÕÕ ÉÏÃæµÄ˳Ðò¼ì²éµÄ£»ÉèÖÃ×îÔçµÄ×îÏÈʹÓá£

SHELL

\! ÃüÁîÖ´ÐеÄÃüÁî¡£

TMPDIR

´æ´¢ÁÙʱÎļþµÄĿ¼¡£È±Ê¡ÊÇ /tmp¡£

Îļþ

×¢Òâ

Àý×Ó

×¢Òâ: ±¾½ÚÖ»ÊÇÏÔʾÁË psqlÉÙÊý¼¸¸öÀý×Ó¡£Èç¹ûÄãÏ£Íûѧϰ SQL »òÕßÊìϤ PostgreSQL£¬Äã¿ÉÄÜÔ¸ÒâÔĶÁһϰüº¬ÔÚÕâ¸ö°æ±¾ ÀïµÄ½Ì³Ì¡£

µÚÒ»¸öÀý×ÓÑÝʾÁËÈçºÎ°ÑÒ»¸ö²éѯ·Ö³É¶à¸öÐнøÐÐÊäÈë¡£×¢ÒâÌáʾ·ûµÄ±ä»¯£º

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)

Äã¿ÉÒÔÓà \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