psql 滇婔婻傖䂽䆇婺嘺䇔䔇 PostgreSQL 嬉䆇㔗垄噕螩嘹庴庐婄髞噖昖臵䇽劯檪垄傸埏庺䂍 PostgreSQL 喉滆䴺昖臵䔇䂷悩㔗埥崡膷噖埇傖準躻婔婻桺傽㔗誻橬垄柊冕庖婔底噄变傴启崔䓉䌂嚚 shell 䔇䬹攓準垂䯄幥喍臔橸傖埪凹崓麟傂媇䔇躻媘寡㔗
婘臂埡臯施劏湺庖膷庺欷剄欔橬喙垹㔗認婻锬釹婘臔橸崇䊖施懫庴庐昇嚟施敘橬䫘㔗認婻锬釹京昽庯螆䘞 ECHO 埻麟婺 all
彺扵婺麂凹阊膷庺昇嚟㔗䚺䩕膷庺昇嚟滇凹阊䔇㔗
弄滯 psql 儖欓臯婔溇昖臵庖严婾 command 䇽劯锔庺㔗認婔䗹婘 shell 臔橸麯冽橬䫘㔗
command 媙釂滇婔溇垯噘埇傖赆橉媇単彖悊䔇庖严婾(幘儌滇婉寙劆 psql 䬹橬䔇䬹攓)潡蔙滇婔婻埉桩溹变傴㔗認湙嘹儌婉嚔晙劽 SQL 启 psql 噄变傴㔗襕愿晙劽嘪䫘嘹埇傖檪庖严婾麉垔劏彄 psql 麯償認湙echo '\x \\ SELECT * FROM foo;' | psql (\\ 䫘庯锫嚔噄变傴)㔗
套悩变傴庖严婾寙劆崔婻 SQL 变傴闼幽傡傸儖婘婔婻庋媇麯崇䊖鍴麂婘庖严婾麯寙劆庖滯䇞䔇 BEGIN/COMMIT 变傴檪傡傸彖潊崔婻庋媇㔗認婻启傯 psql 䔇湺庖膷噖麯䂍垄准噙䕩劯庖严婾婉劯㔗
弄滯愿襕誂毖䔇昄扞康劉䓄㔗京昽庯婘变傴臯臯婪檪 dbname 弄滯婺丸婔婻麂锬釹埗昄㔗
檪欔橬埏锕䂍橉媇単䔇昖臵劯施幘啂滆彄湺庖膷庺㔗京昽庯檪埻麟 ECHO 螆䘞婺 queries
啂滆䫌 \d 启噽垄埉桩溹变傴䫘潊䔇垂鍙昖臵㔗嘹埇傖嘪䫘認婻变傴庥幹 psql 䔇喙鄘淉嘩㔗認京昽庯婘 psql 麯螆䘞埻麟 ECHO_HIDDEN
嘪䫘 filename 嘩婺变傴䔇臺埖溊蔯婉滇庴庐嚟臂噖昖臵㔗psql 儖婘崇䊖垯桺傽劯䂷溘㔗認婻锬釹婘冽崔桹麵京昽庯喙鄘变傴 \i
套悩 filename 滇 -(誂庖严)彍傯湺庖膷噖臂埡㔗
嘪䫘認婻锬釹婯嘪䫘 psql < filename 橬冞償䔇寺彆㔗锔婩婴蔙鄘啂毬䙓嘹鵇橘闼湙誊臯嘖滇嘪䫘 -f 欷嚔庖婔底冽喘䔇䬹攓懫套婥臯埙䔇髍臇媇敇㔗蔯婫嘪䫘認婻锬釹誻埇脘废償劇媘䔇嚔體㔗埥婔桹麵套悩嘹檪欔橬喙垹欋噖膷噖嘪䫘 shell 膷噖垔劏䔇桹嚟(䊖螺婪)脘媺臕䫘潊启嘹噾䂟冖彄䔇垯噘婔湙䔇膷庺㔗
嘪䫘 separator 嘩婺橻凹阊膷庺䔇嘘彖锫严㔗京昽庯 \pset fieldsep 潡 \f
毺垔溼婘誊臯橉媇単䔇婂橺劉㔗套悩婂橺劉傖桩溹嚔崘彍垄赆䫘嘩彄 Unix 嘘喖毖庖䔇虇冇㔗
欷嚔 HTML 湚嚟膷庺㔗京昽庯 \pset format html 潡 \H 变傴㔗
彖庺欔橬埇䫘䔇昄扞康䇽劯锔庺㔗噽垄麂誂毖锬釹儖赆媘䘖㔗䌂嚚庯喙鄘变傴 \list
鍴庖溼婩䔇膷庺溊幋崡檪欔橬昖臵膷庺螄嘘彄桺傽 filename
儖欔橬昖臵膷庺麉垔劏彄桺傽 filename 㔗認婻锬釹京昽庯 \o 变傴㔗
毺垔橉媇単冥劸䔇 TCP 䆇埼潡橸婄 Unix 嘘喖毖庖桺傽䔇欷匘㔗䚺䩕嘪䫘䯇嵄埻麟 PGPORT 䔇唚套悩澇橬螆䘞䔇臺彍嘪䫘䚡臏施弄滯䔇䆇埼(锔婩滇 5432)㔗
噕螩嘹婘变傴臯婪傖 \pset 䔇鼯湚螆䘞欷剄锬釹㔗襕濘懟䔇滇嘹婘認麯媙釂䫘京埙蔯婉滇䷺湚彖嬾劉䓄启唚㔗啹溴襕檪膷庺湚嚟螆䘞婺 LaTeX 嘹埇傖显噖 -P format=latex
垬麍婄欓臯崇䊖傂媇㔗䚺䩕施 psql 儖欷剄渵誯启螩崔噽垄膷庺媇敇㔗套悩嘪䫘庖溴锬釹認底鄘婉嚔庺䯄㔗認婘启 -c 锬釹婔蕙嘪䫘施冽橬昽㔗婘 psql 麯埇傖锔誺螆䘞 QUIET 埻麟垂䯄劯湙昽悩㔗
嘪䫘 separator 啔婺麂凹阊膷庺䔇螄嘘彖锫严㔗京昽庯 \pset recordsep 变傴㔗
剘準昇嚟誊臯㔗懟叿五懟婻昖臵婘埏冔橉媇単幋嬉鄘襕柊䴺䫘潙䫘認婻锬釹幘埇傖埡潽欓臯㔗溴锬釹婂襕䫘庯脄臘臔橸㔗
剘臯誊臯昇嚟認施懟婻变傴鄘儖䫌扵臯严䂷溘償彖埙闼湙㔗
㔊濘懟㔏認婻昇嚟滇䂍闼底应毕襕嘪䫘認婻䬹攓䔇庺媺䘍䔇婉隷媌嘹認幽䫘㔗垂鍙婪套悩嘹婘婔臯麯晙劽嘪䫘 SQL 启噄变傴欓臯䔇釺废凹婉䖘䂄䔇䫘潙蔯蘔幽婉攂滇橙捄䔇㔗
噿閺欷剄彖劉䓄启䂷悩臯螇昄臔濘京媇敇㔗京昽庯 \t 变傴㔗
噕螩嘹弄滯櫆婘 HTML table
湺了麯䔇锬釹㔗埗黙 \pset 诙埡䂖誗㔗
嚺彽 psql 婘启昄扞康誂毖幋嬉柊䴺膷噖䫘潙劉启埼傴㔗
認婻锬釹噾䂟庘嚄庖啹婺垄婘楗媕婪橬暟昂㔗柊䴺膷噖麂䚺䩕䫘潙劉启柊䴺膷噖橉媇単襕挗䔇埼傴滇垯噘婴乕庋㔗隷媌嘹䫘 -U 启 -W 锬釹埡傼垄㔗
傖䫘潙 username 傼敪䚺䩕䫘潙婯昄扞康誂毖㔗嘷䇽嘹媙釂橬認幽啔䔇溄鍊㔗
償喙鄘变傴 \set 闼湙誕臯婔渇埻麟彖陉㔗濘懟套悩橬埻麟劉启唚䔇臺嘹媙釂婘变傴臯婪䫘京埙彖锫垄傸㔗寂毬京埙彍麉䘞埻麟㔗襕螆䘞婔婻澇橬唚䔇埻麟埇傖媺䘍京埙嘖滇婉毺垔唚㔗認婻彖陉滇婘劇媘幋彺誕臯䔇欔傖婺喙鄘嘪䫘蔯媺䘍䔇埻麟埇脘赆喉渇襖䕡㔗
欷剄 psql 䬽橸媇敇䇽劯锔庺㔗
嚺彽 psql 婘婯婔婻昄扞康誂毖嬉柊䴺膷噖埼傴㔗
套悩橉媇単襕挗埼傴螴臕psql 儖躻媘滆䴺埼傴柊䴺严㔗婉誺䕞嬉滇劥驔襕膷噖埼傴䔇彴桺幽婉垯噘埇麹啹溴䫘認婻锬釹嚺彽滆䴺認婻柊䴺严㔗套悩澇橬埏庺埼傴柊䴺严蔯橉媇単襕挗埼傴螴臕闼幽誂毖嚕商儖崌蘖㔗
認婻锬釹儖婘昘婻嚔臺誺䘋婺橬昽剿嘪嘹䫘噄变傴 \connect 櫹埻庖欔誂毖䔇昄扞康㔗
欷嚔欷匘臘湚嚟昇嚟㔗京昽庯 \x 变傴㔗
婉臂埡劇媘桺傽(係䂘评啘䔇 psqlrc 潡蔙嘹躻噌䔇 ~/.psqlrc 鄘婉臂埡)㔗
嘷 psql 嘪䫘 -f 锬釹欓臯臔橸施嘪䫘認婻锬釹儖凚躘婘臔橸䔇嚔崘启䂷儆彖彆媹婪 BEGIN/COMMIT 準檪昘婻臔橸嘷嘩婔婻庋媇欓臯㔗認儖媺臕臖臔橸襕幽垯噘欓臯潊媘襕幽婉库䫘傂嘘嘌巉㔗
套悩婘臔橸婺噾䂟嘪䫘庖 BEGIN, COMMIT, ROLLBACK 闼幽臖锬釹儖婉嚔冖彄橘橕䔇昽悩㔗劯湙套悩臔橸婺寙劆傂嘘婉脘婘庋媇庖喙鄘嘪䫘䔇变傴嘪䫘認婻锬釹儖凚躘認湙䔇变傴欓臯崌蘖嘷䇽昘婻庋媇庥儖崌蘖㔗
滆䴺噿庯 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 儖誫啂婔婻髍臇幽锔庺㔗
锔婩䪽喕婋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 麯膷噖䔇傂嘘傖婉婥嚘埙䔇埉桩溹嚔崘䔇婩薪鄘滇 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 变傴埇傖躻䫌䔇婘婔臯麯麵晙劽㔗嘖滇婘傂嘘愙喕婋婔溇噄变傴䔇埗昄婉脘傽䂺轙誺臯儆㔗
婋麵滇噾垔幬䔇噄变傴
套悩䕞嬉䔇臘膷庺湚嚟滇婉凹阊䔇彍彺扵潊凹阊䔇㔗套悩滇凹阊䔇彍彺扵潊婉凹阊㔗認溇变傴滇婺庖劏劯噚垹㔗埗黙 \pset 诙埡婔婻敘锔䫘䔇蓼喿桹濘㔗
檪嘷嬉噖嘩䕞嘘櫹埻彄 directory 㔗澇橬埗昄彍滇櫹埻彄嘷嬉䫘潙䔇垽䕞嘘㔗
㔊柊䴺㔏嘪䫘 \!pwd 欷剄庺嘷嬉噖嘩䕞嘘
檪溼婘欷剄䔇臘䔇湺鵻螆䘞婺婔婻昖臵䔇䂷悩潡蔙埡潽認湙䔇螆䘞㔗認溇变傴京昽庯 \pset title title 㔗認溇变傴䔇劉䓄溊庯"caption"啹婺傖嬉埻滇䫘庯婘婔婻 HTML 臘湚麯麵螆䘞湺鵻㔗
婯婔婻桄䔇昄扞康傺䆋婔婻誂毖嘪䫘/婉䫘婔婻䫘潙劉㔗嬉麵䔇誂毖儖噿閺㔗套悩 dbname, username, host, port 赆䩕䘖潡滇 - 闼幽儌嘪䫘婪渇誂毖麯麵䔇唚㔗 套悩幋嬉澇橬鷆毖彍嘪䫘 libpq 䔇䚺䩕唚㔗
套悩誂毖崌蘖(䫘潙劉髍㔕螪閞赆拐䂺京)闼幽嘷 psql 崇庯庴庐昇嚟施儖媺䘍嬉麵䔇誂毖㔗套悩誊臯䔇滇麂庴庐䔇臔橸崇䊖嚔鷸婪啩溵幽誫啂婔婻髍臇㔗螆䘞認湙䔇寺彆婔桹麵滇婺䫘潙嘪䫘桹冪蔄荏埥婔桹麵幘婺庖媺臕臔橸婉嚔䵄噓淉嘩庖髍臇䔇昄扞康䔇垬噘橺彽蔄荏㔗
欓臯嬉䆇(垵潙䆇)拙蘺㔗認滇婔婻誊臯 SQL COPY 变傴䔇淉嘩婉劯䔇滇橉媇単婘臂喍毺滯䔇桺傽蔯 psql 臂喍桺傽幽嘩婺橸婄䔇桺傽係䂘启橉媇単幋閘䔇虿溪埡庺潡喍噖昄扞㔗認懟叿五桺傽螪閞攓启溄鍊鄘滇橸婄䫘潙䔇蔯婉滇橉媇単䔇啹溴婉驔襕 SQL 轙亓䫘潙溄鍊㔗
認溇变傴䔇臺濘滇昇拘 SQL COPY 变傴䔇㔗襕濘懟䔇滇啹溴婥準婔底庫䫘庯 \copy 变傴䔇䬹枪彖悊蓇彍(儴噽滇埻麟敪扵蓇彍启埉桩溹傼扵蓇彍)儖婉蕙嘩䫘㔗
\copy ... from stdin | to stdout 彖彆嘺庯变傴膷噖启膷庺誕臯臂/喍㔗欔橬臯鄘傯埏庺变傴䔇劯婔婻溊臂埡䕘彄臂彄庖 \. 潡蔙敕膆彄 EOF 㔗膷庺埏锕彄启变傴膷庺䕩劯䔇嘉䘞㔗襕傯 psql 䔇湺庖膷噖潡蔙膷庺臂/喍埇傖嘪䫘 pstdin 潡 pstdout 㔗認婻锬釹䫘庯檪启 SQL 臔橸啯婘婔蕙䔇桺傽准噙臘冽橬䫘㔗
㔊柊䴺㔏 溴淉嘩婉償 SQL COPY 变傴認湙醻昽啹婺欔橬昄扞媙釂锔誺垵潙䆇/橉媇単誂毖㔗凹庯崓昄扞麟䔇淉嘩SQL 变傴䔇桹濘敘埇臯㔗
滆䴺 PostgreSQL 䔇䬽溄启䬽橸媇敇㔗
凹庯懟婻对陉 pattern 䔇噿係(臘㔕蓖商㔕䘵嚘㔕废彖)滆䴺欔橬彖㔕垄傸䔇䌂傋㔕臘䷺閘(套悩婉滇䚺䩕䔇)启傂嘘䬹枪匂攓(臩套 NOT NULL 潡䚺䩕京埻襕庻婘)㔗嫇婔亥溘䕩噿䔇䘵嚘㔕蓇彍㔕亥溘㔕蓥埏単幘劯湙滆䴺庺準㔗套悩噿係滇婔婻蓖商誻滆䴺蓖商䔇垔幬㔗"对陉昇嚟"婘婋麵垔幬㔗
傯 \d+ 準䔇变傴幘滇婔湙䔇埻婉誺滆䴺敘崔媇敇傂嘘婯臘䔇彖噿蕫䔇濘麪幘鄘嚔滆䴺誻橬儌滇臘婺庺䯄䔇 OID 㔗
㔊濘懟㔏套悩套悩婉婥傂嘘 pattern 脄䫘 \d 闼幽京昽庯 \dtvs 儖滆䴺婔婻欔橬臘蓖商启废彖䔇彖臘㔗認垯噘滇庺庯桹冪䔇蔄荏㔗
彖庺欔橬埇䫘䔇蕔镖庘昄傖埪垄傸淉嘩䔇昄扞䌂傋㔗套悩弄滯庖 pattern 闼幽埻滆䴺对陉(溼彍臘膆嚟)䔇蕔镖庘昄㔗
彖庺欔橬埇䫘䔇臘䷺閘㔗套悩弄滯庖 pattern 闼幽埻滆䴺闼底对陉昇嚟䔇臘䷺閘㔗套悩婘变傴劉婪鍇媹庖 + 闼幽懟婻凹茇鄘启婯幋䕩噿䔇溄鍊婔蕙彖庺㔗
彖庺欔橬庖严镖幋閘䔇埇䫘蘸扵㔗套悩弄滯庖 pattern 彍埻彖庺闼底对陉昇嚟䔇蘸扵㔗
彖庺欔橬䌂傋蘸扵㔗
滆䴺欔橬对陉 pattern 䔇柟誄套悩澇橬䂍庺埗昄滆䴺欔橬埇蓖凹茇㔗嘖滇婉䞇支湙埻橬闼底橬柟誄喙垹䔇凹茇欉滆䴺庺準㔗"凹茇"寙拸蕔镖㔕庘昄㔕淉嘩严㔕䌂傋㔕噿係(臘㔕蓖商㔕䘵嚘㔕废彖㔕崓凹茇)㔕蓇彍㔕蓥埏単㔗冋套
=> \dd version Object descriptions Schema | Name | Object | Description ------------+---------+----------+--------------------------- pg_catalog | version | function | PostgreSQL version string (1 row)
埇傖䫘 COMMENT 变傴䫘潊凹茇䔇柟誄㔗
彖庺欔橬埇䫘嘘㔗套悩弄滯庖 pattern 闼幽埻滆䴺对陉䔇嘘㔗
彖庺欔橬埇䫘庘昄傖埪垄傸䔇埗昄启誫啂䔇昄扞䌂傋㔗套悩弄滯庖 pattern 闼幽埻滆䴺对陉(溼彍臘膆嚟)䔇庘昄㔗套悩嘪䫘庖 \df+ 䔇嘵嚟懟婻庘昄䔇鍇媹媇敇寙拸臺蘔启柟誄幘嚔滆䴺庺準㔗
㔊濘懟㔏襕昖欆毖埖潡蔙誫啂䬹垔䌂傋䔇庘昄嘪䫘嘹䔇彖釕単抩䘵媘脘準悔媘 \df 䔇膷庺㔗
婺庖废儏晙幌\df 幽婉滆䴺昄扞䌂傋䔇膷噖膷庺庘昄㔗認湙滇锔誺媘䘖闼底毖埖潡蔙誫啂䌂傋 cstring 䔇庘昄垂䯄䔇㔗
彖庺欔橬昄扞康蓐謾㔗套悩弄滯庖 pattern 闼幽埻滆䴺闼底对陉昇嚟䔇劉庖㔗認溇变傴垂鍙婪京庯 \du
認婉滇垂鍙䔇变傴劉䓄庖應 i, s, t, v, S 彖彆傼臘䘵嚘(index)㔕废彖(sequence)㔕臘(table)㔕蓖商(view)㔕係䂘臘(system table)㔗㔗嘹埇傖傖傂懟釺废弄滯傂懟潡蔙欔橬認底庖應诙冖認底凹茇䔇婔婻彖臘㔗庖應 S 檪彖臘鍊彽庯係䂘凹茇套悩澇橬 S 彍埻滆䴺麂係䂘凹茇㔗套悩婘变傴劉婪鍇媹庖 + 闼幽誻嚔彖庺启懟婻凹茇䕩噿蕫䔇柟誄套悩橬䔇臺㔗
套悩弄滯庖 pattern 闼幽埻彖庺对陉昇嚟䔇凹茇㔗
\lo_list 䔇彆劉滆䴺婔婻崓凹茇䔇彖臘㔗
彖庺欔橬埇䫘昇嚟(劉庖䷺閘)㔗套悩弄滯庖 pattern 闼幽埻彖庺对陉昇嚟䔇昇嚟劉㔗婉滆䴺麂橸婄䔇婘施昇嚟㔗套悩婘变傴劉婪鍇媹庖 + 闼幽懟婻凹茇鄘启婯幋䕩噿䔇溄鍊启濘麪婔蕙彖庺(套悩橬䔇臺)㔗
彖庺欔橬埇䫘淉嘩严傖埪垄傸䔇淉嘩昄启誫啂䔇昄扞䌂傋㔗套悩弄滯庖 pattern 闼幽埻滆䴺对陉昇嚟䔇淉嘩严㔗
䫘潊婔彖埇䫘䔇臘启垄傸䕩噿䔇溄鍊㔗套悩弄滯庖 pattern 闼幽埻彖庺劉庖对陉昇嚟䔇臘㔗
彖庺欔橬昄扞䌂傋潡埻滆䴺闼底对陉 pattern 䔇㔗認溇变傴䔇 \dT+ 嘵嚟滆䴺敘崔媇敇㔗
彖庺欔橬噾陉䘞蓐謾潡蔙埻彖庺闼底对陉 pattern 䔇蓐謾㔗
套悩弄滯庖 filename 彍䚡膏溴桺傽幽婫婘䚡膏単锔庺劯儖噽喙垹拙蘺啂昖臵䚷喾寺㔗套悩澇橬䂍庺溴埗昄彍檪嘷嬉昖臵䚷喾寺喙垹拙蘺彄婔婻婘施桺傽䇽劯傖䕩劯桹嚟䚡膏㔗
䇽劯湹扞婔轸䔇 psql 蓇彍麉桄彖悊昖臵䚷喾寺認施昘婻䚷喾寺嘷嘩婔婻剘臯啹溴嘹方濘䫘認婻桹濘彽嘩臔橸(䫘 \i)㔗認誻懟叿五套悩臖昖臵傖彖埙䂷儆(潡蔙寙劆彖埙)垄儌嚔鷸婪赆欓臯㔗劥彍垄埻滇婘昖臵䚷喾寺麯京写㔗
㔊柊䴺㔏 psql 傖 PSQL_EDITOR, EDITOR, VISUAL 釺废抩䘵䯇嵄埻麟昖欆襕䫘彄巻婻䚡膏単㔗套悩婪麵䔇鄘澇橬螆䘞闼幽婘 Unix 係䂘婪嘪䫘 vi 蔯婘 Windows 係䂘婪䫘 notepad.exe
劏湺庖膷庺欷剄埗昄䫘婔婻䷺湚彖锫幽婫橔劯虘五婔婻桄臯㔗認婻䬹攓婘滆䴺臔橸䔇膷庺施嚔橬䫘㔗冋套
=> \echo `date` Tue Oct 26 21:40:57 CEST 1999
套悩丸婔婻埗昄滇婔婻方嚘埙䔇 -n 闼幽婉嚔喍庺䂷儆䔇桄臯㔗
㔊柊䴺㔏套悩嘪䫘 \o 变傴麉垔劏昖臵䔇膷庺嘹埇脘嚔䫘 \qecho 埡傼認溇变傴㔗
螆䘞垵潙䆇庖严䚡乕桹嚟㔗婉婥埗昄施認溇变傴滆䴺嘷嬉䔇䚡乕桹嚟㔗
婺婉凹阊䔇昖臵膷庺螆䘞嘘彖锫严㔗䚺䩕施滇䆡溇(|)㔗埗黙 \pset 诙埡螆䘞膷庺锬釹䔇锔䫘桹濘㔗
檪嘷嬉䔇昖臵膷噖䚷喾寺䔇喙垹埏锕䂍橉媇単幽婫檪昖臵䔇膷庺庻嗘彄埇锬䔇 filename 潡蔙檪膷庺麉垔劏彄婔婻䋸䆋䔇欓臯 command 䔇 Unix shell 㔗剘䋸婔婻 \g 垂鍙婪京昽庯婔婻彖埙㔗婔婻婥橬埗昄䔇 \g 滇"婔渇攓"䔇 \o 变傴䔇傼䫘巕㔗
䂍庺毺垔 SQL 变傴䔇臺濘婞媷㔗套悩澇橬䂍庺 command 闼幽 psql 儖彖庺埇诙冖臺濘婞媷䔇欔橬变傴㔗套悩 command 滇婔婻滘埙(*) 彍滆䴺欔橬 SQL 变傴䔇臺濘婞媷㔗
㔊濘懟㔏婺䞔寡庂髞寙劆崔婻剘庖䔇变傴婉驔襕嚘蕙㔗啹溴髞噖 \help alter table 滇溼䇞䔇㔗
欷嚔 HTML 昖臵膷庺湚嚟㔗套悩 HTML 湚嚟噾䂟欷嚔彍彺扵啂䚺䩕䔇凹阊䔇桺橸湚嚟㔗認婻变傴滇婺庖噚垹启桹冪埗黙 \pset 诙埡螆䘞噽垄膷庺锬釹䔇喙垹㔗
傯桺傽 filename 婺臂埡幽檪噽喙垹嘷嘩傯髞䕻膷噖䔇闼湙欓臯昖臵㔗
㔊濘懟㔏套悩嘹愿婘匟幘婪䩋彄臂噖䔇臯儌媙釂凹欔橬臯儖埻麟 ECHO 螆䘞婺 all
彖庺橉媇単婪欔橬昄扞康䔇劉庖启垄傸䔇欔橬蔙傖埪庖严镖䚡乕㔗婘变傴劉䓄劯麵媹婔婻 + 誻埇傖䩋彄凹昄扞康䔇柟誄㔗
傯昄扞康麯臂埡 OID 婺 loid 䔇崓凹茇幽檪垄喍彄 filename 麯㔗濘懟認婻媘脘婯橉媇単庘昄 lo_export
橬底冞償䔇寺彆劯蔙誊臯施婥五誊臯昄扞康橉媇単䔇䫘潙溄鍊蔯婫滇婘橉媇単䔇桺傽係䂘婪㔗
㔊柊䴺㔏嘪䫘 \lo_list 昖䩋崓凹茇䔇 OID 㔗
檪桺傽庻嗘婺婔婻 PostgreSQL 崓凹茇㔗埇傖婥五婔婻臖凹茇䔇濘蓼锬釹㔗冋套
foo=> \lo_import '/home/peter/pictures/photo.xcf' 'a picture of me' lo_import 152801
巉庫臘滯溴崓凹茇冖彄婔婻凹茇湺臖 152801 套悩嘹誻愿螪閞臖凹茇儌庫臖檪認婻凹茇湺臖螄嘟㔗啹溴傺螞攂滇䂍懟婻凹茇噿蕫婔婻庺䌂埇臂䔇濘蓼㔗闼湙儌埇傖䫘 \lo_list 变傴䩋彄認底濘蓼㔗
濘懟認溇变傴婯橉媇単䆇䔇 lo_import
橬婔底寺彆啹婺認溇变傴滇橸婄䫘潙婘橸婄桺傽係䂘婪淉嘩蔯婉滇傖橉媇単䫘潙婘橉媇単桺傽係䂘婪淉嘩㔗
滆䴺婔婻䕞嬉庻嗘婘臖昄扞康麯䔇欔橬 PostgreSQL 崓凹茇启垄傸䔇欔橬蔙䔇彖臘㔗
傯昄扞康麯役鍴 OID 婺 loid 䔇崓凹茇㔗
㔊柊䴺㔏嘪䫘 \lo_list 昖欆崓凹茇䔇 OID 㔗
檪劯麵䔇昖臵䂷悩媺庻彄桺傽 filename 麯潡蔙檪劯麵䔇昖臵䂷悩麉垔劏彄婔婻䋸䆋欓臯 command 䔇 Unix shell 㔗套悩澇橬弄滯埗昄昖臵膷庺儖赆麉䘞婺湺庖膷庺㔗
"昖臵䂷悩"寙拸欔橬臘变傴巉庫启傯昄扞康橉媇単準䔇柊䴺劯湙誻橬劇䓉劇湙昖臵昄扞康䔇埉桩溹变傴䔇膷庺(套 \d)嘖滇澇橬髍臇媇敇㔗
㔊柊䴺㔏襕䫘桺橸彖昼昖臵䂷悩幋閘䔇膷庺䫘 \qecho
欷剄嘷嬉昖臵䚷喾寺彄湺庖膷庺㔗
敘櫹毺垔䫘潙䔇埼傴䚺䩕婺嘷嬉䫘潙㔗臖变傴儖柊䴺埼傴膷噖䇽劯儖媹凖誺䔇埼傴嘪䫘 ALTER ROLE 幋䌂䔇变傴埏锕䂍橉媇単㔗認埇傖媺臕桄埼傴婉嚔傖滯桺嘵嚟庺䯄婘变傴寖埾㔕橉媇単斖媖㔕潡噽傡傔幽婄桹㔗
認溇变傴螆䘞嘌巉昖臵䂷悩臘膷庺䔇锬釹㔗parameter 柟誄襕螆䘞䔇锬釹滇巻婔婻㔗value 䔇臺懟幘埡喿庯垄㔗
埇脄誗䔇欷剄锬釹橬
螆䘞膷庺湚嚟婺 unaligned, aligned, html, latex, troff-ms 幋婔㔗噕螩嘪䫘嫇婔䚷喍認幘懟叿五婔婻庖應儌崘庖㔗
"Unaligned"(婉凹阊)檪婔溇螄嘘䔇欔橬庖枕鄘膷庺彄婔臯䫘嘷嬉橬昽䔇嘘彖锫严彖锫㔗認婂襕䫘庯䫘潊闼底襕赆噽垄䘋废臂埡䔇膷庺(彽臘严彖锫㔕锖埙彖锫)㔗"Aligned"(凹阊)昇嚟滇湺庖䔇庺䌂埇臂䔇湚嚟寡喘庖䔇桺橸膷庺幘滇䚺䩕㔗"HTML"启"LaTeX"昇嚟檪臘膷庺婺埇䫘庯桺懼麯䔇凹庫湺螄臺蘔㔗垄傸誻婉滇垯昘䔇桺懼埇脘凹庯 HTML 埻寡誻婉滇崻崓嘖滇婘 LaTeX 麯嘹媙釂橬婔婻垯昘䔇桺懼寙輙単㔗
丸庯婻埗昄媙釂滇婔婻昄庖㔗锔婩昄庖轪崓臘儌橬轪垘䔇膹䘯启轪崔䔇亪嘖滇認婻埗昄埡喿庯垂鍙䔇湚嚟㔗婘 HTML 昇嚟麯認婻埗昄嚔䕘毖䪂臏潊 border=... 匂攓婘噽垄䔇昇嚟麯埻橬唚 0(方膹䘯)㔕1(喙鄘彖锫亪)㔕2(臘懖悽)橬懟幬㔗
婘溼婩启欷匘湚嚟幋閘彺扵㔗嘷欷嚔欷匘湚嚟施昖臵䂷悩䫘婴彖滆䴺庖枕劉䓄婘噥㔕昄扞婘埿㔗認婻昇嚟婘昄扞方濘櫆誕锔婩䔇"愘广"昇嚟䔇匟幘施冽橬䫘㔗
欔橬啕䓉膷庺昇嚟鄘櫇毕欷匘湚嚟㔗
丸庯婻埗昄滇婔婻庖严婾䫘傖傼臘庖枕䔇唚婺 null 施䔇欷剄膷庺㔗䚺䩕滇傔幽鄘婉欷認湙冽垹滷启䌂嚚婔婻䷺庖严婾晙晖㔗啹溴埇脘锬拷 \pset null '(null)'
弄滯婘麂凹阊昇嚟施䔇嘘彖锫严㔗認湙儌埇傖录傺噽垄䘋废婯橕䔇彽臘严潡锖埙彖锫䔇膷庺㔗襕螆䘞彽臘严嘘彖锫严髞噖 \pset fieldsep '\t' 㔗䚺䩕嘘彖锫严滇 '|' (䆡溇严)㔗
彺扵䚺䩕臔濘(x rows)
彺扵彖锫償昄䗹噥膹䔇昄唚䔇寺嘘䕩噿䔇彖䂇严埙㔗垄誻欷嚔寺嘘䕩噿䔇償昄䗹㔗
弄滯婘麂凹阊昇嚟施䔇螄嘘彖锫严㔗䚺䩕滇扵臯严㔗
婘垯噘滆䴺启埻滆䴺螄嘘幋閘彺扵㔗垯噘滆䴺儖滆䴺償彖崘㔕湺鵻㔕劇䓉臔濘京媇敇㔗婘認婻昇嚟婋埻滆䴺螄嘘昇嚟儖埻滆䴺垂鍙䔇臘昄扞㔗
婺傂嘘锟劯欷剄䔇臘螆䘞湺鵻㔗認婻埗昄埇傖䫘庯䂍嘹䔇膷庺婔婻柟誄攓湺螄㔗套悩婉婥埗昄麉䘞湺鵻㔗
噕螩嘹弄滯櫆婘 HTML table
湺了麯䔇傂嘘匂攓(冋套 cellpadding 潡 bgcolor)㔗濘懟嘹埇脘婉驔襕婘認麯弄滯 border 啹婺噾䂟婘 \pset border 麯䫘誺庖㔗
毓彽昖臵启 psql 婞媷膷庺䔇彖釕単㔗套悩螆䘞庖䯇嵄埻麟 PAGER 闼幽膷庺赆垔劏彄毺垔䘋废劥彍嘪䫘係䂘䚺䩕(懫套 more)㔗
套悩噿閺庖彖釕単彍婉嘪䫘垄套悩欷嚔庖䘋废埻婘驔襕䔇施唍嘪䫘彖釕単幘儌滇臘膷庺滇彄䂽䆇蔯婫闼婻臘冽埇脘方濘婯匟幘对陉㔗psql 婘喿垔嘘施彖釕施婉滇冽垯䆯㔗\pset pager 嚔噿彖釕単㔗幘埇傖檪彖釕単螆䘞婺 always 凚躘婘傂嘘愙喕婋鄘嘪䫘彖釕単㔗
埇傖婘冋床償誗䩋彄認底婉劯湚嚟膷庺䔇䴺冋㔗
㔊柊䴺㔏橬冽崔䫘庯 \pset 䔇媆锘变傴㔗埗黙 \a, \C, \H, \t, \T, \x
㔊濘懟㔏方埗昄誊臯 \pset 滇髍臇䔇㔗傖劯認湙脄䫘儖滆䴺嘷嬉欷剄锬釹䪽攕㔗
锔庺 psql 䘋废㔗
認溇变傴京昽庯 \echo 寺彆滇欔橬膷庺儖喍噖䫌 \o 螆䘞䔇膷庺锔長㔗
麉䘞(橙䷺)昖臵䚷喾寺
儖变傴臯寖埾欷剄庺潡滇庻櫆彄 filename 㔗套悩䩕䘖彍膷庺彄湺庖膷庺㔗認婻锬釹埻橬婘 psql 陉䘞潊嘪䫘 GNU Readline 康劯欉䫘昽㔗
螆䘞喙鄘埻麟 name 婺 value 潡蔙套悩䂍庺庖崔庯婔婻唚螆䘞婺欔橬認底唚䔇誂毖䂷悩㔗套悩澇橬䂍庺丸庯婻埗昄闼幽埻螆埻麟婉螆唚㔗襕麉䘞婔婻埻麟嘪䫘 \unset 变傴㔗
橬昽䔇埻麟劉埇傖寙劆庖严昄庖启婋彐亪㔗埗黙婋麵䔇埻麟诙埡䂖誗㔗
儘䞇嘹埇傖螆䘞傂嘘埻麟婺傂懟唚psql 凹婔底埻麟䬹枪凹写㔗垄傸婘噿庯埻麟䔇償誗麯麵橬桺懼㔗
㔊濘懟㔏認溇变傴启 SQL 变傴 SET 滇垯噘婉婔湙䔇㔗
彺扵膷庺䔇庖枕劉䔇媇敇崘启臯螄昄臔濘㔗認溇变傴京昽庯 \pset tuples_only 柊冕垄婂襕婺庖桹冪㔗
噕螩嘹婘嘪䫘 HTML 膷庺昇嚟施弄滯櫆婘 table
湺螄麯䔇匂攓㔗認溇变傴京昽庯 \pset tableattr table_options
傖懆䓐婺剘嘉滆䴺懟溇 SQL 臺埖䔇蔖施㔗
儖嘷嬉昖臵䚷喾寺膷庺彄桺傽 filename 潡蔙麉垔劏彄 Unix 变傴 command
彺扵欷匘臯湚嚟㔗京昽庯 \pset expanded
䫘潊婔婻婥橬螪閞溄鍊彖臘䔇昄扞康婺欔橬臘㔕蓖商㔕废彖䔇彖臘㔗套悩䂍庺傂嘘 pattern 彍赆嘷潊婔婻溼彍臘膆嚟埻滆䴺对陉䔇臘㔕蓖商㔕废彖㔗
認滇 \dp (滆䴺溄鍊)䔇彆劉㔗
誫啂彄婔婻剘䋸䔇 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 䬹枪䕩写㔗垄傸滇婔底锬釹螆䘞認底锬釹婘誊臯施埇傖锔誺櫹埻埻麟䔇唚潡蔙櫹埻婔底庫䫘䔇臘䯄䪽攕蔯櫹埻㔗儘䞇嘹埇傖檪認底埻麟䫘庯噽垄䫘锫嘖滇婉隷媌認幽啔啹婺䘋废䔇䬹攓埇脘嚔埻冖麂婩喺攻㔗锔婩欔橬䬹枪凹写䔇埻麟鄘滇䫌崓喍庖應䂇潊(埇脘誻橬昄庖启婋彐亪)㔗婺庖媺臕启橻準䔇橔崓鍊庥䔇噚垹攓臙镪噉嘪䫘認湙䔇埻麟㔗婋麵滇婔婻欔橬䬹枪凹写䔇埻麟彖臘㔗
套悩滇 on(䚺䩕)闼幽懟婻 SQL 变傴鄘婘潊媘垯潊劯躻媘柊庴㔗襕毘誘認䓉昇嚟婋䔇柊庴嘹媙釂膷噖婔婻 BEGIN 潡 START TRANSACTION 变傴㔗套悩滇 off 潡蔙橻螆䘞SQL 变傴婉嚔柊庴䕘彄嘹滯䇞婄埏庺 COMMIT 潡 END 㔗噿閺躻媘柊庴䔇昇嚟滇锔誺婺嘹滯䇞埏庺婔婻 BEGIN 垂䯄䔇垄滇櫆婘傂嘘儔橻婘婔婻庋媇庖婺幽婫躻噌婉滇 BEGIN 潡噽垄庋媇毓彽变傴幘婉滇闼底婉脘婘庋媇庖麯欓臯䔇变傴(懫套 VACUUM)䔇嬉麵㔗
㔊濘懟㔏婘噿閺躻媘柊庴䔇昇嚟婋嘹媙釂滯䇞櫆嚄傂嘘崌蘖䔇庋媇桹濘滇欓臯 ABORT 潡 ROLLBACK 㔗誻襕濘懟套悩嘹婉柊庴儌锔庺嚔臺欔啔䔇噖嘩嚔婵崌㔗
㔊濘懟㔏欷嚔躻媘柊庴滇 PostgreSQL 䔇嚹䂘臯婺嘖滇噿閺躻媘柊庴敘毖誏 SQL 蓇评㔗嘹埇傖婘係䂘评啘䔇 psqlrc 潡 ~/.psqlrc 桺傽婺噿閺躻媘柊庴㔗
溼婘誂毖五䔇昄扞康劉䓄㔗懟渇婯婔婻昄扞康蕫䂷鄘嚔螆䘞認婻唚(寙拸䘋废劇媘)嘖滇埇傖役鍴㔗
套悩螆婺 all 闼幽準躻髞䕻潡臔橸䔇欔橬膷噖臯婘彖悊潡欓臯嬉鄘啂滆彄湺庖膷庺㔗嘪䫘 -a 锬釹弄滯婘䘋废劇媘施儌邻螴認湙啔㔗套悩螆䘞婺 queries 闼幽 psql 埻滇婘昖臵埏锕䂍橉媇単幋嬉欷剄庺準㔗垂䯄認婻媘脘䔇变傴臯锬釹滇 -e
嘷螆䘞庖認婻埻麟幽婫婔婻埉桩溹变傴昖臵昄扞康施饡噽滆䴺昖臵㔗認湙嘹埇傖庥幹 PostgreSQL 喙鄘䔇婩薪幽婫婘嘹躻噌䔇䘋废麯柊冕䌂嚚媘脘㔗襕婘䘋废婔蕙媘䔇施唍儌劇䫘認婻臯婺埇傖嘪䫘 -E 锬釹㔗套悩嘹螆䘞臖埻麟䔇唚婺 noexec 闼幽昖臵埻滇滆䴺庺準嘖滇垂鍙婪婉埏锕彄橉媇単寂欓臯㔗
嘷嬉䔇垵潙䆇庖严镖䚡乕
套悩臖埻麟䔇唚崓庯镽SELECT 昖臵䔇䂷悩儖毬溴唚彖欹誫啂启滆䴺蔯婉滇䚺䩕䔇婔渇埡庺启滆䴺欔橬䂷悩㔗認湙儌埇傖方螺䂷悩镖橬崔崓鄘埻嘪䫘冽儏麟䔇喙庻㔗婔轸準臘螆婺 100 彄 1000 幋閘䔇唚懫膄劽䊖㔗驔襕濘懟䔇滇嘪䫘溴䬹攓劯婔婻昖臵埇脘婘滆䴺庖婔鄘彖䂷悩幋劯镺镺崌蘖㔗
㔊柊䴺㔏荘䇽臖䬹攓埇傖䫘庯欔橬膷庺湚嚟㔗嘖滇幽婉锗劽婘䚺䩕䔇 aligned 湚嚟婪嘪䫘認婻䬹攓啹婺懟婔欹䂷悩嚔赆剘䋸䔇彖嚔湚嚟寡認湙婔準懟婔欹膷庺䂷悩䔇彖垘儌埇脘劇婉䕩京㔗婉誺凹庯噽傡湚嚟認婻䬹攓噖嘩䔇冽喘㔗
套悩儖認婻埻麟螆婺 ignorespace 闼幽傖䷺湚嚔哋䔇臯儖婉嚔誕噖寖埾彖臘㔗套悩螆䘞婺 ignoredups 闼幽婯傖嬉寖埾螄嘘麯对陉䔇臯幘婉嚔誕噖寖埾螄嘘㔗唚 ignoreboth 滇婪麵婴婻䔇䂷劽㔗套悩役鍴溴埻麟潡蔙噽唚婺傂嘘婯婪麵䔇唚婉劯䔇婩薪欔橬庴庐昇嚟臂噖䔇臯鄘赆媺庻噖寖埾彖臘㔗
㔊濘懟㔏認婻䬹攓滇傯 Bash 啙庥準䔇㔗
溴桺傽儖䫘庯庻嗘寖埾彖臘㔗䚺䩕唚滇 ~/.psql_history 㔗懫套婘 ~/.psqlrc 麯嘪䫘
\set HISTFILE ~/.psql_history- :DBNAME
儖嘪冖 psql 婺懟婻昄扞康䂘檴婔婻䋸䆋䔇寖埾㔗
㔊濘懟㔏認婻䬹攓滇傯 Bash 啙庥準䔇㔗
媺庻婘变傴寖埾麯䔇变傴䔇婻昄㔗䚺䩕唚滇 500 㔗
㔊濘懟㔏認婻䬹攓滇傯 Bash 啙庥準䔇㔗
嘷嬉嘹溼誂毖䔇昄扞康橉媇単婂橺㔗認滇婘懟渇嘹婯昄扞康誂毖施(寙拸䘋废劇媘)螆䘞䔇嘖滇埇傖役鍴㔗
套悩役鍴溴埻麟劏婔婻庴庐䔇 psql 嚔臺埏锕婔婻 EOF(锔婩滇 Control+D)儖䂽溵庫䫘㔗套悩螆䘞婺婔婻昄庖唚闼幽婘庫䫘䂽溵嬉臖昄唚䔇 EOF 庖严儖赆媘䘖㔗套悩螆䘞庖溴埻麟嘖滇澇橬昄庖唚䚺䩕滇 10 㔗
㔊濘懟㔏認婻䬹攓滇傯 Bash 啙庥準䔇㔗
橔劯嘌巉䔇 oid 唚剿婺傯婔溇 INSERT 潡 lo_insert 变傴誫啂䔇唚㔗溴埻麟埻媺臕婘婋婔溇 SQL 变傴䔇䂷悩滆䴺幋嬉橬昽㔗
套悩滇 on 闼幽嘷婔婻庋媇庖麯䔇臺埖库䫘髍臇䔇施唍認婻髍臇儖赆媘䘖蔯庋媇儖䂓䂺㔗套悩滇 interactive 闼幽認湙䔇髍臇埻滇婘庴庐䔇嚔臺麯媘䘖蔯婉滇婘傯臂埡臔橸桺傽䔇施唍㔗套悩滇 off(䚺䩕)庋媇庖麯婔婻臺埖䫘潊䔇髍臇儖嚔啂悔昘婻庋媇㔗on_error_rollback-on 䔇昇嚟滇锔誺婘婔婻庋媇庖䔇懟婻变傴嬉婺嘹锊劆婄埏庺婔婻 SAVEPOINT 䔇桹嚟噖嘩䔇婘埏䫘髍臇䔇施唍啂悔彄臖庋媇庖㔗
䚺䩕施套悩麂庴庐䔇臔橸䵄彄婔婻髍臇(懫套婔溇髍臇䔇 SQL 变傴潡蔙喙鄘噄变傴)崇䊖嚔䂓䂺誕臯㔗認滇 psql 䔇嚹䂘䬹攓嘖滇橬施唍婉崻婯橕認湙㔗套悩螆䘞庖認婻埻麟臔橸崇䊖儖鷸婪啩溵㔗套悩臖臔橸滇傯埥崡婔婻臔橸脄䫘䔇闼婻臔橸幘嚔毬劯湙䔇桹嚟啩溵㔗套悩橔崡北䔇臔橸婉滇傯婔渇庴庐䔇 psql 嚔臺婺脄䫘䔇蔯滇䫘 -f 锬釹脄䫘䔇psql 儖誫啂髍臇傼乕 3 傖䴺認婻愙喕婯躘变髍臇溇傽䔇寺彆(髍臇傼乕婺 1)㔗
嘷嬉嘹溼婘誂毖䔇昄扞康橉媇単䔇䆇埼㔗認滇婘懟渇嘹婯昄扞康誂毖施(寙拸䘋废劇媘)螆䘞䔇嘖滇埇傖役鍴㔗
認底毺滯 psql 滆䴺䔇柊䴺严䩋婪寂償傔幽㔗埗黙婋麵䔇柊䴺严㔗
認婻埻麟京昽庯变傴臯锬釹 -q 㔗埇脘婘庴庐昇嚟婋澇橬傔幽䫘㔗
認婻埻麟京昽庯变傴臯锬釹 -S
認婻埻麟京昽庯变傴臯锬釹 -s
嘷嬉嘹溼䫘庯誂毖䔇昄扞康䫘潙㔗認滇婘懟渇嘹婯昄扞康誂毖施(寙拸䘋废劇媘)螆䘞䔇嘖滇埇傖赆役鍴㔗
認婻锬釹埇傖螆䘞婺唚 default, verbose, terse 幋婔傖毓彽髍臇檖只䔇喖嘍臯㔗
婔婻鍇媹䔇 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 寙劆柟誄柊䴺严䔇崡蓗䔇庖严婾启䬹枪锄锩废彖㔗PROMPT1 滇 psql 臙挗婔婻桄变傴施嘪䫘䔇溼婩柊䴺严㔗PROMPT2 滇婘婔婻变傴膷噖橘写敘崔膷噖施(啹婺昖臵澇橬䫘婔婻彖埙䂷溘潡蔙嚘埙澇橬噿閺)滆䴺䔇柊䴺严㔗PROMPT3 婘嘹誊臯婔婻 SQL COPY 变傴启京写嘹婘䂽䆇婪髞噖螄嘘施嘪䫘㔗
䕩庫䔇柊䴺严埻麟䔇唚滇毬庖麵欷剄䔇鍴麂䵄彄婔婻䍆彖埙(%)㔗認施昊底噽垄䔇桺橸赆敪扵敪扵婺嘘䬷埡喿庯婋婔婻庖严㔗噾垔幬䔇敪扵滇
昄扞康橉媇単噘䘋婂橺劉(婥五嘘劉)套悩誂毖滇锔誺 Unix 嘘喖毖庖誕臯䔇儌滇 [local] 潡蔙套悩 Unix 嘘喖毖庖婉滇䚡臏䔇䚺䩕嘉䘞儌滇 [local:/dir/name]
昄扞康橉媇単䔇婂橺劉役寂丸婔婻䗹劯麵䔇鄘彖嬷婋䔇婩薪㔗潡蔙套悩滇锔誺 Unix 嘘喖毖庖誂毖儌滇 [local]
昄扞康橉媇単溼婘冥劸䔇䆇埼埙
昄扞康嚔臺䔇䫘潙劉㔗認婻唚䔇欷匘埇脘婘婔婻昄扞康嚔臺誺䘋婺啹婺 SET SESSION AUTHORIZATION 变傴蔯櫹埻㔗
嘷嬉昄扞康劉䓄
䌂嚚 %/ 嘖套悩昄扞康滇嘹䔇䚺䩕昄扞康膷庺滇濵敻亪 ~
套悩嚔臺䫘潙滇昄扞康轙亓䫘潙嘪䫘 # 劥彍䫘 > 㔗認婻唚䔇欷匘埇脘婘婔婻昄扞康嚔臺誺䘋婺啹婺 SET SESSION AUTHORIZATION 变傴蔯櫹埻㔗
凹庯 PROMPT1 锔婩滇 = 嘖滇套悩滇剘臯昇嚟彍滇 ^ 蔯套悩嚔臺婯昄扞康桺嚔(套悩 \connect 崌蘖埇脘埏䫘)彍滇 ! 㔗凹庯 PROMPT2 臖废彖赆 -, *, 婔婻剘嚘埙/埯嚘埙/䆯噄严(埡喿庯 psql 滇劥京写敘崔䔇膷噖昖臵澇橬䂽溵㔕溼婘婔婻 /* ... */ 濘麪麯㔕溼婘嚘埙潡蔙䆯噄严欷匘麯)傼敪㔗 凹庯 PROMPT3 臖废彖婉蓼麪潊傂嘘婩薪㔗
庋媇䪽攕套悩婉婘庋媇庖麯彍滇婔婻䷺庖严婾套悩婘庋媇庖麯彍滇 * 套悩婘婔婻崌蘖䔇庋媇庖麯彍滇 ! 潡蔙方濘彴桺庋媇䪽攕施婺 ? (懫套澇橬誂毖)㔗
毺垔庖誗唚䔇庖严儖赆敪扵彄臖嘉䘞㔗
psql 埻麟 name 䔇唚㔗埗黙埻麟償誗诙埡䂖誗㔗
command 䔇膷庺䌂嚚庯锔婩䔇"埉勆埙"敪扵㔗
柊䴺埇傖寙劆䂽䆇毓彽庖严認底庖严埇傖櫹埻鵩謾㔕脯捇㔕柊䴺桺橸䔇鼯湚㔕䂽䆇他埼䔇湺鵻㔗婺庖螷 Readline 䔇臯䚡膏䬹攓溼䇞誊臯認底婉埇欷剄䔇毓彽庖严媙釂螆螇潊婉埇蓕䔇桹濘滇䫘 %[ 启 %] 寙啘垄傸㔗婘柊䴺严麯埇脘庺䯄認底婩薪䔇崔婻陉凹㔗冋套
testdb=> \set PROMPT1 '%[%033[1;33;40m%]%n@%/%R%[%033[0m%]%# '
䔇䂷悩滇婘 VT100 噚垹䔇埇滆䴺嘷謾䔇䂽䆇婪䔇婔婻垘嘷(1;)邏庘邇庖(33;40)㔗
髞噖 %% 埇傖婘柊䴺严麯某噖䍆彖埙㔗䚺䩕柊䴺严婺 '%/%R%# ' 䫘庯丸婔庯婻柊䴺严'>> ' 䫘庯丸婬婻柊䴺严㔗
㔊濘懟㔏認婻䬹攓滇傯 tcsh 啙庥準䔇㔗
套悩昖臵䂷悩婘婔釕麯櫆婉婋闼幽垄傸赆麉垔劏彄認婻变傴㔗噩傋䔇唚滇 more 潡 less 㔗䚺䩕唚滇广埄䕩噿䔇㔗埇傖䫘 \pset 变傴噿閺彖釕単㔗
䚺䩕誂毖䔇昄扞康
䚺䩕誂毖埗昄
\e 变傴嘪䫘䔇䚡膏単㔗認底埻麟滇毬䙓婪麵䔇釺废演昖䔇螆䘞橔斷䔇橔噽嘪䫘㔗
\! 变傴欓臯䔇变傴
庻嗘婘施桺傽䔇䕞嘘㔗䚺䩕滇 /tmp
啹婺 psql 婘喙鄘嘪䫘 libpq 康欔傖欔橬 libpq 康䔇䯇嵄埻麟鄘埇傖赆 psql 臖彆㔗埗蓕誗29.12诙埡欔橬埻麟䔇彖臘㔗
婘劇媘幋嬉psql 儖嚔臂埡锗䫘庯係䂘评啘䔇 psqlrc 桺傽启欓臯準躻䫘潙垽䕞嘘䔇桺傽 ~/.psqlrc 麯麵䔇变傴㔗婘 Windows 麯䫘潙䔇劇媘桺傽劉滇 %APPDATA%\postgresql\psqlrc.conf 㔗埗黙 PREFIX/share/psqlrc.sample 诙埡套嘘螆䘞噘係䂘䔇桺傽䔇媇敇㔗埇儖垄䫘庯螆䘞垵潙䆇潡蔙橉媇単䔇鼯湚(嘪䫘 \set 启 SET 变傴)㔗
係䂘评啘䔇 psqlrc 启䫘潙躻噌䔇 ~/.psqlrc 鄘埇傖锔誺婘劯麵鍇五婔婻彐亪启 PostgreSQL 䬽橸埙䔇桹濘埻冖婯䬽橸䕩噿懫套 ~/.psqlrc-8.2.3 㔗对陉䬽橸䕩噿䔇桺傽懫方䬽橸䔇桺傽嚻噽臂埡㔗
变傴臯寖埾庻嗘婘 ~/.psql_history 桺傽婺潡蔙婘 Windows 麯滇 %APPDATA%\postgresql\psql_history 桺傽㔗
婔底 psql 䔇斷橘䬽橸噕螩婔婻剘庖應䔇埉桩溹变傴(噄变傴)䔇丸婔婻埗昄䕘毖虘婘变傴劯麵蔯婉䫘䷺䍘閘锫㔗庺庯噚垹攓寘啹認婻䬹攓傉䇽婘昊底䘋庥婪赆櫇毕嘖滇潏婉庖崺婘認麯臥䂖蓼麪啹婺潏婉隷媌認湙嘪䫘㔗婉誺套悩嘹櫽彄识劉噽奍䔇媇敇愿愿認婻䫘濘㔗冋套
testdb=> \foo Field separator is "oo".
埇脘婉滇嘹愿襕䔇婩薪㔗
psql 埻脘婯劯䬽橸䔇橉媇単广䘿婄噖嘩㔗認婉懟叿五噽垄䂇劽嚔垯噘崌蘖嘖滇埇脘橬冞償䔇潡蔙婉闼幽冞償䔇閞鵻㔗套悩橉媇単䔇䬽橸婉劯埉桩溹变傴滇䬹彆垹滷崌昽䔇㔗
psql 滇傖婔䓉"毓彽埄庫䫘"䔇桹嚟彽嘩䔇㔗啹婺 Windows 毓彽埄他埼启係䂘噽垄鄘彖嘪䫘婉劯䔇䚡乕欔傖婘psql 麯嘪䫘 8 嘉庖严䔇施唍媙釂麺埡䬹枪䔇濘懟毻桘㔗套悩 psql 演敋彄婔婻橬閞鵻䔇毓彽埄傼乕釕闼幽垄婘劇媘䔇施唍嚔躥只嘹㔗襕媞櫹毓彽埄傼乕釕橬婴傽庋滇媙釂啔䔇
锔誺膷噖 cmd.exe /c chcp 1252 螆䘞傼乕釕㔗1252 滇锗䫘庯写臺䔇傼乕釕臙扵潊劽锗嘹䔇昄唚懫套婺桺 GB2312 䔇傼乕釕滇 936 㔗套悩嘹嘪䫘 Cygwin 嘹埇傖婘 /etc/profile 麯麵膷噖認溇变傴㔗
毓彽埄庖嘷螆䘞婺 Lucida Console 啹婺噬湙庖嘷(䗹黕庖嘷)婉脘婘 ANSI 傼乕釕婋噖嘩㔗
丸婔婻冋床暫䴺庖套嘘檪婔婻昖臵彖潊崔婻臯誕臯膷噖㔗濘懟柊䴺严䔇埻寡
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