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

psql

劉䓄

psql -- PostgreSQL 庴庐䂽䆇

臺濘

psql [option...] [dbname [username]]

柟誄

psql 滇婔婻傖䂽䆇婺嘺䇔䔇 PostgreSQL 嬉䆇㔗垄噕螩嘹庴庐婄髞噖昖臵䇽劯檪垄傸埏庺䂍 PostgreSQL 喉滆䴺昖臵䔇䂷悩㔗埥崡膷噖埇傖準躻婔婻桺傽㔗誻橬垄柊冕庖婔底噄变傴启崔䓉䌂嚚 shell 䔇䬹攓準垂䯄幥喍臔橸傖埪凹崓麟傂媇䔇躻媘寡㔗

锬釹

-a
--echo-all

婘臂埡臯施劏湺庖膷庺欷剄欔橬喙垹㔗認婻锬釹婘臔橸崇䊖施懫庴庐昇嚟施敘橬䫘㔗認婻锬釹京昽庯螆䘞 ECHO 埻麟婺 all

-A
--no-align

彺扵婺麂凹阊膷庺昇嚟㔗䚺䩕膷庺昇嚟滇凹阊䔇㔗

-c command
--command command

弄滯 psql 儖欓臯婔溇昖臵庖严婾 command 䇽劯锔庺㔗認婔䗹婘 shell 臔橸麯冽橬䫘㔗

command 媙釂滇婔溇垯噘埇傖赆橉媇単彖悊䔇庖严婾(幘儌滇婉寙劆 psql 䬹橬䔇䬹攓)潡蔙滇婔婻埉桩溹变傴㔗認湙嘹儌婉嚔晙劽 SQL 启 psql 噄变傴㔗襕愿晙劽嘪䫘嘹埇傖檪庖严婾麉垔劏彄 psql 麯償認湙echo '\x \\ SELECT * FROM foo;' | psql (\\ 䫘庯锫嚔噄变傴)㔗

套悩变傴庖严婾寙劆崔婻 SQL 变傴闼幽傡傸儖婘婔婻庋媇麯崇䊖鍴麂婘庖严婾麯寙劆庖滯䇞䔇 BEGIN/COMMIT 变傴檪傡傸彖潊崔婻庋媇㔗認婻启傯 psql 䔇湺庖膷噖麯䂍垄准噙䕩劯庖严婾婉劯㔗

-d dbname
--dbname dbname

弄滯愿襕誂毖䔇昄扞康劉䓄㔗京昽庯婘变傴臯臯婪檪 dbname 弄滯婺丸婔婻麂锬釹埗昄㔗

-e
--echo-queries

檪欔橬埏锕䂍橉媇単䔇昖臵劯施幘啂滆彄湺庖膷庺㔗京昽庯檪埻麟 ECHO 螆䘞婺 queries

-E
--echo-hidden

啂滆䫌 \d 启噽垄埉桩溹变傴䫘潊䔇垂鍙昖臵㔗嘹埇傖嘪䫘認婻变傴庥幹 psql 䔇喙鄘淉嘩㔗認京昽庯婘 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

毺垔溼婘誊臯橉媇単䔇婂橺劉㔗套悩婂橺劉傖桩溹嚔崘彍垄赆䫘嘩彄 Unix 嘘喖毖庖䔇虇冇㔗

-H
--html

欷嚔 HTML 湚嚟膷庺㔗京昽庯 \pset format html\H 变傴㔗

-l
--list

彖庺欔橬埇䫘䔇昄扞康䇽劯锔庺㔗噽垄麂誂毖锬釹儖赆媘䘖㔗䌂嚚庯喙鄘变傴 \list

-L filename
--log-file filename

鍴庖溼婩䔇膷庺溊幋崡檪欔橬昖臵膷庺螄嘘彄桺傽 filename

-o filename
--output filename

儖欔橬昖臵膷庺麉垔劏彄桺傽 filename 㔗認婻锬釹京昽庯 \o 变傴㔗

-p port
--port port

毺垔橉媇単冥劸䔇 TCP 䆇埼潡橸婄 Unix 嘘喖毖庖桺傽䔇欷匘㔗䚺䩕嘪䫘䯇嵄埻麟 PGPORT 䔇唚套悩澇橬螆䘞䔇臺彍嘪䫘䚡臏施弄滯䔇䆇埼(锔婩滇 5432)㔗

-P assignment
--pset assignment

噕螩嘹婘变傴臯婪傖 \pset 䔇鼯湚螆䘞欷剄锬釹㔗襕濘懟䔇滇嘹婘認麯媙釂䫘京埙蔯婉滇䷺湚彖嬾劉䓄启唚㔗啹溴襕檪膷庺湚嚟螆䘞婺 LaTeX 嘹埇傖显噖 -P format=latex

-q
--quiet

垬麍婄欓臯崇䊖傂媇㔗䚺䩕施 psql 儖欷剄渵誯启螩崔噽垄膷庺媇敇㔗套悩嘪䫘庖溴锬釹認底鄘婉嚔庺䯄㔗認婘启 -c 锬釹婔蕙嘪䫘施冽橬昽㔗婘 psql 麯埇傖锔誺螆䘞 QUIET 埻麟垂䯄劯湙昽悩㔗

-R separator
--record-separator separator

嘪䫘 separator 啔婺麂凹阊膷庺䔇螄嘘彖锫严㔗京昽庯 \pset recordsep 变傴㔗

-s
--single-step

剘準昇嚟誊臯㔗懟叿五懟婻昖臵婘埏冔橉媇単幋嬉鄘襕柊䴺䫘潙䫘認婻锬釹幘埇傖埡潽欓臯㔗溴锬釹婂襕䫘庯脄臘臔橸㔗

-S
--single-line

剘臯誊臯昇嚟認施懟婻变傴鄘儖䫌扵臯严䂷溘償彖埙闼湙㔗

㔊濘懟㔏認婻昇嚟滇䂍闼底应毕襕嘪䫘認婻䬹攓䔇庺媺䘍䔇婉隷媌嘹認幽䫘㔗垂鍙婪套悩嘹婘婔臯麯晙劽嘪䫘 SQL 启噄变傴欓臯䔇釺废凹婉䖘䂄䔇䫘潙蔯蘔幽婉攂滇橙捄䔇㔗

-t
--tuples-only

噿閺欷剄彖劉䓄启䂷悩臯螇昄臔濘京媇敇㔗京昽庯 \t 变傴㔗

-T table_options
--table-attr table_options

噕螩嘹弄滯櫆婘 HTML table 湺了麯䔇锬釹㔗埗黙 \pset 诙埡䂖誗㔗

-u

嚺彽 psql 婘启昄扞康誂毖幋嬉柊䴺膷噖䫘潙劉启埼傴㔗

認婻锬釹噾䂟庘嚄庖啹婺垄婘楗媕婪橬暟昂㔗柊䴺膷噖麂䚺䩕䫘潙劉启柊䴺膷噖橉媇単襕挗䔇埼傴滇垯噘婴乕庋㔗隷媌嘹䫘 -U-W 锬釹埡傼垄㔗

-U username
--username username

傖䫘潙 username 傼敪䚺䩕䫘潙婯昄扞康誂毖㔗嘷䇽嘹媙釂橬認幽啔䔇溄鍊㔗

-v assignment
--set assignment
--variable assignment

償喙鄘变傴 \set 闼湙誕臯婔渇埻麟彖陉㔗濘懟套悩橬埻麟劉启唚䔇臺嘹媙釂婘变傴臯婪䫘京埙彖锫垄傸㔗寂毬京埙彍麉䘞埻麟㔗襕螆䘞婔婻澇橬唚䔇埻麟埇傖媺䘍京埙嘖滇婉毺垔唚㔗認婻彖陉滇婘劇媘幋彺誕臯䔇欔傖婺喙鄘嘪䫘蔯媺䘍䔇埻麟埇脘赆喉渇襖䕡㔗

-V
--version

欷剄 psql 䬽橸媇敇䇽劯锔庺㔗

-W
--password

嚺彽 psql 婘婯婔婻昄扞康誂毖嬉柊䴺膷噖埼傴㔗

套悩橉媇単襕挗埼傴螴臕psql 儖躻媘滆䴺埼傴柊䴺严㔗婉誺䕞嬉滇劥驔襕膷噖埼傴䔇彴桺幽婉垯噘埇麹啹溴䫘認婻锬釹嚺彽滆䴺認婻柊䴺严㔗套悩澇橬埏庺埼傴柊䴺严蔯橉媇単襕挗埼傴螴臕闼幽誂毖嚕商儖崌蘖㔗

認婻锬釹儖婘昘婻嚔臺誺䘋婺橬昽剿嘪嘹䫘噄变傴 \connect 櫹埻庖欔誂毖䔇昄扞康㔗

-x
--expanded

欷嚔欷匘臘湚嚟昇嚟㔗京昽庯 \x 变傴㔗

-X,
--no-psqlrc

婉臂埡劇媘桺傽(係䂘评啘䔇 psqlrc 潡蔙嘹躻噌䔇 ~/.psqlrc 鄘婉臂埡)㔗

-1
--single-transaction

psql 嘪䫘 -f 锬釹欓臯臔橸施嘪䫘認婻锬釹儖凚躘婘臔橸䔇嚔崘启䂷儆彖彆媹婪 BEGIN/COMMIT 準檪昘婻臔橸嘷嘩婔婻庋媇欓臯㔗認儖媺臕臖臔橸襕幽垯噘欓臯潊媘襕幽婉库䫘傂嘘嘌巉㔗

套悩婘臔橸婺噾䂟嘪䫘庖 BEGIN, COMMIT, ROLLBACK 闼幽臖锬釹儖婉嚔冖彄橘橕䔇昽悩㔗劯湙套悩臔橸婺寙劆傂嘘婉脘婘庋媇庖喙鄘嘪䫘䔇变傴嘪䫘認婻锬釹儖凚躘認湙䔇变傴欓臯崌蘖嘷䇽昘婻庋媇庥儖崌蘖㔗

-?
--help

滆䴺噿庯 psql 变傴臯埗昄䔇婞媷䇽劯锔庺㔗

锔庺䪽攕

套悩溼婩䂷溘闼幽 psql 劏 shell 誫啂 0 套悩躻躆埏䫘躘变髍臇彍誫啂 1(喙庻䫘儘橻欆彄桺傽京)套悩启昄扞康䔇誂毖崌昽蔯婫嚔臺婉喉昂虄彍誫啂 2 套悩臔橸婺埏䫘髍臇幽婫螆䘞庖 ON_ERROR_STOP 彍誫啂 3 㔗

䫘濘

誂毖婔婻昄扞康

psql 滇婔婻捞锔䔇 PostgreSQL 垵潙䆇庫䫘㔗婺庖婯婔婻昄扞康誂毖嘹驔襕䘖長䕞湺昄扞康㔕橉媇単䔇婂橺劉启䆇埼埙㔕傖埪嘹婯橕傖巻婻䫘潙䔇躆傘誕臯誂毖京媇敇㔗埇傖锔誺变傴臯埗昄 -d, -h, -p, -U 只臬 psql 認底媇敇㔗套悩昊婻埗昄婉匂庯傂嘘锬釹闼幽垄嚔赆蓼麪潊昄扞康劉潡蔙滇䫘潙劉(套悩昄扞康劉䓄噾䂟䂍庺庖)㔗婉滇欔橬認底锬釹鄘滇媙釂䔇橬䔇䚺䩕儌庻婘㔗套悩嘹䩕䘖婂橺劉psql 儖锔誺 Unix 嘘喖毖庖婯橸婄婂橺䔇橉媇単䕩蕫潡蔙婘澇橬 unix 嘘喖毖庖䔇橺単婪锔誺 TCP/IP 婯 localhost 誂毖㔗䚺䩕䔇䆇埼埙滇䚡臏施䇞垔䔇㔗啹婺昄扞康橉媇単嘪䫘劯湙䔇䚺䩕唚欔傖婘崓崔昄螆䘞婋嘹埇脘婉驔襕弄滯䆇埼埙㔗䚺䩕䔇䫘潙劉滇嘹䔇 Unix 䫘潙劉婯昄扞康劯劉㔗襕濘懟䔇滇嘹婉脘䫘傂懟䫘潙劉婯傂嘘昄扞康䕩蕫㔗嘹䔇昄扞康䞇䊖叻庫臖只臬嘹橬巻底螪閞溄鍊㔗

套悩䚺䩕婉崻溼䇞闼幽嘹埇傖锔誺螆䘞庹婻䯇嵄埻麟 PGDATABASE, PGHOST, PGPORT and/or PGUSER 䔇桹濘誗亥庹渇显庂㔗噽垄䯇嵄埻麟䔇媇敇埗黙誗29.12㔗埥崡䫘婔婻 ~/.pgpass 桺傽準镪噉膷噖凖乕幘滇冽桹冪䔇㔗埗黙誗29.13诙埡敘崔媇敇㔗

套悩啹婺傂嘘寘啹蔯方濘婯昄扞康䕩蕫(溄鍊婉崘㔕橉媇単澇橬誊臯京)psql 儖誫啂婔婻髍臇幽锔庺㔗

膷噖 SQL 变傴

锔婩䪽喕婋psql 柊冕婔婻婥橬溼婘婯幋誂毖䔇毖昄扞康劉䔇劯䚔 => 䔇柊䴺严㔗冋套

$ psql testdb
Welcome to psql 8.2.3, the PostgreSQL interactive terminal.

Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help with psql commands
       \g or terminate with semicolon to execute query
       \q to quit

testdb=>

䫘潙埇傖婘認婻柊䴺严婋髞噖 SQL 变傴㔗锔婩膷噖䔇臯儖婘变傴䂽溵彖埙庺䯄施锕彄橉媇単㔗婔臯䔇䂽溵幽婉臘䴺变傴䔇䂷溘㔗啹溴变傴埇傖婺庖橙捄蕙蓕虘轪喘庹臯㔗套悩变傴埏锕庺寂蔯婫欓臯澇橬髍臇变傴䂷悩嚔滆䴺婘匟幘婪㔗

嘷变傴溼婘誕臯施psql 劯湙誻蘞臵䫌 LISTENNOTIFY 䫘潊䔇嚗準锔䘖媇埙㔗

噄变傴

嘹婘 psql 麯膷噖䔇傂嘘傖婉婥嚘埙䔇埉桩溹嚔崘䔇婩薪鄘滇 psql 噄变傴認底变傴滇儖䫌 psql 躻噌崇䊖䔇㔗認底变傴幘滇嘪冖 psql 敘冪庯䞇䊖潡幥喍臔橸䔇寘啹㔗噄变傴敘婩蓕䔇埆濘滇桩溹潡埉桩溹变傴㔗

婔婻 psql 变傴䔇湚嚟滇埉桩溹劯麵䘓虘婔婻变傴媘臉䇽劯滇傂懟埗昄㔗埗昄婯变傴媘臉启噽垄埗昄傖傂懟婻䷺䍘庖严閘锫㔗

襕婘埗昄麯麵寙劆䷺䍘嘹媙釂䫘剘嚘埙檪垄寙啘蕙準㔗襕婘認湙䔇埗昄麯寙劆剘嚘埙埇傖婘嬉麵媹婔婻埉桩溹㔗傂嘘寙劆婘剘嚘埙麯䔇婩薪鄘嚔赆誕婔準誕臯䌂 C 䔇敪扵\n (桄臯)㔕\t (彽臘严)㔕\digits (噆誕彽臘䴺䔇庖严)㔕\xdigits (剕噺誕彽臘䴺䔇庖严)

套悩婔婻婉婥嚘埙䔇埗昄傖喐埙(:)嚔崘垄嚔赆嘷嘩婔婻 psql 埻麟幽婫臖埻麟䔇唚嚔橔䂽潊婺䩘溼䔇埗昄唚㔗

䫘埉勆埙(`)寙啘䔇喙垹赆嘷嘩婔婻变傴臯嚹噖 shell 㔗臖变傴䔇膷庺(役鍴庖䂷儆䔇桄臯)赆嘷嘩埗昄唚㔗婪麵柟誄䔇锄锩(庖严)废彖婘埉勆埙麯幘䫘昽㔗

橬底变傴傖婔婻 SQL 湺臖䔇劉䓄(懫套婔婻臘劉)婺埗昄㔗認底埗昄镕冻 SQL 臺濘噿庯埯嚘埙䔇蓇彍婉婥埯嚘埙䔇湺臖嚺彽潊償喍蔯埯嚘埙媺檴庖應婉誕臯崓償喍蘸扵幽婫噕螩婘湺臖严婺嘪䫘䷺䍘㔗婘埯嚘埙婺潊凹䔇埯嚘埙婘䂷悩劉庖婺彖悊潊婔婻埯嚘埙㔗懫套FOO"BAR"BAZ 蓼悊潊 fooBARbaz 蔯 "A weird"" name" 蓼悊潊 A weird" name

凹埗昄䔇彖悊婘䵄彄埥婔婻婉婥嚘埙䔇埉桩溹施啩溵㔗認麯嚔螴婺滇婔婻桄䔇噄变傴䔇嚔哋㔗䬹枪䔇埯埉桩溹废彖(\\)湺臖埗昄䔇䂷儆幽儖䂓䂺彖悊劯麵䔇 SQL 变傴(套悩庻婘䔇臺)㔗認湙 SQL 启 psql 变傴埇傖躻䫌䔇婘婔臯麯麵晙劽㔗嘖滇婘傂嘘愙喕婋婔溇噄变傴䔇埗昄婉脘傽䂺轙誺臯儆㔗

婋麵滇噾垔幬䔇噄变傴

\a

套悩䕞嬉䔇臘膷庺湚嚟滇婉凹阊䔇彍彺扵潊凹阊䔇㔗套悩滇凹阊䔇彍彺扵潊婉凹阊㔗認溇变傴滇婺庖劏劯噚垹㔗埗黙 \pset 诙埡婔婻敘锔䫘䔇蓼喿桹濘㔗

\cd [ directory ]

檪嘷嬉噖嘩䕞嘘櫹埻彄 directory 㔗澇橬埗昄彍滇櫹埻彄嘷嬉䫘潙䔇垽䕞嘘㔗

㔊柊䴺㔏嘪䫘 \!pwd 欷剄庺嘷嬉噖嘩䕞嘘

\C [ title ]

檪溼婘欷剄䔇臘䔇湺鵻螆䘞婺婔婻昖臵䔇䂷悩潡蔙埡潽認湙䔇螆䘞㔗認溇变傴京昽庯 \pset title title 㔗認溇变傴䔇劉䓄溊庯"caption"啹婺傖嬉埻滇䫘庯婘婔婻 HTML 臘湚麯麵螆䘞湺鵻㔗

\connect(潡 \c) [ dbname [ username ] [ host ] [ port ] ]

婯婔婻桄䔇昄扞康傺䆋婔婻誂毖嘪䫘/婉䫘婔婻䫘潙劉㔗嬉麵䔇誂毖儖噿閺㔗套悩 dbname, username, host, port 赆䩕䘖潡滇 - 闼幽儌嘪䫘婪渇誂毖麯麵䔇唚㔗 套悩幋嬉澇橬鷆毖彍嘪䫘 libpq 䔇䚺䩕唚㔗

套悩誂毖崌蘖(䫘潙劉髍㔕螪閞赆拐䂺京)闼幽嘷 psql 崇庯庴庐昇嚟施儖媺䘍嬉麵䔇誂毖㔗套悩誊臯䔇滇麂庴庐䔇臔橸崇䊖嚔鷸婪啩溵幽誫啂婔婻髍臇㔗螆䘞認湙䔇寺彆婔桹麵滇婺䫘潙嘪䫘桹冪蔄荏埥婔桹麵幘婺庖媺臕臔橸婉嚔䵄噓淉嘩庖髍臇䔇昄扞康䔇垬噘橺彽蔄荏㔗

\copy { table [ ( column_list ) ] | ( query ) } { from | to } { filename | stdin | stdout | pstdin | pstdout } [ with ] [ binary ] [ oids ] [ delimiter [ as ] 'character' ] [ null [ as ] 'string' ] [ csv [ header ] [ quote [ as ] 'character' ] [ escape [ as ] 'character' ] [ force quote column_list ] [ force not null column_list ] ]

欓臯嬉䆇(垵潙䆇)拙蘺㔗認滇婔婻誊臯 SQL COPY 变傴䔇淉嘩婉劯䔇滇橉媇単婘臂喍毺滯䔇桺傽蔯 psql 臂喍桺傽幽嘩婺橸婄䔇桺傽係䂘启橉媇単幋閘䔇虿溪埡庺潡喍噖昄扞㔗認懟叿五桺傽螪閞攓启溄鍊鄘滇橸婄䫘潙䔇蔯婉滇橉媇単䔇啹溴婉驔襕 SQL 轙亓䫘潙溄鍊㔗

認溇变傴䔇臺濘滇昇拘 SQL COPY 变傴䔇㔗襕濘懟䔇滇啹溴婥準婔底庫䫘庯 \copy 变傴䔇䬹枪彖悊蓇彍(儴噽滇埻麟敪扵蓇彍启埉桩溹傼扵蓇彍)儖婉蕙嘩䫘㔗

\copy ... from stdin | to stdout 彖彆嘺庯变傴膷噖启膷庺誕臯臂/喍㔗欔橬臯鄘傯埏庺变傴䔇劯婔婻溊臂埡䕘彄臂彄庖 \. 潡蔙敕膆彄 EOF 㔗膷庺埏锕彄启变傴膷庺䕩劯䔇嘉䘞㔗襕傯 psql 䔇湺庖膷噖潡蔙膷庺臂/喍埇傖嘪䫘 pstdinpstdout 㔗認婻锬釹䫘庯檪启 SQL 臔橸啯婘婔蕙䔇桺傽准噙臘冽橬䫘㔗

㔊柊䴺㔏 溴淉嘩婉償 SQL COPY 变傴認湙醻昽啹婺欔橬昄扞媙釂锔誺垵潙䆇/橉媇単誂毖㔗凹庯崓昄扞麟䔇淉嘩SQL 变傴䔇桹濘敘埇臯㔗

\copyright

滆䴺 PostgreSQL 䔇䬽溄启䬽橸媇敇㔗

\d [ pattern ]
\d+ [ pattern ]

凹庯懟婻对陉 pattern 䔇噿係(臘㔕蓖商㔕䘵嚘㔕废彖)滆䴺欔橬彖㔕垄傸䔇䌂傋㔕臘䷺閘(套悩婉滇䚺䩕䔇)启傂嘘䬹枪匂攓(臩套 NOT NULL 潡䚺䩕京埻襕庻婘)㔗嫇婔亥溘䕩噿䔇䘵嚘㔕蓇彍㔕亥溘㔕蓥埏単幘劯湙滆䴺庺準㔗套悩噿係滇婔婻蓖商誻滆䴺蓖商䔇垔幬㔗"对陉昇嚟"婘婋麵垔幬㔗

\d+ 準䔇变傴幘滇婔湙䔇埻婉誺滆䴺敘崔媇敇傂嘘婯臘䔇彖噿蕫䔇濘麪幘鄘嚔滆䴺誻橬儌滇臘婺庺䯄䔇 OID 㔗

㔊濘懟㔏套悩套悩婉婥傂嘘 pattern 脄䫘 \d 闼幽京昽庯 \dtvs 儖滆䴺婔婻欔橬臘蓖商启废彖䔇彖臘㔗認垯噘滇庺庯桹冪䔇蔄荏㔗

\da [ pattern ]

彖庺欔橬埇䫘䔇蕔镖庘昄傖埪垄傸淉嘩䔇昄扞䌂傋㔗套悩弄滯庖 pattern 闼幽埻滆䴺对陉(溼彍臘膆嚟)䔇蕔镖庘昄㔗

\db [ pattern ]
\db+ [ pattern ]

彖庺欔橬埇䫘䔇臘䷺閘㔗套悩弄滯庖 pattern 闼幽埻滆䴺闼底对陉昇嚟䔇臘䷺閘㔗套悩婘变傴劉婪鍇媹庖 + 闼幽懟婻凹茇鄘启婯幋䕩噿䔇溄鍊婔蕙彖庺㔗

\dc [ pattern ]

彖庺欔橬庖严镖幋閘䔇埇䫘蘸扵㔗套悩弄滯庖 pattern 彍埻彖庺闼底对陉昇嚟䔇蘸扵㔗

\dC

彖庺欔橬䌂傋蘸扵㔗

\dd [ pattern ]

滆䴺欔橬对陉 pattern 䔇柟誄套悩澇橬䂍庺埗昄滆䴺欔橬埇蓖凹茇㔗嘖滇婉䞇支湙埻橬闼底橬柟誄喙垹䔇凹茇欉滆䴺庺準㔗"凹茇"寙拸蕔镖㔕庘昄㔕淉嘩严㔕䌂傋㔕噿係(臘㔕蓖商㔕䘵嚘㔕废彖㔕崓凹茇)㔕蓇彍㔕蓥埏単㔗冋套

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

埇傖䫘 COMMENT 变傴䫘潊凹茇䔇柟誄㔗

\dD [ pattern ]

彖庺欔橬埇䫘嘘㔗套悩弄滯庖 pattern 闼幽埻滆䴺对陉䔇嘘㔗

\df [ pattern ]
\df+ [ pattern ]

彖庺欔橬埇䫘庘昄傖埪垄傸䔇埗昄启誫啂䔇昄扞䌂傋㔗套悩弄滯庖 pattern 闼幽埻滆䴺对陉(溼彍臘膆嚟)䔇庘昄㔗套悩嘪䫘庖 \df+ 䔇嘵嚟懟婻庘昄䔇鍇媹媇敇寙拸臺蘔启柟誄幘嚔滆䴺庺準㔗

㔊濘懟㔏襕昖欆毖埖潡蔙誫啂䬹垔䌂傋䔇庘昄嘪䫘嘹䔇彖釕単抩䘵媘脘準悔媘 \df 䔇膷庺㔗

婺庖废儏晙幌\df 幽婉滆䴺昄扞䌂傋䔇膷噖膷庺庘昄㔗認湙滇锔誺媘䘖闼底毖埖潡蔙誫啂䌂傋 cstring 䔇庘昄垂䯄䔇㔗

\dg [ pattern ]

彖庺欔橬昄扞康蓐謾㔗套悩弄滯庖 pattern 闼幽埻滆䴺闼底对陉昇嚟䔇劉庖㔗認溇变傴垂鍙婪京庯 \du

\distvS [ pattern ]

認婉滇垂鍙䔇变傴劉䓄庖應 i, s, t, v, S 彖彆傼臘䘵嚘(index)㔕废彖(sequence)㔕臘(table)㔕蓖商(view)㔕係䂘臘(system table)㔗㔗嘹埇傖傖傂懟釺废弄滯傂懟潡蔙欔橬認底庖應诙冖認底凹茇䔇婔婻彖臘㔗庖應 S 檪彖臘鍊彽庯係䂘凹茇套悩澇橬 S 彍埻滆䴺麂係䂘凹茇㔗套悩婘变傴劉婪鍇媹庖 + 闼幽誻嚔彖庺启懟婻凹茇䕩噿蕫䔇柟誄套悩橬䔇臺㔗

套悩弄滯庖 pattern 闼幽埻彖庺对陉昇嚟䔇凹茇㔗

\dl

\lo_list 䔇彆劉滆䴺婔婻崓凹茇䔇彖臘㔗

\dn [ pattern ]
\dn+ [ pattern ]

彖庺欔橬埇䫘昇嚟(劉庖䷺閘)㔗套悩弄滯庖 pattern 闼幽埻彖庺对陉昇嚟䔇昇嚟劉㔗婉滆䴺麂橸婄䔇婘施昇嚟㔗套悩婘变傴劉婪鍇媹庖 + 闼幽懟婻凹茇鄘启婯幋䕩噿䔇溄鍊启濘麪婔蕙彖庺(套悩橬䔇臺)㔗

\do [ pattern ]

彖庺欔橬埇䫘淉嘩严傖埪垄傸䔇淉嘩昄启誫啂䔇昄扞䌂傋㔗套悩弄滯庖 pattern 闼幽埻滆䴺对陉昇嚟䔇淉嘩严㔗

\dp [ pattern ]

䫘潊婔彖埇䫘䔇臘启垄傸䕩噿䔇溄鍊㔗套悩弄滯庖 pattern 闼幽埻彖庺劉庖对陉昇嚟䔇臘㔗

GRANTREVOKE 变傴䫘庯螆䘞螪閞溄鍊㔗

\dT [ pattern ]
\dT+ [ pattern ]

彖庺欔橬昄扞䌂傋潡埻滆䴺闼底对陉 pattern 䔇㔗認溇变傴䔇 \dT+ 嘵嚟滆䴺敘崔媇敇㔗

\du [ pattern ]

彖庺欔橬噾陉䘞蓐謾潡蔙埻彖庺闼底对陉 pattern 䔇蓐謾㔗

\edit(潡 \e) [ filename ]

套悩弄滯庖 filename 彍䚡膏溴桺傽幽婫婘䚡膏単锔庺劯儖噽喙垹拙蘺啂昖臵䚷喾寺㔗套悩澇橬䂍庺溴埗昄彍檪嘷嬉昖臵䚷喾寺喙垹拙蘺彄婔婻婘施桺傽䇽劯傖䕩劯桹嚟䚡膏㔗

䇽劯湹扞婔轸䔇 psql 蓇彍麉桄彖悊昖臵䚷喾寺認施昘婻䚷喾寺嘷嘩婔婻剘臯啹溴嘹方濘䫘認婻桹濘彽嘩臔橸(䫘 \i)㔗認誻懟叿五套悩臖昖臵傖彖埙䂷儆(潡蔙寙劆彖埙)垄儌嚔鷸婪赆欓臯㔗劥彍垄埻滇婘昖臵䚷喾寺麯京写㔗

㔊柊䴺㔏 psqlPSQL_EDITOR, EDITOR, VISUAL 釺废抩䘵䯇嵄埻麟昖欆襕䫘彄巻婻䚡膏単㔗套悩婪麵䔇鄘澇橬螆䘞闼幽婘 Unix 係䂘婪嘪䫘 vi 蔯婘 Windows 係䂘婪䫘 notepad.exe

\echo text [ ... ]

劏湺庖膷庺欷剄埗昄䫘婔婻䷺湚彖锫幽婫橔劯虘五婔婻桄臯㔗認婻䬹攓婘滆䴺臔橸䔇膷庺施嚔橬䫘㔗冋套

=> \echo `date`
Tue Oct 26 21:40:57 CEST 1999

套悩丸婔婻埗昄滇婔婻方嚘埙䔇 -n 闼幽婉嚔喍庺䂷儆䔇桄臯㔗

㔊柊䴺㔏套悩嘪䫘 \o 变傴麉垔劏昖臵䔇膷庺嘹埇脘嚔䫘 \qecho 埡傼認溇变傴㔗

\encoding [ encoding ]

螆䘞垵潙䆇庖严䚡乕桹嚟㔗婉婥埗昄施認溇变傴滆䴺嘷嬉䔇䚡乕桹嚟㔗

\f [ string ]

婺婉凹阊䔇昖臵膷庺螆䘞嘘彖锫严㔗䚺䩕施滇䆡溇(|)㔗埗黙 \pset 诙埡螆䘞膷庺锬釹䔇锔䫘桹濘㔗

\g [ { filename | |command } ]

檪嘷嬉䔇昖臵膷噖䚷喾寺䔇喙垹埏锕䂍橉媇単幽婫檪昖臵䔇膷庺庻嗘彄埇锬䔇 filename 潡蔙檪膷庺麉垔劏彄婔婻䋸䆋䔇欓臯 command 䔇 Unix shell 㔗剘䋸婔婻 \g 垂鍙婪京昽庯婔婻彖埙㔗婔婻婥橬埗昄䔇 \g 滇"婔渇攓"䔇 \o 变傴䔇傼䫘巕㔗

\help(潡 \h) [ command ]

䂍庺毺垔 SQL 变傴䔇臺濘婞媷㔗套悩澇橬䂍庺 command 闼幽 psql 儖彖庺埇诙冖臺濘婞媷䔇欔橬变傴㔗套悩 command 滇婔婻滘埙(*) 彍滆䴺欔橬 SQL 变傴䔇臺濘婞媷㔗

㔊濘懟㔏婺䞔寡庂髞寙劆崔婻剘庖䔇变傴婉驔襕嚘蕙㔗啹溴髞噖 \help alter table 滇溼䇞䔇㔗

\H

欷嚔 HTML 昖臵膷庺湚嚟㔗套悩 HTML 湚嚟噾䂟欷嚔彍彺扵啂䚺䩕䔇凹阊䔇桺橸湚嚟㔗認婻变傴滇婺庖噚垹启桹冪埗黙 \pset 诙埡螆䘞噽垄膷庺锬釹䔇喙垹㔗

\i filename

傯桺傽 filename 婺臂埡幽檪噽喙垹嘷嘩傯髞䕻膷噖䔇闼湙欓臯昖臵㔗

㔊濘懟㔏套悩嘹愿婘匟幘婪䩋彄臂噖䔇臯儌媙釂凹欔橬臯儖埻麟 ECHO 螆䘞婺 all

\l(潡 \list)
\l+(潡 \list+)

彖庺橉媇単婪欔橬昄扞康䔇劉庖启垄傸䔇欔橬蔙傖埪庖严镖䚡乕㔗婘变傴劉䓄劯麵媹婔婻 + 誻埇傖䩋彄凹昄扞康䔇柟誄㔗

\lo_export loid filename

傯昄扞康麯臂埡 OID 婺 loid 䔇崓凹茇幽檪垄喍彄 filename 麯㔗濘懟認婻媘脘婯橉媇単庘昄 lo_export 橬底冞償䔇寺彆劯蔙誊臯施婥五誊臯昄扞康橉媇単䔇䫘潙溄鍊蔯婫滇婘橉媇単䔇桺傽係䂘婪㔗

㔊柊䴺㔏嘪䫘 \lo_list 昖䩋崓凹茇䔇 OID 㔗

\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 橬婔底寺彆啹婺認溇变傴滇橸婄䫘潙婘橸婄桺傽係䂘婪淉嘩蔯婉滇傖橉媇単䫘潙婘橉媇単桺傽係䂘婪淉嘩㔗

\lo_list

滆䴺婔婻䕞嬉庻嗘婘臖昄扞康麯䔇欔橬 PostgreSQL 崓凹茇启垄傸䔇欔橬蔙䔇彖臘㔗

\lo_unlink loid

傯昄扞康麯役鍴 OID 婺 loid 䔇崓凹茇㔗

㔊柊䴺㔏嘪䫘 \lo_list 昖欆崓凹茇䔇 OID 㔗

\o [ {filename | |command} ]

檪劯麵䔇昖臵䂷悩媺庻彄桺傽 filename 麯潡蔙檪劯麵䔇昖臵䂷悩麉垔劏彄婔婻䋸䆋欓臯 command 䔇 Unix shell 㔗套悩澇橬弄滯埗昄昖臵膷庺儖赆麉䘞婺湺庖膷庺㔗

"昖臵䂷悩"寙拸欔橬臘变傴巉庫启傯昄扞康橉媇単準䔇柊䴺劯湙誻橬劇䓉劇湙昖臵昄扞康䔇埉桩溹变傴䔇膷庺(套 \d)嘖滇澇橬髍臇媇敇㔗

㔊柊䴺㔏襕䫘桺橸彖昼昖臵䂷悩幋閘䔇膷庺䫘 \qecho

\p

欷剄嘷嬉昖臵䚷喾寺彄湺庖膷庺㔗

\password [ username ]

敘櫹毺垔䫘潙䔇埼傴䚺䩕婺嘷嬉䫘潙㔗臖变傴儖柊䴺埼傴膷噖䇽劯儖媹凖誺䔇埼傴嘪䫘 ALTER ROLE 幋䌂䔇变傴埏锕䂍橉媇単㔗認埇傖媺臕桄埼傴婉嚔傖滯桺嘵嚟庺䯄婘变傴寖埾㔕橉媇単斖媖㔕潡噽傡傔幽婄桹㔗

\pset parameter [ value ]

認溇变傴螆䘞嘌巉昖臵䂷悩臘膷庺䔇锬釹㔗parameter 柟誄襕螆䘞䔇锬釹滇巻婔婻㔗value 䔇臺懟幘埡喿庯垄㔗

埇脄誗䔇欷剄锬釹橬

format

螆䘞膷庺湚嚟婺 unaligned, aligned, html, latex, troff-ms 幋婔㔗噕螩嘪䫘嫇婔䚷喍認幘懟叿五婔婻庖應儌崘庖㔗

"Unaligned"(婉凹阊)檪婔溇螄嘘䔇欔橬庖枕鄘膷庺彄婔臯䫘嘷嬉橬昽䔇嘘彖锫严彖锫㔗認婂襕䫘庯䫘潊闼底襕赆噽垄䘋废臂埡䔇膷庺(彽臘严彖锫㔕锖埙彖锫)㔗"Aligned"(凹阊)昇嚟滇湺庖䔇庺䌂埇臂䔇湚嚟寡喘庖䔇桺橸膷庺幘滇䚺䩕㔗"HTML"启"LaTeX"昇嚟檪臘膷庺婺埇䫘庯桺懼麯䔇凹庫湺螄臺蘔㔗垄傸誻婉滇垯昘䔇桺懼埇脘凹庯 HTML 埻寡誻婉滇崻崓嘖滇婘 LaTeX 麯嘹媙釂橬婔婻垯昘䔇桺懼寙輙単㔗

border

丸庯婻埗昄媙釂滇婔婻昄庖㔗锔婩昄庖轪崓臘儌橬轪垘䔇膹䘯启轪崔䔇亪嘖滇認婻埗昄埡喿庯垂鍙䔇湚嚟㔗婘 HTML 昇嚟麯認婻埗昄嚔䕘毖䪂臏潊 border=... 匂攓婘噽垄䔇昇嚟麯埻橬唚 0(方膹䘯)㔕1(喙鄘彖锫亪)㔕2(臘懖悽)橬懟幬㔗

expanded(潡 x)

婘溼婩启欷匘湚嚟幋閘彺扵㔗嘷欷嚔欷匘湚嚟施昖臵䂷悩䫘婴彖滆䴺庖枕劉䓄婘噥㔕昄扞婘埿㔗認婻昇嚟婘昄扞方濘櫆誕锔婩䔇"愘广"昇嚟䔇匟幘施冽橬䫘㔗

欔橬啕䓉膷庺昇嚟鄘櫇毕欷匘湚嚟㔗

null

丸庯婻埗昄滇婔婻庖严婾䫘傖傼臘庖枕䔇唚婺 null 施䔇欷剄膷庺㔗䚺䩕滇傔幽鄘婉欷認湙冽垹滷启䌂嚚婔婻䷺庖严婾晙晖㔗啹溴埇脘锬拷 \pset null '(null)'

fieldsep

弄滯婘麂凹阊昇嚟施䔇嘘彖锫严㔗認湙儌埇傖录傺噽垄䘋废婯橕䔇彽臘严潡锖埙彖锫䔇膷庺㔗襕螆䘞彽臘严嘘彖锫严髞噖 \pset fieldsep '\t' 㔗䚺䩕嘘彖锫严滇 '|' (䆡溇严)㔗

footer

彺扵䚺䩕臔濘(x rows)

numericlocale

彺扵彖锫償昄䗹噥膹䔇昄唚䔇寺嘘䕩噿䔇彖䂇严埙㔗垄誻欷嚔寺嘘䕩噿䔇償昄䗹㔗

recordsep

弄滯婘麂凹阊昇嚟施䔇螄嘘彖锫严㔗䚺䩕滇扵臯严㔗

tuples_only(潡 t)

婘垯噘滆䴺启埻滆䴺螄嘘幋閘彺扵㔗垯噘滆䴺儖滆䴺償彖崘㔕湺鵻㔕劇䓉臔濘京媇敇㔗婘認婻昇嚟婋埻滆䴺螄嘘昇嚟儖埻滆䴺垂鍙䔇臘昄扞㔗

title [ text ]

婺傂嘘锟劯欷剄䔇臘螆䘞湺鵻㔗認婻埗昄埇傖䫘庯䂍嘹䔇膷庺婔婻柟誄攓湺螄㔗套悩婉婥埗昄麉䘞湺鵻㔗

tableattr(潡 T) [ text ]

噕螩嘹弄滯櫆婘 HTML table 湺了麯䔇傂嘘匂攓(冋套 cellpaddingbgcolor)㔗濘懟嘹埇脘婉驔襕婘認麯弄滯 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 㔗套悩䩕䘖彍膷庺彄湺庖膷庺㔗認婻锬釹埻橬婘 psql 陉䘞潊嘪䫘 GNU Readline 康劯欉䫘昽㔗

\set [ name [ value [ ... ] ] ]

螆䘞喙鄘埻麟 namevalue 潡蔙套悩䂍庺庖崔庯婔婻唚螆䘞婺欔橬認底唚䔇誂毖䂷悩㔗套悩澇橬䂍庺丸庯婻埗昄闼幽埻螆埻麟婉螆唚㔗襕麉䘞婔婻埻麟嘪䫘 \unset 变傴㔗

橬昽䔇埻麟劉埇傖寙劆庖严昄庖启婋彐亪㔗埗黙婋麵䔇埻麟诙埡䂖誗㔗

儘䞇嘹埇傖螆䘞傂嘘埻麟婺傂懟唚psql 凹婔底埻麟䬹枪凹写㔗垄傸婘噿庯埻麟䔇償誗麯麵橬桺懼㔗

㔊濘懟㔏認溇变傴启 SQL 变傴 SET 滇垯噘婉婔湙䔇㔗

\t

彺扵膷庺䔇庖枕劉䔇媇敇崘启臯螄昄臔濘㔗認溇变傴京昽庯 \pset tuples_only 柊冕垄婂襕婺庖桹冪㔗

\T table_options

噕螩嘹婘嘪䫘 HTML 膷庺昇嚟施弄滯櫆婘 table 湺螄麯䔇匂攓㔗認溇变傴京昽庯 \pset tableattr table_options

\timing

傖懆䓐婺剘嘉滆䴺懟溇 SQL 臺埖䔇蔖施㔗

\w {filename | |command}

儖嘷嬉昖臵䚷喾寺膷庺彄桺傽 filename 潡蔙麉垔劏彄 Unix 变傴 command

\x

彺扵欷匘臯湚嚟㔗京昽庯 \pset expanded

\z [ pattern ]

䫘潊婔婻婥橬螪閞溄鍊彖臘䔇昄扞康婺欔橬臘㔕蓖商㔕废彖䔇彖臘㔗套悩䂍庺傂嘘 pattern 彍赆嘷潊婔婻溼彍臘膆嚟埻滆䴺对陉䔇臘㔕蓖商㔕废彖㔗

GRANTREVOKE 变傴䫘庯螆䘞螪閞溄鍊㔗

認滇 \dp (滆䴺溄鍊)䔇彆劉㔗

\! [ command ]

誫啂彄婔婻剘䋸䔇 Unix shell 潡蔙欓臯 Unix 变傴 command 㔗埗昄婉嚔赆誕婔準蓼麪shell 儖䩋彄噘鄘埗昄㔗

\?

诙冖噿庯埉桩溹变傴䔇婞媷媇敇㔗

对陉昇嚟

劇䓉 \d 变傴鄘毖埖婔婻 pattern 埗昄弄滯襕滆䴺䔇凹茇劉庖㔗橔䞔剘䔇愙喕婋 pattern 溼喘京庯凹茇䔇劉庖㔗pattern 婺䔇庖严锔婩嚔赆躻媘蘸扵潊償喍儌償 SQL 劉庖婔湙㔗冋套 \dt FOO 儖滆䴺劉婺 foo 䔇臘㔗婯婘 SQL 劉庖婺䕩劯䔇滇埯嚘埙䘯垔䔇 pattern 儖媺毕寘湙(婉啔崓償喍蘸扵)㔗套悩驔襕婘埯嚘埙䘯垔䔇 pattern 婺嘪䫘埯嚘埙庖严嘹埇傖喍婴婻幽彖䔇埯嚘埙認婯 SQL 䔇嚘埙蓇彍䕩劯㔗冋套\dt "FOO""BAR" 儖嚔滆䴺劉婺 FOO"BAR 䔇臘嘖滇婉嚔滆䴺 foo"bar 㔗婯婔轸䔇 SQL 劉庖蓇彍婉劯䔇滇嘹埇傖備䫘埯嚘埙䘯垔劉庖䔇婔鄘彖冋套 \dt FOO"FOO"BAR 儖滆䴺劉婺 fooFOObar 䔇臘㔗

pattern 婺䔇 * 臘䴺"傂嘘庖严废彖"寙拸"澇橬庖严"蔯 ? 臘䴺"傂嘘剘婻庖严"㔗認婻臘䴺濘启 Unix 䔇 shell 桺傽劉昇嚟噚垹㔗懫套 \dt int* 滆䴺欔橬劉庖傖 int 嚔崘䔇臘㔗嘖滇婘埯嚘埙喙鄘䔇 *? 婉噙橬对陉䔇媘脘垄傸埻傼臘躻躆㔗

寙劆䗹(.)䔇 pattern 儖赆蓼麪潊昇嚟劉 pattern 劯麵虘婔婻凹茇劉 pattern 㔗冋套 \dt foo*.bar* 滆䴺欔橬劉庖傖 foo 嚔崘䔇昇嚟婺䔇欔橬劉庖傖 bar 嚔崘䔇臘㔗套悩澇橬庺䯄埖䗹闼幽認婻昇嚟埻对陉婘嘷嬉昇嚟抩䘵虇冇婺埇蓕䔇凹茇㔗劯湙婘埯嚘埙喙䔇䗹澇橬認婻劆幬垄埻傼臘噽躻躆㔗

誻埇傖嘪䫘溼彍臘膆嚟臺濘懫套庖严䌂京京㔗冋套䫘 [0-9] 对陉欔橬昄庖㔗鍴 . 幋崡䔇欔橬溼彍臘膆嚟婺䔇䬹枪庖严鄘毬䙓誗9.7.3麯麵柟誄䔇蓇彍誕臯蓼悊溴崡* 儖赆䊖蓼潊 .* 劯施 ? 儖赆䊖蓼潊 . 㔗認湙婔準嘹儌埇傖䫘 ? 傼敪 . 㔕䫘 (R+|) for R* 㔕䫘 (R|) 傼敪 R? 㔗驔襕濘懟䔇滇昇嚟媙釂对陉昘婻劉䓄蔯婉滇婔轸䊖蓼䔇对陉婔鄘彖剿埇㔗套悩嘹埻愿对陉婔鄘彖埇傖婘 pattern 䔇嚔崘启䂷儆嘪䫘 * 㔗誻驔襕濘懟䔇滇婘埯嚘埙喙鄘䔇欔橬溼彍臘膆嚟䬹枪庖严鄘儖崌寂噽䬹枪劆幬㔗劯湙婘凹淉嘩严(幘儌滇嘩婺 \do 埗昄䔇施唍)誕臯对陉施溼彍臘膆嚟䬹枪庖严幘儖崌寂噽䬹枪劆幬㔗

套悩垯噘䩕䘖 pattern 埗昄闼幽 \d 变傴滆䴺欔橬婘嘷嬉昇嚟抩䘵虇冇婺埇蓕䔇凹茇(京備庯嘪䫘 * 对陉昇嚟)㔗襕昖黙婘昄扞康婺䔇欔橬凹茇嘪䫘 *.* 昇嚟㔗

醻亓䬹攓

埻麟

psql 柊冕䌂嚚锔婩 Unix 变傴 shell 闼湙䔇埻麟敪扵䬹攓㔗埻麟埻滇䞔剘䔇劉䓄/唚凹認麯䔇唚埇傖滇傂嘘阪庥䔇傂嘘唚㔗埇傖嘪䫘 psql 噄变傴 \set 螆䘞婔婻埻麟

testdb=> \set foo bar

檪埻麟 foo 䔇唚螆䘞婺 bar 㔗襕演䘵埻麟䔇喙垹婘埻麟劉嬉麵櫆婪喐埙䇽劯檪垄䫘婘傂懟桩溹变傴麯

testdb=> \echo :foo
bar

㔊濘懟㔏\set 䔇埗昄橉傯启噽垄变傴婔湙䔇敪扵蓇彍㔗啹溴嘹埇傖悇锹橬轼䔇嚘䫘償 \set :foo 'something' 認湙诙冖彖彆償 Perl 潡 PHP 闼湙橬劉䔇"蘇誂毖"潡"埻麟埻麟"㔗婉幩(潡蔙婺幩?)䔇滇䫘認底悇锹婉脘啔傂嘘橬䫘䔇庋愙㔗埥婔桹麵\set bar :foo 滇婔婻麂婩橬昽䔇拙蘺埻麟䔇桹濘㔗

套悩嘹婉婥丸庯婻埗昄脄䫘 \set 闼幽埻滇螆䘞認婻埻麟蔯澇橬唚㔗襕麉䘞(潡役鍴)婔婻埻麟嘪䫘 \unset 变傴㔗

psql 䔇喙鄘埻麟埇傖寙拸傂懟釺废启昄麟䔇庖應㔕昄庖㔕婋彐亪㔗橬婔底婩䫘埻麟赆 psql 䬹枪䕩写㔗垄傸滇婔底锬釹螆䘞認底锬釹婘誊臯施埇傖锔誺櫹埻埻麟䔇唚潡蔙櫹埻婔底庫䫘䔇臘䯄䪽攕蔯櫹埻㔗儘䞇嘹埇傖檪認底埻麟䫘庯噽垄䫘锫嘖滇婉隷媌認幽啔啹婺䘋废䔇䬹攓埇脘嚔埻冖麂婩喺攻㔗锔婩欔橬䬹枪凹写䔇埻麟鄘滇䫌崓喍庖應䂇潊(埇脘誻橬昄庖启婋彐亪)㔗婺庖媺臕启橻準䔇橔崓鍊庥䔇噚垹攓臙镪噉嘪䫘認湙䔇埻麟㔗婋麵滇婔婻欔橬䬹枪凹写䔇埻麟彖臘㔗

AUTOCOMMIT

套悩滇 on(䚺䩕)闼幽懟婻 SQL 变傴鄘婘潊媘垯潊劯躻媘柊庴㔗襕毘誘認䓉昇嚟婋䔇柊庴嘹媙釂膷噖婔婻 BEGINSTART TRANSACTION 变傴㔗套悩滇 off 潡蔙橻螆䘞SQL 变傴婉嚔柊庴䕘彄嘹滯䇞婄埏庺 COMMITEND 㔗噿閺躻媘柊庴䔇昇嚟滇锔誺婺嘹滯䇞埏庺婔婻 BEGIN 垂䯄䔇垄滇櫆婘傂嘘儔橻婘婔婻庋媇庖婺幽婫躻噌婉滇 BEGIN 潡噽垄庋媇毓彽变傴幘婉滇闼底婉脘婘庋媇庖麯欓臯䔇变傴(懫套 VACUUM)䔇嬉麵㔗

㔊濘懟㔏婘噿閺躻媘柊庴䔇昇嚟婋嘹媙釂滯䇞櫆嚄傂嘘崌蘖䔇庋媇桹濘滇欓臯 ABORTROLLBACK 㔗誻襕濘懟套悩嘹婉柊庴儌锔庺嚔臺欔啔䔇噖嘩嚔婵崌㔗

㔊濘懟㔏欷嚔躻媘柊庴滇 PostgreSQL 䔇嚹䂘臯婺嘖滇噿閺躻媘柊庴敘毖誏 SQL 蓇评㔗嘹埇傖婘係䂘评啘䔇 psqlrc~/.psqlrc 桺傽婺噿閺躻媘柊庴㔗

DBNAME

溼婘誂毖五䔇昄扞康劉䓄㔗懟渇婯婔婻昄扞康蕫䂷鄘嚔螆䘞認婻唚(寙拸䘋废劇媘)嘖滇埇傖役鍴㔗

ECHO

套悩螆婺 all 闼幽準躻髞䕻潡臔橸䔇欔橬膷噖臯婘彖悊潡欓臯嬉鄘啂滆彄湺庖膷庺㔗嘪䫘 -a 锬釹弄滯婘䘋废劇媘施儌邻螴認湙啔㔗套悩螆䘞婺 queries 闼幽 psql 埻滇婘昖臵埏锕䂍橉媇単幋嬉欷剄庺準㔗垂䯄認婻媘脘䔇变傴臯锬釹滇 -e

ECHO_HIDDEN

嘷螆䘞庖認婻埻麟幽婫婔婻埉桩溹变傴昖臵昄扞康施饡噽滆䴺昖臵㔗認湙嘹埇傖庥幹 PostgreSQL 喙鄘䔇婩薪幽婫婘嘹躻噌䔇䘋废麯柊冕䌂嚚媘脘㔗襕婘䘋废婔蕙媘䔇施唍儌劇䫘認婻臯婺埇傖嘪䫘 -E 锬釹㔗套悩嘹螆䘞臖埻麟䔇唚婺 noexec 闼幽昖臵埻滇滆䴺庺準嘖滇垂鍙婪婉埏锕彄橉媇単寂欓臯㔗

ENCODING

嘷嬉䔇垵潙䆇庖严镖䚡乕

FETCH_COUNT

套悩臖埻麟䔇唚崓庯镽SELECT 昖臵䔇䂷悩儖毬溴唚彖欹誫啂启滆䴺蔯婉滇䚺䩕䔇婔渇埡庺启滆䴺欔橬䂷悩㔗認湙儌埇傖方螺䂷悩镖橬崔崓鄘埻嘪䫘冽儏麟䔇喙庻㔗婔轸準臘螆婺 100 彄 1000 幋閘䔇唚懫膄劽䊖㔗驔襕濘懟䔇滇嘪䫘溴䬹攓劯婔婻昖臵埇脘婘滆䴺庖婔鄘彖䂷悩幋劯镺镺崌蘖㔗

㔊柊䴺㔏荘䇽臖䬹攓埇傖䫘庯欔橬膷庺湚嚟㔗嘖滇幽婉锗劽婘䚺䩕䔇 aligned 湚嚟婪嘪䫘認婻䬹攓啹婺懟婔欹䂷悩嚔赆剘䋸䔇彖嚔湚嚟寡認湙婔準懟婔欹膷庺䂷悩䔇彖垘儌埇脘劇婉䕩京㔗婉誺凹庯噽傡湚嚟認婻䬹攓噖嘩䔇冽喘㔗

HISTCONTROL

套悩儖認婻埻麟螆婺 ignorespace 闼幽傖䷺湚嚔哋䔇臯儖婉嚔誕噖寖埾彖臘㔗套悩螆䘞婺 ignoredups 闼幽婯傖嬉寖埾螄嘘麯对陉䔇臯幘婉嚔誕噖寖埾螄嘘㔗唚 ignoreboth 滇婪麵婴婻䔇䂷劽㔗套悩役鍴溴埻麟潡蔙噽唚婺傂嘘婯婪麵䔇唚婉劯䔇婩薪欔橬庴庐昇嚟臂噖䔇臯鄘赆媺庻噖寖埾彖臘㔗

㔊濘懟㔏認婻䬹攓滇傯 Bash 啙庥準䔇㔗

HISTFILE

溴桺傽儖䫘庯庻嗘寖埾彖臘㔗䚺䩕唚滇 ~/.psql_history 㔗懫套婘 ~/.psqlrc 麯嘪䫘

\set HISTFILE ~/.psql_history- :DBNAME

儖嘪冖 psql 婺懟婻昄扞康䂘檴婔婻䋸䆋䔇寖埾㔗

㔊濘懟㔏認婻䬹攓滇傯 Bash 啙庥準䔇㔗

HISTSIZE

媺庻婘变傴寖埾麯䔇变傴䔇婻昄㔗䚺䩕唚滇 500 㔗

㔊濘懟㔏認婻䬹攓滇傯 Bash 啙庥準䔇㔗

HOST

嘷嬉嘹溼誂毖䔇昄扞康橉媇単婂橺㔗認滇婘懟渇嘹婯昄扞康誂毖施(寙拸䘋废劇媘)螆䘞䔇嘖滇埇傖役鍴㔗

IGNOREEOF

套悩役鍴溴埻麟劏婔婻庴庐䔇 psql 嚔臺埏锕婔婻 EOF(锔婩滇 Control+D)儖䂽溵庫䫘㔗套悩螆䘞婺婔婻昄庖唚闼幽婘庫䫘䂽溵嬉臖昄唚䔇 EOF 庖严儖赆媘䘖㔗套悩螆䘞庖溴埻麟嘖滇澇橬昄庖唚䚺䩕滇 10 㔗

㔊濘懟㔏認婻䬹攓滇傯 Bash 啙庥準䔇㔗

LASTOID

橔劯嘌巉䔇 oid 唚剿婺傯婔溇 INSERTlo_insert 变傴誫啂䔇唚㔗溴埻麟埻媺臕婘婋婔溇 SQL 变傴䔇䂷悩滆䴺幋嬉橬昽㔗

ON_ERROR_ROLLBACK

套悩滇 on 闼幽嘷婔婻庋媇庖麯䔇臺埖库䫘髍臇䔇施唍認婻髍臇儖赆媘䘖蔯庋媇儖䂓䂺㔗套悩滇 interactive 闼幽認湙䔇髍臇埻滇婘庴庐䔇嚔臺麯媘䘖蔯婉滇婘傯臂埡臔橸桺傽䔇施唍㔗套悩滇 off(䚺䩕)庋媇庖麯婔婻臺埖䫘潊䔇髍臇儖嚔啂悔昘婻庋媇㔗on_error_rollback-on 䔇昇嚟滇锔誺婘婔婻庋媇庖䔇懟婻变傴嬉婺嘹锊劆婄埏庺婔婻 SAVEPOINT 䔇桹嚟噖嘩䔇婘埏䫘髍臇䔇施唍啂悔彄臖庋媇庖㔗

ON_ERROR_STOP

䚺䩕施套悩麂庴庐䔇臔橸䵄彄婔婻髍臇(懫套婔溇髍臇䔇 SQL 变傴潡蔙喙鄘噄变傴)崇䊖嚔䂓䂺誕臯㔗認滇 psql 䔇嚹䂘䬹攓嘖滇橬施唍婉崻婯橕認湙㔗套悩螆䘞庖認婻埻麟臔橸崇䊖儖鷸婪啩溵㔗套悩臖臔橸滇傯埥崡婔婻臔橸脄䫘䔇闼婻臔橸幘嚔毬劯湙䔇桹嚟啩溵㔗套悩橔崡北䔇臔橸婉滇傯婔渇庴庐䔇 psql 嚔臺婺脄䫘䔇蔯滇䫘 -f 锬釹脄䫘䔇psql 儖誫啂髍臇傼乕 3 傖䴺認婻愙喕婯躘变髍臇溇傽䔇寺彆(髍臇傼乕婺 1)㔗

PORT

嘷嬉嘹溼婘誂毖䔇昄扞康橉媇単䔇䆇埼㔗認滇婘懟渇嘹婯昄扞康誂毖施(寙拸䘋废劇媘)螆䘞䔇嘖滇埇傖役鍴㔗

PROMPT1
PROMPT2
PROMPT3

認底毺滯 psql 滆䴺䔇柊䴺严䩋婪寂償傔幽㔗埗黙婋麵䔇柊䴺严

QUIET

認婻埻麟京昽庯变傴臯锬釹 -q 㔗埇脘婘庴庐昇嚟婋澇橬傔幽䫘㔗

SINGLELINE

認婻埻麟京昽庯变傴臯锬釹 -S

SINGLESTEP

認婻埻麟京昽庯变傴臯锬釹 -s

USER

嘷嬉嘹溼䫘庯誂毖䔇昄扞康䫘潙㔗認滇婘懟渇嘹婯昄扞康誂毖施(寙拸䘋废劇媘)螆䘞䔇嘖滇埇傖赆役鍴㔗

VERBOSITY

認婻锬釹埇傖螆䘞婺唚 default, verbose, terse 幋婔傖毓彽髍臇檖只䔇喖嘍臯㔗

SQL 傼扵

婔婻鍇媹䔇 psql 埻麟䔇橬䫘䬹攓滇嘹埇傖檪垄傸敪扵潊溼蓇䔇 SQL 臺埖㔗認湙啔䔇臺濘劯湙誻滇埻麟劉嬉麵媹婔婻喐埙(:)㔗

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` ''''

套悩嘪䫘麂湺庖噚垹䔇庖严婾闼幽傉䇽驔襕埯喍埉桩溹㔗認橬底麂䄥

testdb=> \set content '''' `sed -e "s/'/''/g" -e 's/\\/\\\\/g' < my_file.txt` ''''

臙濘懟婉劯䔇 shell 嚘埙鼯湚䔇嘪䫘剘嚘埙启埉桩溹凹庯 shell 準臘鄘婉滇䬹枪庖严㔗嘖滇埉桩溹凹庯 sed 滇䬹枪庖严啹溴驔襕埯喍㔗欔橬䔇 Unix 变傴鄘嘪䫘䕩劯䔇锄锩庖严認婔䗹䩘滇崻佘庖㔗

啹婺喐埙幘埇傖劽濘䔇庺䯄婘 SQL 变傴麯冪橬婋麵䔇蓇彍鍴麂"name"滇嘷嬉螆䘞䔇昊婻埻麟䔇劉庖劥彍庖严废彖":name"婉嚔埻寡㔗嘖滇方螺套嘘嘹鄘埇傖䫘埉桩溹锄锩喐埙傖黾溵垄赆敪扵㔗埻麟䔇喐埙臺濘严劽臩套 ECPG 幋䌂䔇啯噖嚟 SQL 湺庖㔗䫘庯昄䂇䬺枕启䌂傋蘸扵䔇喐埙臺濘滇 PostgreSQL 欷匘啹溴嚔凚躘喾仕㔗

柊䴺严

psql 嘪䫘䔇柊䴺严埇傖湹扞嘹䔇塩喘躻垔幬㔗婬婻埻麟 PROMPT1, PROMPT2, PROMPT3 寙劆柟誄柊䴺严䔇崡蓗䔇庖严婾启䬹枪锄锩废彖㔗PROMPT1psql 臙挗婔婻桄变傴施嘪䫘䔇溼婩柊䴺严㔗PROMPT2 滇婘婔婻变傴膷噖橘写敘崔膷噖施(啹婺昖臵澇橬䫘婔婻彖埙䂷溘潡蔙嚘埙澇橬噿閺)滆䴺䔇柊䴺严㔗PROMPT3 婘嘹誊臯婔婻 SQL COPY 变傴启京写嘹婘䂽䆇婪髞噖螄嘘施嘪䫘㔗

䕩庫䔇柊䴺严埻麟䔇唚滇毬庖麵欷剄䔇鍴麂䵄彄婔婻䍆彖埙(%)㔗認施昊底噽垄䔇桺橸赆敪扵敪扵婺嘘䬷埡喿庯婋婔婻庖严㔗噾垔幬䔇敪扵滇

%M

昄扞康橉媇単噘䘋婂橺劉(婥五嘘劉)套悩誂毖滇锔誺 Unix 嘘喖毖庖誕臯䔇儌滇 [local] 潡蔙套悩 Unix 嘘喖毖庖婉滇䚡臏䔇䚺䩕嘉䘞儌滇 [local:/dir/name]

%m

昄扞康橉媇単䔇婂橺劉役寂丸婔婻䗹劯麵䔇鄘彖嬷婋䔇婩薪㔗潡蔙套悩滇锔誺 Unix 嘘喖毖庖誂毖儌滇 [local]

%>

昄扞康橉媇単溼婘冥劸䔇䆇埼埙

%n

昄扞康嚔臺䔇䫘潙劉㔗認婻唚䔇欷匘埇脘婘婔婻昄扞康嚔臺誺䘋婺啹婺 SET SESSION AUTHORIZATION 变傴蔯櫹埻㔗

%/

嘷嬉昄扞康劉䓄

%~

䌂嚚 %/ 嘖套悩昄扞康滇嘹䔇䚺䩕昄扞康膷庺滇濵敻亪 ~

%#

套悩嚔臺䫘潙滇昄扞康轙亓䫘潙嘪䫘 # 劥彍䫘 > 㔗認婻唚䔇欷匘埇脘婘婔婻昄扞康嚔臺誺䘋婺啹婺 SET SESSION AUTHORIZATION 变傴蔯櫹埻㔗

%R

凹庯 PROMPT1 锔婩滇 = 嘖滇套悩滇剘臯昇嚟彍滇 ^ 蔯套悩嚔臺婯昄扞康桺嚔(套悩 \connect 崌蘖埇脘埏䫘)彍滇 ! 㔗凹庯 PROMPT2 臖废彖赆 -, *, 婔婻剘嚘埙/埯嚘埙/䆯噄严(埡喿庯 psql 滇劥京写敘崔䔇膷噖昖臵澇橬䂽溵㔕溼婘婔婻 /* ... */ 濘麪麯㔕溼婘嚘埙潡蔙䆯噄严欷匘麯)傼敪㔗 凹庯 PROMPT3 臖废彖婉蓼麪潊傂嘘婩薪㔗

%x

庋媇䪽攕套悩婉婘庋媇庖麯彍滇婔婻䷺庖严婾套悩婘庋媇庖麯彍滇 * 套悩婘婔婻崌蘖䔇庋媇庖麯彍滇 ! 潡蔙方濘彴桺庋媇䪽攕施婺 ? (懫套澇橬誂毖)㔗

%digits

毺垔庖誗唚䔇庖严儖赆敪扵彄臖嘉䘞㔗

%:name:

psql 埻麟 name 䔇唚㔗埗黙埻麟償誗诙埡䂖誗㔗

%`command`

command 䔇膷庺䌂嚚庯锔婩䔇"埉勆埙"敪扵㔗

%[ ... %]

柊䴺埇傖寙劆䂽䆇毓彽庖严認底庖严埇傖櫹埻鵩謾㔕脯捇㔕柊䴺桺橸䔇鼯湚㔕䂽䆇他埼䔇湺鵻㔗婺庖螷 Readline 䔇臯䚡膏䬹攓溼䇞誊臯認底婉埇欷剄䔇毓彽庖严媙釂螆螇潊婉埇蓕䔇桹濘滇䫘 %[%] 寙啘垄傸㔗婘柊䴺严麯埇脘庺䯄認底婩薪䔇崔婻陉凹㔗冋套

testdb=> \set PROMPT1 '%[%033[1;33;40m%]%n@%/%R%[%033[0m%]%# '

䔇䂷悩滇婘 VT100 噚垹䔇埇滆䴺嘷謾䔇䂽䆇婪䔇婔婻垘嘷(1;)邏庘邇庖(33;40)㔗

髞噖 %% 埇傖婘柊䴺严麯某噖䍆彖埙㔗䚺䩕柊䴺严婺 '%/%R%# ' 䫘庯丸婔庯婻柊䴺严'>> ' 䫘庯丸婬婻柊䴺严㔗

㔊濘懟㔏認婻䬹攓滇傯 tcsh 啙庥準䔇㔗

变傴臯䚡膏

psql 婺庖䚡膏启演䘵变傴臯䔇桹冪櫇毕 Readline 启寖埾康㔗变傴寖埾婘 psql 锔庺䔇施唍躻媘媺庻婘 psql 劇媘䔇施唍媹蘘㔗誻櫇毕 Tab 臖阊儘䞇臖臖阊锂膏幽婉滇婔婻 SQL 彖悊単媙崺䔇㔗套悩啹昊底寘啹嘹婉塩渵 tab 臖阊埇傖檪婋麵庹臯櫆婘嘹䔇垽䕞嘘婋䔇 .inputrc 桺傽麯噿閺認婻䬹攓

$if psql
set disable-completion on
$endif

認婉滇 psql 蔯滇 Readline 䔇䬹攓埗蔄垄䔇桺懼诙埡敘崔䂖誗㔗

䯇嵄埻麟

PAGER

套悩昖臵䂷悩婘婔釕麯櫆婉婋闼幽垄傸赆麉垔劏彄認婻变傴㔗噩傋䔇唚滇 moreless 㔗䚺䩕唚滇广埄䕩噿䔇㔗埇傖䫘 \pset 变傴噿閺彖釕単㔗

PGDATABASE

䚺䩕誂毖䔇昄扞康

PGHOST
PGPORT
PGUSER

䚺䩕誂毖埗昄

PSQL_EDITOR
EDITOR
VISUAL

\e 变傴嘪䫘䔇䚡膏単㔗認底埻麟滇毬䙓婪麵䔇釺废演昖䔇螆䘞橔斷䔇橔噽嘪䫘㔗

SHELL

\! 变傴欓臯䔇变傴

TMPDIR

庻嗘婘施桺傽䔇䕞嘘㔗䚺䩕滇 /tmp

啹婺 psql 婘喙鄘嘪䫘 libpq 康欔傖欔橬 libpq 康䔇䯇嵄埻麟鄘埇傖赆 psql 臖彆㔗埗蓕誗29.12诙埡欔橬埻麟䔇彖臘㔗

桺傽

濘懟

Windows 䫘潙驔襕濘懟䔇婄桹

psql 滇傖婔䓉"毓彽埄庫䫘"䔇桹嚟彽嘩䔇㔗啹婺 Windows 毓彽埄他埼启係䂘噽垄鄘彖嘪䫘婉劯䔇䚡乕欔傖婘psql 麯嘪䫘 8 嘉庖严䔇施唍媙釂麺埡䬹枪䔇濘懟毻桘㔗套悩 psql 演敋彄婔婻橬閞鵻䔇毓彽埄傼乕釕闼幽垄婘劇媘䔇施唍嚔躥只嘹㔗襕媞櫹毓彽埄傼乕釕橬婴傽庋滇媙釂啔䔇

冋床

丸婔婻冋床暫䴺庖套嘘檪婔婻昖臵彖潊崔婻臯誕臯膷噖㔗濘懟柊䴺严䔇埻寡

testdb=> CREATE TABLE my_table (
testdb(>  first integer not null default 0,
testdb(>  second text)
testdb-> ;
CREATE TABLE

䯄婘喉䩋䩋臘垔幬

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

劯锔饡釕嬉誕
pg_restore婪婔亓reindexdb