psql.1

来自「PostgreSQL 8.2中增加了很多企业用户所需要的功能和性能上的提高,其开」· 1 代码 · 共 1,822 行 · 第 1/4 页

1
1,822
字号
\&'\\t'. The default field separator is\&'|' (a vertical bar)..TP\fBfooter\fRToggles the display of the default footer (xrows)..TP\fBnumericlocale\fRToggles the display of a locale-aware character to separate groupsof digits to the left of the decimal marker. It also enablesa locale-aware decimal marker..TP\fBrecordsep\fRSpecifies the record (line) separator to use in unalignedoutput mode. The default is a newline character..TP\fBtuples_only (or t)\fRToggles between tuples only and full display. Full display mayshow extra information such as column headers, titles, andvarious footers. In tuples only mode, only actual table datais shown..TP\fBtitle [ \fItext\fB ]\fRSets the table title for any subsequently printed tables. Thiscan be used to give your output descriptive tags. If noargument is given, the title is unset..TP\fBtableattr (or T) [ \fItext\fB ]\fRAllows you to specify any attributes to be placed inside theHTML table tag. Thiscould for example be cellpadding orbgcolor. Note that you probably don't wantto specify border here, as that is alreadytaken care of by \\pset border..TP\fBpager\fRControls use of a pager for query and \fBpsql\fRhelp output. If the environment variable \fBPAGER\fRis set, the output is piped to the specified program.Otherwise a platform-dependent default (such as\fImore\fR) is used.When the pager is off, the pager is not used. When the pageris on, the pager is used only when appropriate, i.e. theoutput is to a terminal and will not fit on the screen.(\fBpsql\fR does not do a perfect job of estimatingwhen to use the pager.) \\pset pager turns thepager on and off. Pager can also be set to always,which causes the pager to be always used..RE.PPIllustrations on how these different formats look can be seen inthe Examples [\fBpsql\fR(1)] section..sp.RS.B "Tip:"There are various shortcut commands for \fB\\pset\fR. See\fB\\a\fR, \fB\\C\fR, \fB\\H\fR,\fB\\t\fR, \fB\\T\fR, and \fB\\x\fR..RE.sp.sp.RS.B "Note:"It is an error to call \fB\\pset\fR withoutarguments. In the future this call might show the current statusof all printing options..RE.sp.TP\fB\\q\fRQuits the \fBpsql\fR program..TP\fB\\qecho \fItext\fB [ ... ]\fRThis command is identical to \fB\\echo\fR exceptthat the output will be written to the query output channel, asset by \fB\\o\fR..TP\fB\\r\fRResets (clears) the query buffer..TP\fB\\s [ \fIfilename\fB ]\fRPrint or save the command line history to \fIfilename\fR. If \fIfilename\fR is omitted, the historyis written to the standard output. This option is only availableif \fBpsql\fR is configured to use theGNU \fBReadline\fR library..TP\fB\\set [ \fIname\fB [ \fIvalue\fB [ ... ] ] ]\fRSets the internal variable \fIname\fR to \fIvalue\fR or, if more than one valueis given, to the concatenation of all of them. If no secondargument is given, the variable is just set with no value. Tounset a variable, use the \fB\\unset\fR command.Valid variable names can contain characters, digits, andunderscores. See the section Variables [\fBpsql\fR(1)] below for details.Variable names are case-sensitive.Although you are welcome to set any variable to anything youwant, \fBpsql\fR treats several variablesas special. They are documented in the section about variables..sp.RS.B "Note:"This command is totally separate from the SQLcommand SET [\fBset\fR(7)]..RE.sp.TP\fB\\t\fRToggles the display of output column name headings and row countfooter. This command is equivalent to \\psettuples_only and is provided for convenience..TP\fB\\T \fItable_options\fB\fRAllows you to specify attributes to be placed within thetable tag in HTML tabularoutput mode. This command is equivalent to \\psettableattr \fItable_options\fR..TP\fB\\timing\fRToggles a display of how long each SQL statement takes, in milliseconds..TP\fB\\w {\fIfilename\fB | \fI|command\fB}\fROutputs the current query buffer to the file \fIfilename\fR or pipes it to the Unixcommand \fIcommand\fR..TP\fB\\x\fRToggles expanded table formatting mode. As such it is equivalent to\\pset expanded..TP\fB\\z [ \fIpattern\fB ]\fRProduces a list of all available tables, views and sequences with theirassociated access privileges.If a \fIpattern\fR isspecified, only tables,views and sequences whose names match the pattern are listed.The GRANT [\fBgrant\fR(7)] andREVOKE [\fBrevoke\fR(7)]commands are used to set access privileges.This is an alias for \fB\\dp\fR (``displayprivileges'')..TP\fB\\! [ \fIcommand\fB ]\fREscapes to a separate Unix shell or executes the Unix command\fIcommand\fR. Thearguments are not further interpreted, the shell will see themas is..TP\fB\\?\fRShows help information about the backslash commands..PP.SS "PATTERNS".PPThe various \\d commands accept a \fIpattern\fR parameter to specify theobject name(s) to be displayed. In the simplest case, a patternis just the exact name of the object. The characters within apattern are normally folded to lower case, just as in SQL names;for example, \\dt FOO will display the table namedfoo. As in SQL names, placing double quotes arounda pattern stops folding to lower case. Should you need to includean actual double quote character in a pattern, write it as a pairof double quotes within a double-quote sequence; again this is inaccord with the rules for SQL quoted identifiers. For example,\\dt "FOO""BAR" will display the table namedFOO"BAR (not foo"bar). Unlike the normalrules for SQL names, you can put double quotes around just partof a pattern, for instance \\dt FOO"FOO"BAR will displaythe table named fooFOObar..PPWithin a pattern, * matches any sequence of characters(including no characters) and ? matches any single character.(This notation is comparable to Unix shell file name patterns.)For example, \\dt int* displays all tables whose namesbegin with int. But within double quotes, *and ? lose these special meanings and are just matchedliterally..PPA pattern that contains a dot (.) is interpreted as a schemaname pattern followed by an object name pattern. For example,\\dt foo*.bar* displays all tables whose table namestarts with bar that are in schemas whose schema namestarts with foo. When no dot appears, then the patternmatches only objects that are visible in the current schema search path.Again, a dot within double quotes loses its special meaning and is matchedliterally..PPAdvanced users can use regular-expression notations such as characterclasses, for example [0-9] to match any digit. All regularexpression special characters work as specified inin the documentation, except for . whichis taken as a separator as mentioned above, * which istranslated to the regular-expression notation .*, and? which is translated to .. You can emulatethese pattern characters at need by writing? for .,(\fIR\fR+|) for\fIR\fR*, or(\fIR\fR|) for\fIR\fR?.Remember that the pattern must match the whole name, unlike the usualinterpretation of regular expressions; write * at the beginningand/or end if you don't wish the pattern to be anchored.Note that within double quotes, all regular expression special characterslose their special meanings and are matched literally. Also, the regularexpression special characters are matched literally in operator namepatterns (i.e., the argument of \\do)..PPWhenever the \fIpattern\fR parameteris omitted completely, the \\d commands display all objectsthat are visible in the current schema search path \(em this isequivalent to using the pattern *.To see all objects in the database, use the pattern *.*..SS "ADVANCED FEATURES".SS "VARIABLES".PP\fBpsql\fR provides variable substitutionfeatures similar to common Unix command shells.Variables are simply name/value pairs, where the valuecan be any string of any length. To set variables, use the\fBpsql\fR meta-command\fB\\set\fR:.sp.nftestdb=> \fB\\set foo bar\fR.sp.fisets the variable foo to the valuebar. To retrieve the content of the variable, precedethe name with a colon and use it as the argument of any slashcommand:.sp.nftestdb=> \fB\\echo :foo\fRbar.sp.fi.sp.RS.B "Note:"The arguments of \fB\\set\fR are subject to the samesubstitution rules as with other commands. Thus you can constructinteresting references such as \\set :foo\&'something' and get ``soft links'' or``variable variables'' of Perlor PHP fame,respectively. Unfortunately (or fortunately?), there is no way to doanything useful with these constructs. On the other hand,\\set bar :foo is a perfectly valid way to copy avariable..RE.sp.PPIf you call \fB\\set\fR without a second argument, thevariable is set, with an empty string as value. To unset (or delete) avariable, use the command \fB\\unset\fR..PP\fBpsql\fR's internal variable names canconsist of letters, numbers, and underscores in any order and anynumber of them. A number of these variables are treated speciallyby \fBpsql\fR. They indicate certain optionsettings that can be changed at run time by altering the value ofthe variable or represent some state of the application. Althoughyou can use these variables for any other purpose, this is notrecommended, as the program behavior might grow really strangereally quickly. By convention, all specially treated variablesconsist of all upper-case letters (and possibly numbers andunderscores). To ensure maximum compatibility in the future, avoidusing such variable names for your own purposes. A list of all speciallytreated variables follows..TP\fBAUTOCOMMIT\fRWhen on (the default), each SQL command is automaticallycommitted upon successful completion. To postpone commit in thismode, you must enter a \fBBEGIN\fR or \fBSTARTTRANSACTION\fR SQL command. When off or unset, SQLcommands are not committed until you explicitly issue\fBCOMMIT\fR or \fBEND\fR. The autocommit-offmode works by issuing an implicit \fBBEGIN\fR for you, justbefore any command that is not already in a transaction block andis not itself a \fBBEGIN\fR or other transaction-controlcommand, nor a command that cannot be executed inside a transactionblock (such as \fBVACUUM\fR)..sp.RS.B "Note:"In autocommit-off mode, you must explicitly abandon any failedtransaction by entering \fBABORT\fR or \fBROLLBACK\fR.Also keep in mind that if you exit the sessionwithout committing, your work will be lost..RE.sp.sp.RS.B "Note:"The autocommit-on mode is PostgreSQL's traditionalbehavior, but autocommit-off is closer to the SQL spec. If youprefer autocommit-off, you may wish to set it in the system-wide\fIpsqlrc\fR file or your\fI~/.psqlrc\fR file..RE.sp.TP\fBDBNAME\fRThe name of the database you are currently connected to. This isset every time you connect to a database (including programstart-up), but can be unset..TP\fBECHO\fRIf set to all, all linesentered from the keyboard or from a script are written to the standard outputbefore they are parsed or executed. To select this behavior on programstart-up, use the switch \fB-a\fR. If set toqueries,\fBpsql\fR merely prints all queries asthey are sent to the server. The switch for this is\fB-e\fR..TP\fBECHO_HIDDEN\fRWhen this variable is set and a backslash command queries thedatabase, the query is first shown. This way you can study thePostgreSQL internals and providesimilar functionality in your own programs. (To select this behavioron program start-up, use the switch \fB-E\fR.) If you setthe variable to the value noexec, the queries arejust shown but are not actually sent to the server and executed..TP\fBENCODING\fRThe current client character set encoding..TP\fBFETCH_COUNT\fRIf this variable is set to an integer value > 0,the results of \fBSELECT\fR queries are fetchedand displayed in groups of that many rows, rather than thedefault behavior of collecting the entire result set beforedisplay. Therefore only alimited amount of memory is used, regardless of the size ofthe result set. Settings of 100 to 1000 are commonly usedwhen enabling this feature.Keep in mind that when using this feature, a query mayfail after having already displayed some rows..sp.RS.B "Tip:"Although you can use any output format with this feature,the default aligned format tends to look badbecause each group of FETCH_COUNT rowswill be formatted separately, leading to varying columnwidths across the row groups. The other output formats work better..RE.sp.TP\fBHISTCONTROL\fRIf this variable is set to ignorespace,lines which begin with a space are not entered into the historylist. If set to a value of ignoredups, linesmatching the previous history line are not entered. A value ofignoreboth combines the two options. Ifunset, or if set to any other value than those above, all linesread in interactive mode are saved on the history list..sp.RS.B "Note:"This feature was shamelessly plagiarized from\fBBash\fR..RE.sp.TP\fBHISTFILE\fRThe file name that will be used to store the history list. The defaultvalue is \fI~/.psql_history\fR. For example, putting.sp.nf\\set HISTFILE ~/.psql_history- :DBNAME.sp.fiin \fI~/.psqlrc\fR will cause\fBpsql\fR to maintain a separate history foreach database..sp.RS.B "Note:"This feature was shamelessly plagiarized from\fBBash\fR..RE.sp.TP\fBHISTSIZE\fRThe number of commands to store in the command history. Thedefault value is 500..sp.RS.B "Note:"This feature was shamelessly plagiarized from\fBBash\fR..RE.sp.TP\fBHOST\fRThe database server host you are currently connected to. This isset every time you connect to a database (including programstart-up), but can be unset..TP\fBIGNOREEOF\fRIf unset, sending an EOF character (usually\fBControl\fR+\fBD\fR)to an interactive session of \fBpsql\fRwill terminate the application. If set to a numeric value,that many EOF characters are ignored before theapplication terminates. If the variable is set but has nonumeric value, the default is 10..sp.RS.B "Note:"This feature was shamelessly plagiarized from\fBBash\fR..RE.sp.TP\fBLASTOID\fRThe value of the last affected OID, as returned from an\fBINSERT\fR or \fBlo_insert\fRcommand. This variable is only guaranteed to be valid untilafter the result of the next SQL command hasbeen displayed..TP\fBON_ERROR_ROLLBACK\fRWhen on, if a statement in a transaction blockgenerates an error, the error is ignored and the transactioncontinues. When interactive, such errors are onlyignored in interactive sessions, and not when reading scriptfiles. When off (the default), a statement in atransaction block that generates an error aborts the entiretransaction. The on_error_rollback-on mode works by issuing animplicit \fBSAVEPOINT\fR for you, just before each commandthat is in a transaction block, and rolls back to the savepointon error..TP\fBON_ERROR_STOP\fRBy default, if non-interactive scripts encounter an error, suchas a malformed SQL command or internalmeta-command, processing continues. This has been thetraditional behavior of \fBpsql\fR but itis sometimes not desirable. If this variable is set, scriptprocessing will immediately terminate. If the script was calledfrom another script it will terminate in the same fashion. Ifthe outermost script was not called from an interactive\fBpsql\fR session but rather using the\fB-f\fR option, \fBpsql\fR willreturn error code 3, to distinguish this case from fatal errorconditions (error code 1)..TP

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?