バージョンごとのドキュメント一覧

psql

psql <productname>PostgreSQL</productname> interactive terminal PostgreSQLの対話的ターミナル

概要

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

説明

<title>Description</title>

<application>psql</application> is a terminal-based front-end to <productname>PostgreSQL</productname>. It enables you to type in queries interactively, issue them to <productname>PostgreSQL</productname>, and see the query results. Alternatively, input can be from a file or from command line arguments. In addition, <application>psql</application> provides a number of meta-commands and various shell-like features to facilitate writing scripts and automating a wide variety of tasks. psqlとはPostgreSQLのターミナル型フロントエンドです。 対話的に問い合わせを入力し、それをPostgreSQLに対して発行して、結果を確認することができます。 また、ファイルまたはコマンドライン引数から入力を読み込むことも可能です。 さらに、psqlは、スクリプトの記述を簡便化したり、様々なタスクを自動化したりする、いくつものメタコマンドとシェルに似た各種の機能を備えています。

オプション

<title>Options</title>
-a
--echo-all #

Print all nonempty input lines to standard output as they are read. (This does not apply to lines read interactively.) This is equivalent to setting the variable <varname>ECHO</varname> to <literal>all</literal>. 読み込んだ全ての空でない入力行を標準出力に表示します。 (これは対話式に読み込まれる行には適用されません。) これはECHO変数をallに設定するのと同じ意味を持ちます。

-A
--no-align #

Switches to unaligned output mode. (The default output mode is <literal>aligned</literal>.) This is equivalent to <command>\pset format unaligned</command>. 位置揃えなしの出力モードに切り替えます。 (デフォルトの出力モードはaligned(位置揃えあり)です。) これは\pset format unalignedと同等です。

-b
--echo-errors #

Print failed SQL commands to standard error output. This is equivalent to setting the variable <varname>ECHO</varname> to <literal>errors</literal>. 失敗したSQLコマンドを標準エラー出力に出力します。 これはECHO変数をerrorsに設定するのと同等です。

-c command
--command=command #

Specifies that <application>psql</application> is to execute the given command string, <replaceable class="parameter">command</replaceable>. This option can be repeated and combined in any order with the <option>-f</option> option. When either <option>-c</option> or <option>-f</option> is specified, <application>psql</application> does not read commands from standard input; instead it terminates after processing all the <option>-c</option> and <option>-f</option> options in sequence. psqlに対し、指定のコマンド文字列commandを実行するよう指示します。 このオプションは繰り返すことができ、また-fオプションと任意の順序で組み合わせることができます。 -cまたは-fが指定されると、psqlは標準入力からコマンドを読み取りません。 その代わりに、すべての-cオプションおよび-fオプションを順に処理した後、終了します。

<replaceable class="parameter">command</replaceable> must be either a command string that is completely parsable by the server (i.e., it contains no <application>psql</application>-specific features), or a single backslash command. Thus you cannot mix <acronym>SQL</acronym> and <application>psql</application> meta-commands within a <option>-c</option> option. To achieve that, you could use repeated <option>-c</option> options or pipe the string into <application>psql</application>, for example: commandは、サーバで完全に解析可能な(つまり、psql特有の機能は含まない)コマンド文字列、もしくは、バックスラッシュコマンド1つである必要があります。 このため、-cオプション内ではSQLpsqlメタコマンドを混在させることはできません。 これらを同時に使用するには、-cオプションを繰り返し利用するか、あるいはパイプを使って文字列をpsqlに渡します。 例えば、

psql -c '\x' -c 'SELECT * FROM foo;'

or あるいは

echo '\x \\ SELECT * FROM foo;' | psql

(<literal>\\</literal> is the separator meta-command.) のようにします(\\はメタコマンドの区切り文字です)。

Each <acronym>SQL</acronym> command string passed to <option>-c</option> is sent to the server as a single request. Because of this, the server executes it as a single transaction even if the string contains multiple <acronym>SQL</acronym> commands, unless there are explicit <command>BEGIN</command>/<command>COMMIT</command> commands included in the string to divide it into multiple transactions. (See <xref linkend="protocol-flow-multi-statement"/> for more details about how the server handles multi-query strings.) -cに渡される各SQLのコマンド文字列は、単一の要求としてサーバに送信されます。 このため、トランザクションを複数に分けるBEGIN/COMMITコマンドが明示的に文字列内に含まれない限り、文字列内に複数のSQLコマンドが含まれていたとしても、サーバはそれを1つのトランザクションとして実行します。 (複数問い合わせの文字列をどのようにサーバが処理するかについて、詳しくは55.2.2.1を参照してください。)

If having several commands executed in one transaction is not desired, use repeated <option>-c</option> commands or feed multiple commands to <application>psql</application>'s standard input, either using <application>echo</application> as illustrated above, or via a shell here-document, for example: 1つのトランザクションで複数のコマンドを実行することが望ましくない場合は、繰り返し-cコマンドを使用するか、あるいは、上記のようにechoを使用するか、以下の例のようにシェルのヒアドキュメントを介してpsqlの標準入力に複数のコマンドを送ります。

psql <<EOF
\x
SELECT * FROM foo;
EOF
--csv #

Switches to <acronym>CSV</acronym> (Comma-Separated Values) output mode. This is equivalent to <command>\pset format csv</command>. CSV(コンマ区切り値)出力モードに切り替えます。 これは\pset format csvと同等です。

-d dbname
--dbname=dbname #

Specifies the name of the database to connect to. This is equivalent to specifying <replaceable class="parameter">dbname</replaceable> as the first non-option argument on the command line. The <replaceable>dbname</replaceable> can be a <link linkend="libpq-connstring">connection string</link>. If so, connection string parameters will override any conflicting command line options. 接続するデータベースの名前を指定します。 コマンドラインでオプション以外の最初の引数としてdbnameを指定するのと同じ効力を持ちます。 dbname接続文字列でも構いません。 その場合、接続文字列パラメータは衝突するコマンドラインオプションに優先します。

-e
--echo-queries #

Copy all SQL commands sent to the server to standard output as well. This is equivalent to setting the variable <varname>ECHO</varname> to <literal>queries</literal>. サーバに送られるすべてのSQLコマンドを標準出力にも送ります。 ECHO変数をqueriesに設定するのと同じ効力を持ちます。

-E
--echo-hidden #

Echo the actual queries generated by <command>\d</command> and other backslash commands. You can use this to study <application>psql</application>'s internal operations. This is equivalent to setting the variable <varname>ECHO_HIDDEN</varname> to <literal>on</literal>. \dやその他のバックスラッシュコマンドによって生成される実際の問い合わせを表示します。 これを使って、psqlの内部動作を調べることができます。 これは変数ECHO_HIDDENonに設定するのと同じ効力を持ちます。

-f filename
--file=filename #

Read commands from the file <replaceable class="parameter">filename</replaceable>, rather than standard input. This option can be repeated and combined in any order with the <option>-c</option> option. When either <option>-c</option> or <option>-f</option> is specified, <application>psql</application> does not read commands from standard input; instead it terminates after processing all the <option>-c</option> and <option>-f</option> options in sequence. Except for that, this option is largely equivalent to the meta-command <command>\i</command>. 標準入力ではなく、ファイルfilenameからコマンドを読み取ります。 このオプションは繰り返すことができ、また-cオプションと任意の順序で組み合わせることができます。 -cまたは-fが指定されると、psqlは標準入力からコマンドを読み取りません。 その代わりに、すべての-cオプションおよび-fオプションを順に処理した後、終了します。 その点を除けば、このオプションは\iメタコマンドとほぼ同等です。

If <replaceable>filename</replaceable> is <literal>-</literal> (hyphen), then standard input is read until an EOF indication or <command>\q</command> meta-command. This can be used to intersperse interactive input with input from files. Note however that Readline is not used in this case (much as if <option>-n</option> had been specified). filename-(ハイフン)を指定すると、標準入力からEOFを示すもの、または\qメタコマンドまで読み取られます。 これは対話的入力をファイルからの入力と混在させるために使うことができます。 ただし、この場合、Readlineは使われないことに注意してください(-nが指定された場合と同様です)。

Using this option is subtly different from writing <literal>psql &lt; <replaceable class="parameter">filename</replaceable></literal>. In general, both will do what you expect, but using <literal>-f</literal> enables some nice features such as error messages with line numbers. There is also a slight chance that using this option will reduce the start-up overhead. On the other hand, the variant using the shell's input redirection is (in theory) guaranteed to yield exactly the same output you would have received had you entered everything by hand. このオプションを指定するのと、psql < filenameと入力するのでは、微妙に動作が異なります。 一般的には、両者とも期待通りの動作を行いますが、-fを使用した場合は、エラーメッセージに行番号を付けるなどいくつか便利な機能が有効になります。 また、このオプションを使用した場合、起動時のオーバーヘッドが減少する可能性が若干あります。 一方、シェルの入力リダイレクションを使用する方法では、(理論的には)全て手作業で入力した場合の出力とまったく同一な出力になることが保証されます。

-F separator
--field-separator=separator #

Use <replaceable class="parameter">separator</replaceable> as the field separator for unaligned output. This is equivalent to <command>\pset fieldsep</command> or <command>\f</command>. separatorを位置揃えを行わない出力におけるフィールド区切り文字として使用します。 \pset fieldsepもしくは\fと同じ効力を持ちます。

-h hostname
--host=hostname #

Specifies the host name of the machine on which the server is running. If the value begins with a slash, it is used as the directory for the Unix-domain socket. サーバを実行しているマシンのホスト名を指定します。 この値がスラッシュから始まる場合、Unixドメインソケット用のディレクトリとして使用されます。

-H
--html #

Switches to <acronym>HTML</acronym> output mode. This is equivalent to <command>\pset format html</command> or the <command>\H</command> command. HTML出力モードに切り替えます。 これは、\pset format htmlもしくは\Hコマンドと同等です。

-l
--list #

List all available databases, then exit. Other non-connection options are ignored. This is similar to the meta-command <command>\list</command>. 利用可能な全てのデータベースを一覧表示し、終了します。 この他の接続に関連しないオプションは無視されます。 \listメタコマンドと似た効力を持ちます。

When this option is used, <application>psql</application> will connect to the database <literal>postgres</literal>, unless a different database is named on the command line (option <option>-d</option> or non-option argument, possibly via a service entry, but not via an environment variable). このオプションが使用されるときは、別のデータベース名がコマンドラインで指定されない限り(オプション-dまたは、環境変数ではない非オプション引数、おそらくサービスエントリーを通じて)、psqlは、postgresデータベースに接続します。

-L filename
--log-file=filename #

Write all query output into file <replaceable class="parameter">filename</replaceable>, in addition to the normal output destination. すべての問い合わせの出力を通常の出力先に出力し、さらにファイルfilenameに書き出します。

-n
--no-readline #

Do not use <application>Readline</application> for line editing and do not use the command history (see <xref linkend="app-psql-readline"/> below). 行編集とコマンド履歴にReadlineを使用しません(下記の「コマンドライン編集」を参照)。

-o filename
--output=filename #

Put all query output into file <replaceable class="parameter">filename</replaceable>. This is equivalent to the command <command>\o</command>. 全ての問い合わせの出力をfilenameファイルに書き込みます。 これは\oコマンドと同じ効力を持ちます。

-p port
--port=port #

Specifies the TCP port or the local Unix-domain socket file extension on which the server is listening for connections. Defaults to the value of the <envar>PGPORT</envar> environment variable or, if not set, to the port specified at compile time, usually 5432. サーバが接続監視を行っているTCPポートもしくはローカルUnixドメインソケットファイルの拡張子を指定します。 環境変数PGPORTの値、環境変数が設定されていない場合はコンパイル時に指定した値(通常は5432)がデフォルト値となります。

-P assignment
--pset=assignment #

Specifies printing options, in the style of <command>\pset</command>. Note that here you have to separate name and value with an equal sign instead of a space. For example, to set the output format to <application>LaTeX</application>, you could write <literal>-P format=latex</literal>. \pset形式により表示オプションを指定します。 ここでは空白ではなく等号を使って名前と値を区切っていることに注意してください。 たとえば、出力形式をLaTeXにする場合、-P format=latexと入力します。

-q
--quiet #

Specifies that <application>psql</application> should do its work quietly. By default, it prints welcome messages and various informational output. If this option is used, none of this happens. This is useful with the <option>-c</option> option. This is equivalent to setting the variable <varname>QUIET</varname> to <literal>on</literal>. psqlがメッセージ出力なしで処理を行うように指示します。 デフォルトでは、ウェルカム(welcome)メッセージや各種の情報が表示されますが、 このオプションを使用した場合、これらのメッセージが表示されません。 -cオプションと併用すると便利です。 これは変数QUIETonに設定するのと同じ効力を持ちます。

-R separator
--record-separator=separator #

Use <replaceable class="parameter">separator</replaceable> as the record separator for unaligned output. This is equivalent to <command>\pset recordsep</command>. separatorを位置揃えを行わない出力におけるレコード区切り文字として使用します。 これは\pset recordsepと同じです。

-s
--single-step #

Run in single-step mode. That means the user is prompted before each command is sent to the server, with the option to cancel execution as well. Use this to debug scripts. シングルステップモードで実行します。 これは各コマンドがサーバに送信される前に、ユーザに対して実行するかキャンセルするかについて確認を求めることを意味します。 スクリプトのデバッグを行う時に使用してください。

-S
--single-line #

Runs in single-line mode where a newline terminates an SQL command, as a semicolon does. シングル行モードで実行します。このモードでは、セミコロンと同じように改行もSQLコマンドの終端として扱われます。

注記

This mode is provided for those who insist on it, but you are not necessarily encouraged to use it. In particular, if you mix <acronym>SQL</acronym> and meta-commands on a line the order of execution might not always be clear to the inexperienced user. このモードはどうしてもこのような方式を使用したいユーザ向けに用意されたもので、必ずしも使用が推奨されるわけではありません。 特に、1行にSQLとメタコマンドを混在させる場合、経験の浅いユーザにとってその実行順番は必ずしもわかりやすいものではありません。

-t
--tuples-only #

Turn off printing of column names and result row count footers, etc. This is equivalent to <command>\t</command> or <command>\pset tuples_only</command>. 列名と結果の行数フッタなどの表示を無効にします。 これは、\tおよび\pset tuples_onlyと同等です。

-T table_options
--table-attr=table_options #

Specifies options to be placed within the <acronym>HTML</acronym> <sgmltag>table</sgmltag> tag. See <command>\pset tableattr</command> for details. HTMLtableタグで使用されるオプションを指定します。 詳細は\pset tableattrを参照してください。

-U username
--username=username #

Connect to the database as the user <replaceable class="parameter">username</replaceable> instead of the default. (You must have permission to do so, of course.) デフォルトのユーザではなくusernameユーザとしてデータベースに接続します (当然、そうする権限を持っていなければなりません)。

-v assignment
--set=assignment
--variable=assignment #

Perform a variable assignment, like the <command>\set</command> meta-command. Note that you must separate name and value, if any, by an equal sign on the command line. To unset a variable, leave off the equal sign. To set a variable with an empty value, use the equal sign but leave off the value. These assignments are done during command line processing, so variables that reflect connection state will get overwritten later. \setメタコマンドのように、変数の代入を行います。 値がある場合、コマンド行上では、名前と値を等号(=)で区切る必要があることに注意してください。 変数を未設定の状態にするには、等号を指定しないでください。 値が空の変数を設定するには、値を指定しないで等号のみ使用してください。 これらの代入はコマンド行処理の段階で行われます。 そのため、接続状態を表す変数は後で上書きされる可能性があります。

-V
--version #

Print the <application>psql</application> version and exit. psqlのバージョンを表示し、終了します。

-w
--no-password #

Never issue a password prompt. If the server requires password authentication and a password is not available from other sources such as a <filename>.pgpass</filename> file, the connection attempt will fail. This option can be useful in batch jobs and scripts where no user is present to enter a password. パスワードの入力を促しません。 サーバがパスワード認証を必要とし、かつ、.pgpassファイルなどの他の情報源からパスワードが入手可能でない場合、接続試行は失敗します。 バッチジョブやスクリプトなどパスワードを入力するユーザが存在しない場合にこのオプションは有用かもしれません。

Note that this option will remain set for the entire session, and so it affects uses of the meta-command <command>\connect</command> as well as the initial connection attempt. このオプションはセッション全体にわたって設定されたままであることに注意してください。 このため\connectメタコマンドの使用に関しても初期接続試行と同様に影響します。

-W
--password #

Force <application>psql</application> to prompt for a password before connecting to a database, even if the password will not be used. パスワードが使われない場合であっても、データベースに接続する前にpsqlは強制的にパスワード入力を促します。

If the server requires password authentication and a password is not available from other sources such as a <filename>.pgpass</filename> file, <application>psql</application> will prompt for a password in any case. However, <application>psql</application> will waste a connection attempt finding out that the server wants a password. In some cases it is worth typing <option>-W</option> to avoid the extra connection attempt. サーバがパスワード認証を必要とし、かつ、.pgpassファイルなどの他の情報源からパスワードが入手可能でない場合、psqlは常にパスワード入力を促します。 しかし、psqlは、サーバにパスワードが必要かどうかを判断するための接続試行を無駄に行います。 こうした余計な接続試行を防ぐために-Wの入力が有意となる場合もあります。

Note that this option will remain set for the entire session, and so it affects uses of the meta-command <command>\connect</command> as well as the initial connection attempt. このオプションはセッション全体に対して設定されたままであることに注意してください。 このため初期接続試行と同様に\connectメタコマンドの使用にも影響を与えます。

-x
--expanded #

Turn on the expanded table formatting mode. This is equivalent to <command>\x</command> or <command>\pset expanded</command>. 拡張テーブル形式モードを有効にします。 これは\xおよび\pset expandedと同じです。

-X,
--no-psqlrc #

Do not read the start-up file (neither the system-wide <filename>psqlrc</filename> file nor the user's <filename>~/.psqlrc</filename> file). 起動用ファイル(psqlrcファイルおよびユーザ用の~/.psqlrcファイルのどちらも)を読み込みません。

-z
--field-separator-zero #

Set the field separator for unaligned output to a zero byte. This is equivalent to <command>\pset fieldsep_zero</command>. 位置揃えを行わない出力用のフィールド区切り文字をゼロバイトに設定します。 これは\pset fieldsep_zeroと同じです。

-0
--record-separator-zero #

Set the record separator for unaligned output to a zero byte. This is useful for interfacing, for example, with <literal>xargs -0</literal>. This is equivalent to <command>\pset recordsep_zero</command>. 位置揃えを行わない出力用のレコード区切り文字をゼロバイトに設定します。 これは例えばxargs -0と連携する時に有用です。 これは\pset recordsep_zeroと同じです。

-1
--single-transaction #

This option can only be used in combination with one or more <option>-c</option> and/or <option>-f</option> options. It causes <application>psql</application> to issue a <command>BEGIN</command> command before the first such option and a <command>COMMIT</command> command after the last one, thereby wrapping all the commands into a single transaction. If any of the commands fails and the variable <varname>ON_ERROR_STOP</varname> was set, a <command>ROLLBACK</command> command is sent instead. This ensures that either all the commands complete successfully, or no changes are applied. このオプションは、1つ以上の-cオプションや-fオプションと組み合わせてのみ使うことができます。 これによりpsqlは、最初のそのようなオプションの前にBEGINコマンドを発行し、最後のオプションの後にCOMMITコマンドを発行するようになります。 そうすることで、すべてのコマンドが単一のトランザクションに囲まれます。 コマンドのいずれかが失敗して、変数ON_ERROR_STOPが設定されていれば、ROLLBACKが代わりに送られます。 これによりすべてのコマンドが成功して完了するか、変更がまったく行われないかのいずれかになります。

If the commands themselves contain <command>BEGIN</command>, <command>COMMIT</command>, or <command>ROLLBACK</command>, this option will not have the desired effects. Also, if an individual command cannot be executed inside a transaction block, specifying this option will cause the whole transaction to fail. コマンド自体がBEGINCOMMITROLLBACKを含んでいる場合、このオプションは期待した効果を得ることができません。 また、個別のコマンドがトランザクションブロック内部で実行できない場合、このオプションを指定することで、そのトランザクション全体が失敗します。

-?
--help[=topic] #

Show help about <application>psql</application> and exit. The optional <replaceable class="parameter">topic</replaceable> parameter (defaulting to <literal>options</literal>) selects which part of <application>psql</application> is explained: <literal>commands</literal> describes <application>psql</application>'s backslash commands; <literal>options</literal> describes the command-line options that can be passed to <application>psql</application>; and <literal>variables</literal> shows help about <application>psql</application> configuration variables. psqlに関するヘルプを表示し、終了します。 オプションのtopicパラメータ(デフォルトはoptions)はpsqlのどの部分を説明するかを選択します。 commandspsqlのバックスラッシュコマンドについて、optionspsqlに渡すことができるコマンド行オプションについて、variablespsqlの設定変数についてのヘルプを表示します。

終了ステータス

<title>Exit Status</title>

<application>psql</application> returns 0 to the shell if it finished normally, 1 if a fatal error of its own occurs (e.g., out of memory, file not found), 2 if the connection to the server went bad and the session was not interactive, and 3 if an error occurred in a script and the variable <varname>ON_ERROR_STOP</varname> was set. psqlは、正常に終了した時には0を、psqlにとって致命的なエラー(メモリ不足やファイルが見つからないなど)が発生した時には1を、セッションが対話式でない状態でサーバとの接続が不完全になった時には2を、ON_ERROR_STOP変数が設定されている状態でスクリプトでエラーが発生した時には3をシェルに返します。

使用方法

<title>Usage</title>

データベースへの接続

<title>Connecting to a Database</title>

<application>psql</application> is a regular <productname>PostgreSQL</productname> client application. In order to connect to a database you need to know the name of your target database, the host name and port number of the server, and what database user name you want to connect as. <application>psql</application> can be told about those parameters via command line options, namely <option>-d</option>, <option>-h</option>, <option>-p</option>, and <option>-U</option> respectively. If an argument is found that does not belong to any option it will be interpreted as the database name (or the database user name, if the database name is already given). Not all of these options are required; there are useful defaults. If you omit the host name, <application>psql</application> will connect via a Unix-domain socket to a server on the local host, or via TCP/IP to <literal>localhost</literal> on Windows. The default port number is determined at compile time. Since the database server uses the same default, you will not have to specify the port in most cases. The default database user name is your operating-system user name. Once the database user name is determined, it is used as the default database name. Note that you cannot just connect to any database under any database user name. Your database administrator should have informed you about your access rights. psqlPostgreSQLの正式なクライアントアプリケーションです。 データベースに接続するには、接続するデータベース名、ホスト名、サーバのポート番号、接続する際に使用するデータベースユーザ名がわかっていなければなりません。 psqlでは、それらをコマンドラインオプションで指定することができます。接続するデータベース名は-d、ホスト名は-h、サーバのポート番号は-p、接続するユーザ名は-Uを使用してそれぞれ指定します。 オプションでない引数がある場合、それはデータベース名(データベース名が与えられている場合にはデータベースユーザ名)とみなされます。 これらのオプションは全て指定されている必要はありません。便利なデフォルト値があります。 ホスト名を省略した場合、psqlはUnixドメインソケット経由でローカルホスト上のサーバに、WindowsではlocalhostにTCP/IP経由で接続します。 デフォルトのポート番号はコンパイル時に設定されます。 データベースサーバは同じデフォルト値を使用するので、多くの場合、ポートは指定する必要はありません。 デフォルトのデータベースユーザ名はOSのユーザ名です。 データベースユーザ名が決まれば、デフォルトのデータベース名として使われます。 任意のデータベースユーザ名で全てのデータベースに接続できるわけではないことに注意してください。 データベース管理者は、接続権限をユーザに知らせておかなければなりません。

When the defaults aren't quite right, you can save yourself some typing by setting the environment variables <envar>PGDATABASE</envar>, <envar>PGHOST</envar>, <envar>PGPORT</envar> and/or <envar>PGUSER</envar> to appropriate values. (For additional environment variables, see <xref linkend="libpq-envars"/>.) It is also convenient to have a <filename>~/.pgpass</filename> file to avoid regularly having to type in passwords. See <xref linkend="libpq-pgpass"/> for more information. デフォルトが完全には適用できない時は、入力の手間を省くために、環境変数PGDATABASEPGHOSTPGPORTPGUSERに適当な値を設定することもできます。 (この他の環境変数については、34.15を参照してください。) また、~/.pgpassファイルを使用すれば、定常的なパスワードの入力を省略でき、便利です。 詳細は34.16を参照してください。

An alternative way to specify connection parameters is in a <parameter>conninfo</parameter> string or a <acronym>URI</acronym>, which is used instead of a database name. This mechanism give you very wide control over the connection. For example: 他の接続パラメータの指定方法としてconninfo文字列またはURIがあります。 これは、データベース名の代わりに使用されます。 この機構により、接続全体に関する非常に幅広い制御を行うことができます。 以下に例を示します。

$ psql "service=myservice sslmode=require"
$ psql postgresql://dbmaster:5433/mydb?sslmode=require

This way you can also use <acronym>LDAP</acronym> for connection parameter lookup as described in <xref linkend="libpq-ldap"/>. See <xref linkend="libpq-paramkeywords"/> for more information on all the available connection options. この方法では接続パラメータの検索に、34.18で説明するLDAPを使用することもできます。 利用できる接続オプションのすべてについての詳細は、34.1.2を参照してください。

If the connection could not be made for any reason (e.g., insufficient privileges, server is not running on the targeted host, etc.), <application>psql</application> will return an error and terminate. 何らかの原因(権限がない、指定したホストでサーバが稼働していないなど)で接続ができなかった場合は、psqlはエラーメッセージを表示し、終了します。

If both standard input and standard output are a terminal, then <application>psql</application> sets the client encoding to <quote>auto</quote>, which will detect the appropriate client encoding from the locale settings (<envar>LC_CTYPE</envar> environment variable on Unix systems). If this doesn't work out as expected, the client encoding can be overridden using the environment variable <envar>PGCLIENTENCODING</envar>. 標準入力および標準出力の両方が端末である場合、psqlはクライアントの符号化方式をautoに設定します。 これはロケール設定(Unixシステムでは環境変数LC_CTYPE)から適切なクライアント符号化方式を決定します。 想定した通りに動作しない場合、環境変数PGCLIENTENCODINGを使用してクライアント符号化方式を上書きすることができます。

SQLコマンドの入力

<title>Entering SQL Commands</title>

In normal operation, <application>psql</application> provides a prompt with the name of the database to which <application>psql</application> is currently connected, followed by the string <literal>=&gt;</literal>. For example: 通常の操作において、psqlは、psqlが現在接続しているデータベース名の後に=>の文字列が付いたプロンプトを表示します。 以下に例を示します。

$ psql testdb
psql (16.0)
Type "help" for help.

testdb=>

At the prompt, the user can type in <acronym>SQL</acronym> commands. Ordinarily, input lines are sent to the server when a command-terminating semicolon is reached. An end of line does not terminate a command. Thus commands can be spread over several lines for clarity. If the command was sent and executed without error, the results of the command are displayed on the screen. プロンプトに対しユーザはSQLコマンドを入力することができます。 通常、入力された行はコマンド終了を意味するセミコロンに達した時点でサーバへと送信されます。 改行はコマンドの終了とはみなされません。 したがって、わかりやすくするために、コマンドは複数の行にわたって記述することができます。 コマンドが送信され問題なく実行されると、画面にコマンドの結果が表示されます。

If untrusted users have access to a database that has not adopted a <link linkend="ddl-schemas-patterns">secure schema usage pattern</link>, begin your session by removing publicly-writable schemas from <varname>search_path</varname>. One can add <literal>options=-csearch_path=</literal> to the connection string or issue <literal>SELECT pg_catalog.set_config('search_path', '', false)</literal> before other SQL commands. This consideration is not specific to <application>psql</application>; it applies to every interface for executing arbitrary SQL commands. 安全なスキーマの利用パターンを適用していないデータベースに信頼できないユーザがアクセス可能な場合は、セッションの開始時にsearch_pathから、誰でも書き込みができるスキーマを削除してください。 options=-csearch_path=を接続文字列に追加するか、SELECT pg_catalog.set_config('search_path', '', false)を他のSQLの前に発行することができます。 この配慮はpsqlに固有のものではありません。 任意のSQLを実行するすべてのインタフェースに適用されるものです。

Whenever a command is executed, <application>psql</application> also polls for asynchronous notification events generated by <link linkend="sql-listen"><command>LISTEN</command></link> and <link linkend="sql-notify"><command>NOTIFY</command></link>. また、コマンドが実行される度に、psqlLISTENNOTIFYによって生成された非同期通知イベントを検査します。

While C-style block comments are passed to the server for processing and removal, SQL-standard comments are removed by <application>psql</application>. Cの形式のブロックコメントは、サーバに送信され、サーバによって取り除かれますが、SQL標準のコメントはpsqlによって取り除かれます。

メタコマンド

<title>Meta-Commands</title>

Anything you enter in <application>psql</application> that begins with an unquoted backslash is a <application>psql</application> meta-command that is processed by <application>psql</application> itself. These commands make <application>psql</application> more useful for administration or scripting. Meta-commands are often called slash or backslash commands. psql内で入力されたコマンドのうち、引用符で囲まれていないバックスラッシュで始まるものは、psql自身が実行するpsqlのメタコマンドとして扱われます。 これらのコマンドを使うと、データベースを管理したりスクリプトを作成するにあたって、psqlがより便利になります。 メタコマンドはよくスラッシュコマンド、またはバックスラッシュコマンドとも呼ばれます。

The format of a <application>psql</application> command is the backslash, followed immediately by a command verb, then any arguments. The arguments are separated from the command verb and each other by any number of whitespace characters. psqlコマンドは、バックスラッシュ、コマンド本体、引数の順につなげた形式になっています。 引数とコマンド本体の間および引数と引数の間は、空白文字によって分割されています。

To include whitespace in an argument you can quote it with single quotes. To include a single quote in an argument, write two single quotes within single-quoted text. Anything contained in single quotes is furthermore subject to C-like substitutions for <literal>\n</literal> (new line), <literal>\t</literal> (tab), <literal>\b</literal> (backspace), <literal>\r</literal> (carriage return), <literal>\f</literal> (form feed), <literal>\</literal><replaceable>digits</replaceable> (octal), and <literal>\x</literal><replaceable>digits</replaceable> (hexadecimal). A backslash preceding any other character within single-quoted text quotes that single character, whatever it is. 引数に空白を含める場合は単一引用符で囲みます。 単一引用符を引数に含める場合には、単一引用符で括られた文字列の中で、その単一引用符を2つ続けてください。 単一引用符で囲われた文字は、C言語と同じような置換の対象となります。 このような文字には、\n(改行)、\t(タブ)、\b (後退)、\r(復帰)、\f (改頁)、\digits(8進数で表された文字)、\xdigits(16進数で表された文字)があります。 単一引用符で括られたテキスト内でその他の任意の文字の前にバックスラッシュを付けた場合は、その文字が何であろうとその一文字だけとして扱われます。

If an unquoted colon (<literal>:</literal>) followed by a <application>psql</application> variable name appears within an argument, it is replaced by the variable's value, as described in <xref linkend="app-psql-interpolation"/> below. The forms <literal>:'<replaceable>variable_name</replaceable>'</literal> and <literal>:"<replaceable>variable_name</replaceable>"</literal> described there work as well. The <literal>:{?<replaceable>variable_name</replaceable>}</literal> syntax allows testing whether a variable is defined. It is substituted by TRUE or FALSE. Escaping the colon with a backslash protects it from substitution. SQL差し替えで説明されているとおり、引数の中に引用符で囲まれていないコロン(:)とそれに続くpsql変数がある場合、その部分は変数の値で置換されます。 そこで説明されている:'variable_name'および:"variable_name"という形式も同様に機能します。 :{?variable_name}構文は、変数が定義済みかどうかをテストできます。 これはTRUEかFALSEに置き換えられます。 コロンをバックスラッシュでエスケープすると置換が防止されます。

Within an argument, text that is enclosed in backquotes (<literal>`</literal>) is taken as a command line that is passed to the shell. The output of the command (with any trailing newline removed) replaces the backquoted text. Within the text enclosed in backquotes, no special quoting or other processing occurs, except that appearances of <literal>:<replaceable>variable_name</replaceable></literal> where <replaceable>variable_name</replaceable> is a <application>psql</application> variable name are replaced by the variable's value. Also, appearances of <literal>:'<replaceable>variable_name</replaceable>'</literal> are replaced by the variable's value suitably quoted to become a single shell command argument. (The latter form is almost always preferable, unless you are very sure of what is in the variable.) Because carriage return and line feed characters cannot be safely quoted on all platforms, the <literal>:'<replaceable>variable_name</replaceable>'</literal> form prints an error message and does not substitute the variable value when such characters appear in the value. 引数の中で逆引用符(`)に囲まれた文字列は、シェルに渡されるコマンド行として解釈されます。 逆引用符に囲まれた文字列は、コマンドの出力(行末の改行はすべて削除されます)で置換されます。 逆引用符に囲まれた文字列内では、:variable_nameという形式でvariable_namepsqlの変数名であるものが、その変数の値で置換されることを除いて、特別な引用やその他の処理は起きません。 また:'variable_name'という形式なら、それが変数値で置換された上で、それがシェルコマンドの単一の引数となるよう適切に引用符が付けられます。 (変数に何が入っているのか正確に理解しているのでなければ、ほとんどすべての場合で後者の形式の方が望ましいでしょう。) 復帰文字、改行文字をすべてのプラットフォームで安全に引用することはできないので、そのような文字が変数値に含まれていた場合は、:'variable_name'はエラーメッセージを表示し、変数値による置換を行いません。

Some commands take an <acronym>SQL</acronym> identifier (such as a table name) as argument. These arguments follow the syntax rules of <acronym>SQL</acronym>: Unquoted letters are forced to lowercase, while double quotes (<literal>"</literal>) protect letters from case conversion and allow incorporation of whitespace into the identifier. Within double quotes, paired double quotes reduce to a single double quote in the resulting name. For example, <literal>FOO"BAR"BAZ</literal> is interpreted as <literal>fooBARbaz</literal>, and <literal>"A weird"" name"</literal> becomes <literal>A weird" name</literal>. コマンドには、引数として(テーブル名などの)SQLの識別子を取るものがあります。 これらの引数は次のようなSQLの構文規則に従います。 引用符を伴わない文字は強制的に小文字になります。しかし、二重引用符(")で囲まれると、大文字小文字変換が行われず、空白文字を識別子内に含めることができます。 さらに、二重引用符内では、連続する2つの二重引用符は1つの二重引用符とみなされます。 例えば、FOO"BAR"BAZfooBARbazと解釈され、"A weird"" name"A weird" nameになります。

Parsing for arguments stops at the end of the line, or when another unquoted backslash is found. An unquoted backslash is taken as the beginning of a new meta-command. The special sequence <literal>\\</literal> (two backslashes) marks the end of arguments and continues parsing <acronym>SQL</acronym> commands, if any. That way <acronym>SQL</acronym> and <application>psql</application> commands can be freely mixed on a line. But in any case, the arguments of a meta-command cannot continue beyond the end of the line. 引数の解析は行末または引用符で囲まれていないもう1つのバックスラッシュが見つかると終了します。 引用符がないバックスラッシュは新しいメタコマンドの始まりと解釈されます。 \\(バックスラッシュ2つ)という特別な文字の並びは引数の終わりを意味するので、SQLコマンドが残されている場合は、その解析を続けます。 このように、SQLコマンドとpsqlコマンドは1つの行に自由に混合して記述することができます。 しかし、あらゆる場合において、メタコマンドの引数は行をまたぐことはできません。

Many of the meta-commands act on the <firstterm>current query buffer</firstterm>. This is simply a buffer holding whatever SQL command text has been typed but not yet sent to the server for execution. This will include previous input lines as well as any text appearing before the meta-command on the same line. メタコマンドの多くは問い合わせバッファの上で動作します。 これは入力されたSQLコマンド文字列で、まだ実行のためにサーバに送信されていないものをすべて保持するだけのバッファです。 これには以前の入力行や、同じ行のメタコマンドより前に入力されたすべての文字列も含まれます。

The following meta-commands are defined: 以下のメタコマンドが定義されています。

\a #

If the current table output format is unaligned, it is switched to aligned. If it is not unaligned, it is set to unaligned. This command is kept for backwards compatibility. See <command>\pset</command> for a more general solution. 現在のテーブルの出力形式が「揃えない」になっていれば「揃える」に、 「揃える」になっていれば「揃えない」に設定します。 このコマンドは後方互換性を保持するためにあります。 より一般的な解決策は\psetを参照してください。

\bind [ parameter ] ... #

Sets query parameters for the next query execution, with the specified parameters passed for any parameter placeholders (<literal>$1</literal> etc.). 次の問い合わせ実行の問い合わせパラメータを設定します。指定されたパラメータはすべてのパラメータプレースホルダ($1など)に渡されます。

Example: 例:

INSERT INTO tbl1 VALUES ($1, $2) \bind 'first value' 'second value' \g

This also works for query-execution commands besides <literal>\g</literal>, such as <literal>\gx</literal> and <literal>\gset</literal>. これは、\gx\gsetのような、\g以外の問い合わせ実行コマンドにも有効です。

This command causes the extended query protocol (see <xref linkend="protocol-query-concepts"/>) to be used, unlike normal <application>psql</application> operation, which uses the simple query protocol. So this command can be useful to test the extended query protocol from psql. (The extended query protocol is used even if the query has no parameters and this command specifies zero parameters.) This command affects only the next query executed; all subsequent queries will use the simple query protocol by default. このコマンドは、通常のpsql操作とは異なり、拡張問い合わせプロトコル(55.1.2を参照)を使用します。通常は、簡易問い合わせプロトコルを使用します。 したがって、このコマンドは、psqlから拡張問い合わせプロトコルをテストするのに有用でしょう。 (拡張問い合わせプロトコルは、問い合わせにパラメータがなく、このコマンドがパラメータを指定していない場合でも使用されます。) このコマンドは、次に実行される問い合わせにのみ影響します。後続のすべての問い合わせは、デフォルトで簡易問い合わせプロトコルを使用します。

\c または \connect [ -reuse-previous=on|off ] [ dbname [ username ] [ host ] [ port ] | conninfo ] #

Establishes a new connection to a <productname>PostgreSQL</productname> server. The connection parameters to use can be specified either using a positional syntax (one or more of database name, user, host, and port), or using a <replaceable>conninfo</replaceable> connection string as detailed in <xref linkend="libpq-connstring"/>. If no arguments are given, a new connection is made using the same parameters as before. PostgreSQLサーバへの新規の接続を確立します。 接続のパラメータは、位置の構文(1つ以上のデータベース名、ユーザ、ホスト、ポート)、あるいはconninfo接続文字列で指定できます。後者の詳細は34.1.1で説明します。 引数が与えられなければ、新しい接続は以前と同じパラメータを使って作られます。

Specifying any of <replaceable class="parameter">dbname</replaceable>, <replaceable class="parameter">username</replaceable>, <replaceable class="parameter">host</replaceable> or <replaceable class="parameter">port</replaceable> as <literal>-</literal> is equivalent to omitting that parameter. dbnameusernamehostportのいずれについても-を指定するのは、パラメータを省略するのと同じになります。

The new connection can re-use connection parameters from the previous connection; not only database name, user, host, and port, but other settings such as <replaceable>sslmode</replaceable>. By default, parameters are re-used in the positional syntax, but not when a <replaceable>conninfo</replaceable> string is given. Passing a first argument of <literal>-reuse-previous=on</literal> or <literal>-reuse-previous=off</literal> overrides that default. If parameters are re-used, then any parameter not explicitly specified as a positional parameter or in the <replaceable>conninfo</replaceable> string is taken from the existing connection's parameters. An exception is that if the <replaceable>host</replaceable> setting is changed from its previous value using the positional syntax, any <replaceable>hostaddr</replaceable> setting present in the existing connection's parameters is dropped. Also, any password used for the existing connection will be re-used only if the user, host, and port settings are not changed. When the command neither specifies nor reuses a particular parameter, the <application>libpq</application> default is used. 新しい接続では以前の接続での接続パラメータを再利用できます。データベース名、ユーザ、ホスト、ポートだけでなく、sslmodeのようなその他の設定もです。 デフォルトでは、パラメータは位置の構文では再利用されますが、conninfo文字列が与えられた場合はそうではありません。 第一引数で-reuse-previous=onあるいは-reuse-previous=offを渡すことで、このデフォルトと異なる動作をさせることができます。 パラメータが再利用される場合、位置パラメータとして明示的に指定されなかったパラメータやconninfo文字列で指定されていないパラメータは、既存の接続のパラメータから取得されます。 例外は、host設定が位置の構文を使った以前の値から変更された場合に、既存の接続のパラメータにあるhostaddr設定が削除されることです。 また、既存の接続で使われたパスワードは、ユーザ、ホスト、ポート設定が変更されていない場合にのみ再利用されます。 コマンドで特定のパラメータを指定せず、かつ再利用もしない場合は、libpqのデフォルトが使用されます。

If the new connection is successfully made, the previous connection is closed. If the connection attempt fails (wrong user name, access denied, etc.), the previous connection will be kept if <application>psql</application> is in interactive mode. But when executing a non-interactive script, the old connection is closed and an error is reported. That may or may not terminate the script; if it does not, all database-accessing commands will fail until another <literal>\connect</literal> command is successfully executed. This distinction was chosen as a user convenience against typos on the one hand, and a safety mechanism that scripts are not accidentally acting on the wrong database on the other hand. Note that whenever a <literal>\connect</literal> command attempts to re-use parameters, the values re-used are those of the last successful connection, not of any failed attempts made subsequently. However, in the case of a non-interactive <literal>\connect</literal> failure, no parameters are allowed to be re-used later, since the script would likely be expecting the values from the failed <literal>\connect</literal> to be re-used. 新規接続に成功した場合、以前の接続は閉じられます。 接続の試行が(ユーザ名の間違いやアクセス拒否などの理由で)失敗した場合、psqlが対話式モードである場合、それまでの接続が保持されます。 非対話式スクリプトを実行している場合は、古い接続は閉じられエラーが報告されます。 これはスクリプトを終了させるかもしれませんし、させないかもしれません。終了させない場合、別の\connectコマンドが実行に成功するまで、データベースにアクセスするコマンドはすべて失敗します。 この実装の違いは、対話モードでは入力ミスに対するユーザの利便性を考慮し、非対話モードではスクリプトによって間違ったデータベースを操作することを防ぐための安全策を考慮した結果決められました。 \connectコマンドがパラメータの再利用を試す場合には、再利用する値は必ず最後に接続に成功したものであり、その後で試して失敗したものではないことに注意してください。 しかしながら、非対話モードで\connectが失敗した場合には、スクリプトは失敗した\connectから再利用する値を得ようとしますので、パラメータを後で再利用できません。

Examples: 例:

=> \c mydb myuser host.dom 6432
=> \c service=foo
=> \c "host=localhost port=5432 dbname=mydb connect_timeout=10 sslmode=disable"

=&gt; \c -reuse-previous=on sslmode=require    &#45;- changes only sslmode

=> \c -reuse-previous=on sslmode=require    -- sslmodeのみ変更
=> \c postgresql://tom@localhost/mydb?application_name=myapp
\C [ title ] #

Sets the title of any tables being printed as the result of a query or unset any such title. This command is equivalent to <literal>\pset title <replaceable class="parameter">title</replaceable></literal>. (The name of this command derives from <quote>caption</quote>, as it was previously only used to set the caption in an <acronym>HTML</acronym> table.) 問い合わせ結果として表示されるテーブルのタイトルの設定、または、タイトルの設定解除を行います。 このコマンドは、\pset title titleと同じ効力を持ちます。 (このコマンド名は標題(caption)に由来します。 以前はHTMLのテーブルの標題を設定するためだけに使われていたためです。)

\cd [ directory ] #

Changes the current working directory to <replaceable>directory</replaceable>. Without argument, changes to the current user's home directory. 現在の作業ディレクトリをdirectoryに変更します。 引数がない場合は、現在のユーザのホームディレクトリに変更します。

ヒント

To print your current working directory, use <literal>\! pwd</literal>. 現在の作業ディレクトリを表示するには、\! pwdを使用してください。

\conninfo #

Outputs information about the current database connection. 現在のデータベース接続に関する情報を出力します。

\copy { table [ ( column_list ) ] } from { 'filename' | program 'command' | stdin | pstdin } [ [ with ] ( option [, ...] ) ] [ where condition ]
\copy { table [ ( column_list ) ] | ( query ) } to { 'filename' | program 'command' | stdout | pstdout } [ [ with ] ( option [, ...] ) ] #

Performs a frontend (client) copy. This is an operation that runs an <acronym>SQL</acronym> <link linkend="sql-copy"><command>COPY</command></link> command, but instead of the server reading or writing the specified file, <application>psql</application> reads or writes the file and routes the data between the server and the local file system. This means that file accessibility and privileges are those of the local user, not the server, and no SQL superuser privileges are required. フロントエンド(クライアント)コピーを行います。 これはCOPY SQLコマンドを実行する操作ですが、サーバで指定ファイルに対する読み込みまたは書き込みを行うのではなく、psqlがファイルの読み書きや、サーバとローカルファイルシステム間のデータ送信を行います。 この場合、ファイルへのアクセス権限はサーバではなくローカルユーザのものを使用するので、SQLのスーパーユーザ権限は必要ありません。

When <literal>program</literal> is specified, <replaceable class="parameter">command</replaceable> is executed by <application>psql</application> and the data passed from or to <replaceable class="parameter">command</replaceable> is routed between the server and the client. Again, the execution privileges are those of the local user, not the server, and no SQL superuser privileges are required. programが指定された場合、commandpsqlにより実行され、commandから、または、commandへのデータはサーバとクライアント間を行き来します。 ここでも、実行権限はローカル側のユーザであり、サーバ側ではなく、SQLスーパーユーザ権限は必要とされません。

For <literal>\copy ... from stdin</literal>, data rows are read from the same source that issued the command, continuing until <literal>\.</literal> is read or the stream reaches <acronym>EOF</acronym>. This option is useful for populating tables in-line within an SQL script file. For <literal>\copy ... to stdout</literal>, output is sent to the same place as <application>psql</application> command output, and the <literal>COPY <replaceable>count</replaceable></literal> command status is not printed (since it might be confused with a data row). To read/write <application>psql</application>'s standard input or output regardless of the current command source or <literal>\o</literal> option, write <literal>from pstdin</literal> or <literal>to pstdout</literal>. \copy ... from stdinでは、データ行は、コマンドの発行源と同じところから、\.を読み取るまで、あるいは、ストリームがEOFに達するまで読み続けます。 このオプションは、SQLスクリプトファイルの内部でテーブルにデータを投入する場合に便利です。 \copy ... to stdoutでは、出力はpsqlコマンドの出力と同じところに送られますが、COPY countコマンドのステータスは表示されません(これはデータ行と混同してしまうかもしれないからです)。 コマンドの入力元や\oオプションに関わらず、psqlの標準入力や標準出力を読み書きするには、from pstdinあるいはto pstdoutと書いてください。

The syntax of this command is similar to that of the <acronym>SQL</acronym> <link linkend="sql-copy"><command>COPY</command></link> command. All options other than the data source/destination are as specified for <command>COPY</command>. Because of this, special parsing rules apply to the <command>\copy</command> meta-command. Unlike most other meta-commands, the entire remainder of the line is always taken to be the arguments of <command>\copy</command>, and neither variable interpolation nor backquote expansion are performed in the arguments. このコマンドの構文はSQLCOPYコマンドに似ています。 データの入力元と出力先以外のすべてのオプションはCOPYと同じです。 このため\copyメタコマンドには特別な解析規則が適用されていることに注意してください。 他のほとんどのメタコマンドとは異なり、行の残り部分の全体は常に\copyの引数として解釈され、引数内の変数の置換や逆引用符の展開は行われません。

ヒント

Another way to obtain the same result as <literal>\copy ... to</literal> is to use the <acronym>SQL</acronym> <literal>COPY ... TO STDOUT</literal> command and terminate it with <literal>\g <replaceable>filename</replaceable></literal> or <literal>\g |<replaceable>program</replaceable></literal>. Unlike <literal>\copy</literal>, this method allows the command to span multiple lines; also, variable interpolation and backquote expansion can be used. \copy ... toと同じ結果を得る他の方法はSQLCOPY ... TO STDOUTコマンドを使って、\g filename\g |programで終了することです。 \copyと違い、この方法はコマンドが複数行にわたっても良いですし、変数の置換や逆引用符の展開式も使用できます。

ヒント

These operations are not as efficient as the <acronym>SQL</acronym> <command>COPY</command> command with a file or program data source or destination, because all data must pass through the client/server connection. For large amounts of data the <acronym>SQL</acronym> command might be preferable. 全データがクライアント/サーバ接続を通らなければならないため、これらの操作は、ファイルやデータソースまたは宛先のプログラムを指定したSQLCOPYコマンドほどには効率的ではありません。 大量のデータにはSQLコマンドがより望ましいでしょう。

Shows the copyright and distribution terms of <productname>PostgreSQL</productname>. PostgreSQLの著作権および配布条項を表示します。

\crosstabview [ colV [ colH [ colD [ sortcolH ] ] ] ] #

Executes the current query buffer (like <literal>\g</literal>) and shows the results in a crosstab grid. The query must return at least three columns. The output column identified by <replaceable class="parameter">colV</replaceable> becomes a vertical header and the output column identified by <replaceable class="parameter">colH</replaceable> becomes a horizontal header. <replaceable class="parameter">colD</replaceable> identifies the output column to display within the grid. <replaceable class="parameter">sortcolH</replaceable> identifies an optional sort column for the horizontal header. 問い合わせのバッファを実行し(\gと同様)、その結果をクロス表形式で表示します。 問い合わせは少なくとも3つの列を返す必要があります。 colVで特定される出力列が縦方向のヘッダになり、colHで特定される出力列が横方向のヘッダになります。 colDは表内に表示される出力列を特定します。 オプションのsortcolHで水平方向のヘッダをソートする列を指定できます。

Each column specification can be a column number (starting at 1) or a column name. The usual SQL case folding and quoting rules apply to column names. If omitted, <replaceable class="parameter">colV</replaceable> is taken as column 1 and <replaceable class="parameter">colH</replaceable> as column 2. <replaceable class="parameter">colH</replaceable> must differ from <replaceable class="parameter">colV</replaceable>. If <replaceable class="parameter">colD</replaceable> is not specified, then there must be exactly three columns in the query result, and the column that is neither <replaceable class="parameter">colV</replaceable> nor <replaceable class="parameter">colH</replaceable> is taken to be <replaceable class="parameter">colD</replaceable>. それぞれの列の指定は、列番号(1から始まります)でも列名でも可能です。 列名については、通常のSQLの大文字小文字変換および引用の規則が適用されます。 省略した場合、colVは列1、colHは列2となります。 colHcolVとは異なるものでなければなりません。 colDを指定しない場合、問い合わせの結果にはちょうど3つの列がなければならず、colVでもcolHでもない列がcolDとなります。

The vertical header, displayed as the leftmost column, contains the values found in column <replaceable class="parameter">colV</replaceable>, in the same order as in the query results, but with duplicates removed. 縦方向のヘッダは一番左の列に表示され、colVの列にある値が問い合わせ結果と同じ順序で現れますが、重複するものは除かれます。

The horizontal header, displayed as the first row, contains the values found in column <replaceable class="parameter">colH</replaceable>, with duplicates removed. By default, these appear in the same order as in the query results. But if the optional <replaceable class="parameter">sortcolH</replaceable> argument is given, it identifies a column whose values must be integer numbers, and the values from <replaceable class="parameter">colH</replaceable> will appear in the horizontal header sorted according to the corresponding <replaceable class="parameter">sortcolH</replaceable> values. 横方向のヘッダは1行目に表示され、colHの列にある値が現れますが、重複するものは除かれます。 デフォルトでは、これらは問い合わせの結果と同じ順序で表示されます。 しかしオプションのsortcolH引数が指定された場合は、colHの値は対応するsortcolHの値に従ってソートされて横方向のヘッダに現れますが、sortcolHの列の値は整数値でなければなりません。

Inside the crosstab grid, for each distinct value <literal>x</literal> of <replaceable class="parameter">colH</replaceable> and each distinct value <literal>y</literal> of <replaceable class="parameter">colV</replaceable>, the cell located at the intersection <literal>(x,y)</literal> contains the value of the <literal>colD</literal> column in the query result row for which the value of <replaceable class="parameter">colH</replaceable> is <literal>x</literal> and the value of <replaceable class="parameter">colV</replaceable> is <literal>y</literal>. If there is no such row, the cell is empty. If there are multiple such rows, an error is reported. クロス表の内側では、colHのそれぞれの個別値xcolVのそれぞれの個別値yに対して、その交点(x,y)に位置するセルに、問い合わせの結果のcolHの値がxcolVの値がyである行のcolD列の値が現れます。 そのような行がなければ、セルは空欄になります。 そのような行が複数あると、エラーが報告されます。

\d[S+] [ pattern ] #

For each relation (table, view, materialized view, index, sequence, or foreign table) or composite type matching the <replaceable class="parameter">pattern</replaceable>, show all columns, their types, the tablespace (if not the default) and any special attributes such as <literal>NOT NULL</literal> or defaults. Associated indexes, constraints, rules, and triggers are also shown. For foreign tables, the associated foreign server is shown as well. (<quote>Matching the pattern</quote> is defined in <xref linkend="app-psql-patterns"/> below.) patternにマッチする各リレーション(テーブル、ビュー、マテリアライズドビュー、インデックス、シーケンス、外部テーブル)または複合型について、全ての列、列の型、テーブル空間(デフォルト以外を使用している場合)、NOT NULLやデフォルトなどの特別な属性を表示します。 関連付けられているインデックス、制約、ルールおよびトリガも表示されます。 外部テーブルでは関連する外部サーバも表示されます。 (パターンのマッチングについては後述のパターンで定義されています。)

For some types of relation, <literal>\d</literal> shows additional information for each column: column values for sequences, indexed expressions for indexes, and foreign data wrapper options for foreign tables. 一部の種類のリレーションでは、\dは各列について追加の情報を表示します。 例えば、シーケンスでは列の値、インデックスではインデックス式、外部テーブルでは外部データラッパーのオプションです。

The command form <literal>\d+</literal> is identical, except that more information is displayed: any comments associated with the columns of the table are shown, as is the presence of OIDs in the table, the view definition if the relation is a view, a non-default <link linkend="sql-altertable-replica-identity">replica identity</link> setting and the <link linkend="sql-create-access-method">access method</link> name if the relation has an access method. \d+というコマンド形式も同一ですが、より多くの情報を表示します。 こちらでは、テーブルの列に関連付けられたコメントやテーブルにOIDが存在するかどうか、リレーションがビューの場合はビューの定義、デフォルトと異なるreplica identityの設定、リレーションにアクセスメソッドがあるならアクセスメソッド名も表示されます。

By default, only user-created objects are shown; supply a pattern or the <literal>S</literal> modifier to include system objects. デフォルトではユーザが作成したオブジェクトのみが表示されます。 システムオブジェクトを含めるためには、パターンまたはS修飾子を付与してください。

注記

If <command>\d</command> is used without a <replaceable class="parameter">pattern</replaceable> argument, it is equivalent to <command>\dtvmsE</command> which will show a list of all visible tables, views, materialized views, sequences and foreign tables. This is purely a convenience measure. \dpattern引数なしで使用された場合は、\dtvmsEと同じ意味となり、可視である全てのテーブル、ビュー、マテリアライズドビュー、シーケンス、外部テーブルの一覧が表示されます。 これは純粋に利便性のためです。

\da[S] [ pattern ] #

Lists aggregate functions, together with their return type and the data types they operate on. If <replaceable class="parameter">pattern</replaceable> is specified, only aggregates whose names match the pattern are shown. By default, only user-created objects are shown; supply a pattern or the <literal>S</literal> modifier to include system objects. 集約関数と、その戻り値のデータ型、演算対象となるデータ型の一覧を表示します。 patternが指定された場合、そのパターンに名前がマッチする集約のみが表示されます。 デフォルトではユーザが作成したオブジェクトのみが表示されます。 システムオブジェクトを含めるためには、パターンまたはS修飾子を付与してください。

\dA[+] [ pattern ] #

Lists access methods. If <replaceable class="parameter">pattern</replaceable> is specified, only access methods whose names match the pattern are shown. If <literal>+</literal> is appended to the command name, each access method is listed with its associated handler function and description. アクセスメソッドの一覧を表示します。 patternが指定された場合は、そのパターンにマッチする名前のアクセスメソッドのみが表示されます。 コマンド名の後に+が付加された場合は、各メソッドに関連付けられたハンドラ関数および説明も表示されます。

\dAc[+] [access-method-pattern [input-type-pattern]] #

Lists operator classes (see <xref linkend="xindex-opclass"/>). If <replaceable class="parameter">access-method-pattern</replaceable> is specified, only operator classes associated with access methods whose names match that pattern are listed. If <replaceable class="parameter">input-type-pattern</replaceable> is specified, only operator classes associated with input types whose names match that pattern are listed. If <literal>+</literal> is appended to the command name, each operator class is listed with its associated operator family and owner. 演算子クラスの一覧を表示します(38.16.1を参照してください)。 access-method-patternが指定されていれば、そのパターンにマッチする名前のアクセスメソッドと関係する演算子クラスのみが表示されます。 input-type-patternが指定されていれば、そのパターンにマッチする名前の入力型と関係する演算子クラスのみが表示されます。 コマンド名の後に+が付加された場合は、各演算子クラスに関連付けられた演算子族および所有者も表示されます。

\dAf[+] [access-method-pattern [input-type-pattern]] #

Lists operator families (see <xref linkend="xindex-opfamily"/>). If <replaceable class="parameter">access-method-pattern</replaceable> is specified, only operator families associated with access methods whose names match that pattern are listed. If <replaceable class="parameter">input-type-pattern</replaceable> is specified, only operator families associated with input types whose names match that pattern are listed. If <literal>+</literal> is appended to the command name, each operator family is listed with its owner. 演算子族の一覧を表示します(38.16.5を参照してください)。 access-method-patternが指定されていれば、そのパターンにマッチする名前のアクセスメソッドと関係する演算子族のみが表示されます。 input-type-patternが指定されていれば、そのパターンにマッチする名前の入力型と関係する演算子族のみが表示されます。 コマンド名の後に+が付加された場合は、各演算子族に関連付けられた所有者も表示されます。

\dAo[+] [access-method-pattern [operator-family-pattern]] #

Lists operators associated with operator families (see <xref linkend="xindex-strategies"/>). If <replaceable class="parameter">access-method-pattern</replaceable> is specified, only members of operator families associated with access methods whose names match that pattern are listed. If <replaceable class="parameter">operator-family-pattern</replaceable> is specified, only members of operator families whose names match that pattern are listed. If <literal>+</literal> is appended to the command name, each operator is listed with its sort operator family (if it is an ordering operator). 演算子族に関連する演算子の一覧を表示します(38.16.2を参照してください)。 access-method-patternが指定されていれば、そのパターンにマッチする名前のアクセスメソッドと関係する演算子族のメンバーのみが表示されます。 operator-family-patternが指定されていれば、そのパターンにマッチする名前の演算子族のメンバーのみが表示されます。 コマンド名の後に+が付加された場合は、(順序演算子であれば)ソート演算子族も表示されます。

\dAp[+] [access-method-pattern [operator-family-pattern]] #

Lists support functions associated with operator families (see <xref linkend="xindex-support"/>). If <replaceable class="parameter">access-method-pattern</replaceable> is specified, only functions of operator families associated with access methods whose names match that pattern are listed. If <replaceable class="parameter">operator-family-pattern</replaceable> is specified, only functions of operator families whose names match that pattern are listed. If <literal>+</literal> is appended to the command name, functions are displayed verbosely, with their actual parameter lists. 演算子族に関連するサポート関数の一覧を表示します(38.16.3を参照してください)。 access-method-patternが指定されていれば、そのパターンにマッチする名前のアクセスメソッドと関係する演算子族の関数のみが表示されます。 operator-family-patternが指定されていれば、そのパターンにマッチする名前の演算子族の関数のみが表示されます。 コマンド名の後に+が付加された場合は、実際のパラメータの一覧を伴って、冗長に表示されます。

\db[+] [ pattern ] #

Lists tablespaces. If <replaceable class="parameter">pattern</replaceable> is specified, only tablespaces whose names match the pattern are shown. If <literal>+</literal> is appended to the command name, each tablespace is listed with its associated options, on-disk size, permissions and description. テーブル空間を一覧表示します。 patternが指定された場合、そのパターンに名前がマッチするテーブル空間のみが表示されます。 コマンド名に+が付与された場合、各テーブル空間に関連付けされたオプション、ディスク上のサイズ、権限、摘要についても表示します。

\dc[S+] [ pattern ] #

Lists conversions between character-set encodings. If <replaceable class="parameter">pattern</replaceable> is specified, only conversions whose names match the pattern are listed. By default, only user-created objects are shown; supply a pattern or the <literal>S</literal> modifier to include system objects. If <literal>+</literal> is appended to the command name, each object is listed with its associated description. 文字セット符号化方式間の変換の一覧を表示します。 patternが指定された場合、そのパターンに名前がマッチする変換のみが表示されます。 デフォルトではユーザが作成したオブジェクトのみが表示されます。 システムオブジェクトを含めるためには、パターンまたはS修飾子を付与してください。 コマンド名に+を付与すると、各オブジェクトに関連する説明を付けて表示します。

\dconfig[+] [ pattern ] #

Lists server configuration parameters and their values. If <replaceable class="parameter">pattern</replaceable> is specified, only parameters whose names match the pattern are listed. Without a <replaceable class="parameter">pattern</replaceable>, only parameters that are set to non-default values are listed. (Use <literal>\dconfig *</literal> to see all parameters.) If <literal>+</literal> is appended to the command name, each parameter is listed with its data type, context in which the parameter can be set, and access privileges (if non-default access privileges have been granted). サーバ構成パラメータとその値の一覧を表示します。 patternが指定されている場合は、そのパターンに名前がマッチするパラメータのみが一覧表示されます。 patternが指定されていない場合は、デフォルト以外の値に設定されているパラメータのみが一覧表示されます。 (すべてのパラメータを表示するには\dconfig *を使用してください。) コマンド名に+が追加されている場合は、各パラメータが、そのデータ型、パラメータを設定できるコンテキスト、および(デフォルト以外のアクセス権限が付与されている場合)アクセス権限とともに一覧表示されます。

\dC[+] [ pattern ] #

Lists type casts. If <replaceable class="parameter">pattern</replaceable> is specified, only casts whose source or target types match the pattern are listed. If <literal>+</literal> is appended to the command name, each object is listed with its associated description. 型キャストの一覧を表示します。 patternが指定された場合、そのパターンに元データ型または変換先データ型がマッチするキャストのみが表示されます。 コマンド名に+を付与すると、各オブジェクトに関連する説明を付けて表示します。

\dd[S] [ pattern ] #

Shows the descriptions of objects of type <literal>constraint</literal>, <literal>operator class</literal>, <literal>operator family</literal>, <literal>rule</literal>, and <literal>trigger</literal>. All other comments may be viewed by the respective backslash commands for those object types. constraintoperator classoperator familyruletriggerという種類のオブジェクトについての説明を表示します。 他のコメントはすべて、これらのオブジェクト種類用の対応するバックスラッシュコマンドによって表示されます。

<para><literal>\dd</literal> displays descriptions for objects matching the <replaceable class="parameter">pattern</replaceable>, or of visible objects of the appropriate type if no argument is given. But in either case, only objects that have a description are listed. By default, only user-created objects are shown; supply a pattern or the <literal>S</literal> modifier to include system objects.

\ddpatternにマッチするオブジェクトの説明を表示します。 引数が指定されていない場合は、適切な種類の可視なオブジェクトの説明を表示します。 どちらの場合でも、一覧に表示されるのは説明を持つオブジェクトのみです デフォルトではユーザが作成したオブジェクトのみが表示されます。 システムオブジェクトを含めるためには、パターンまたはS修飾子を付与してください。

Descriptions for objects can be created with the <link linkend="sql-comment"><command>COMMENT</command></link> <acronym>SQL</acronym> command. オブジェクトの説明はCOMMENT SQLコマンドを使用して作成することができます。

\dD[S+] [ pattern ] #

Lists domains. If <replaceable class="parameter">pattern</replaceable> is specified, only domains whose names match the pattern are shown. By default, only user-created objects are shown; supply a pattern or the <literal>S</literal> modifier to include system objects. If <literal>+</literal> is appended to the command name, each object is listed with its associated permissions and description. ドメインの一覧を表示します。 patternが指定された場合、ドメイン名がそのパターンにマッチするもののみが表示されます。 デフォルトではユーザが作成したオブジェクトのみが表示されます。 システムオブジェクトを含めるには、パターンを指定するか、あるいはS修飾子を付けてください。 コマンド名の後に+を付けた場合は、各オブジェクトの権限と説明も表示されます。

\ddp [ pattern ] #

Lists default access privilege settings. An entry is shown for each role (and schema, if applicable) for which the default privilege settings have been changed from the built-in defaults. If <replaceable class="parameter">pattern</replaceable> is specified, only entries whose role name or schema name matches the pattern are listed. デフォルトのアクセス権限設定を一覧表示します。 組み込みのデフォルトから権限設定が変更されたロール(および適切ならばスキーマも)ごとに1項目示されます。 patternが指定された場合、パターンにマッチするロール名またはスキーマ名の項目のみが表示されます。

The <link linkend="sql-alterdefaultprivileges"><command>ALTER DEFAULT PRIVILEGES</command></link> command is used to set default access privileges. The meaning of the privilege display is explained in <xref linkend="ddl-priv"/>. ALTER DEFAULT PRIVILEGESコマンドを使用して、デフォルトのアクセス権限を設定します。 権限表示の意味は5.7で説明します。

\dE[S+] [ pattern ]
\di[S+] [ pattern ]
\dm[S+] [ pattern ]
\ds[S+] [ pattern ]
\dt[S+] [ pattern ]
\dv[S+] [ pattern ] #

In this group of commands, the letters <literal>E</literal>, <literal>i</literal>, <literal>m</literal>, <literal>s</literal>, <literal>t</literal>, and <literal>v</literal> stand for foreign table, index, materialized view, sequence, table, and view, respectively. You can specify any or all of these letters, in any order, to obtain a listing of objects of these types. For example, <literal>\dti</literal> lists tables and indexes. If <literal>+</literal> is appended to the command name, each object is listed with its persistence status (permanent, temporary, or unlogged), physical size on disk, and associated description if any. If <replaceable class="parameter">pattern</replaceable> is specified, only objects whose names match the pattern are listed. By default, only user-created objects are shown; supply a pattern or the <literal>S</literal> modifier to include system objects. このコマンド群において、Eimstvという文字はそれぞれ、外部テーブル、インデックス、マテリアライズドビュー、シーケンス、テーブル、ビューを表します。 これらの種類のオブジェクトの一覧を表示するために、これらの文字の中の任意の文字またはすべてを任意の順番で指定することができます。 例えば、\dtiはテーブルとインデックスを列挙します。 +がコマンド名に付与された場合、各オブジェクトは、もしあれば永続性の状態(permanent、temporary、またはunlogged)、ディスク上の物理容量、関連する説明をつけて表示されます。 patternが指定されている場合は、パターンに名称がマッチする項目のみが表示されます。 デフォルトでは、ユーザが作成したオブジェクトのみが表示されます。 システムオブジェクトを含めるためにはパターンまたはS修飾子を付与してください。

\des[+] [ pattern ] #

Lists foreign servers (mnemonic: <quote>external servers</quote>). If <replaceable class="parameter">pattern</replaceable> is specified, only those servers whose name matches the pattern are listed. If the form <literal>\des+</literal> is used, a full description of each server is shown, including the server's access privileges, type, version, options, and description. 外部(foreign)サーバ(つまりexternal servers)を一覧表示します。 patternが指定されている場合は、名前がパターンにマッチするサーバのみが表示されます。 \des+構文が使用された場合、サーバのアクセス権限、型、バージョン、オプション、説明など各サーバの完全な説明が表示されます。

\det[+] [ pattern ] #

Lists foreign tables (mnemonic: <quote>external tables</quote>). If <replaceable class="parameter">pattern</replaceable> is specified, only entries whose table name or schema name matches the pattern are listed. If the form <literal>\det+</literal> is used, generic options and the foreign table description are also displayed. 外部(foreign)テーブル(つまりexternal tables)を一覧表示します。 patternが指定された場合、パターンにテーブル名またはスキーマ名がマッチするもののみが表示されます。 \det+が使用された場合、汎用オプションと外部テーブルの説明も表示されます。

\deu[+] [ pattern ] #

Lists user mappings (mnemonic: <quote>external users</quote>). If <replaceable class="parameter">pattern</replaceable> is specified, only those mappings whose user names match the pattern are listed. If the form <literal>\deu+</literal> is used, additional information about each mapping is shown. ユーザマップ(つまりexternal users)を一覧表示します。 patternが指定されている場合は、名前がパターンにマッチするユーザのみが表示されます。 \deu+構文が使用された場合、各マップについて追加情報が表示されます。

注意

<literal>\deu+</literal> might also display the user name and password of the remote user, so care should be taken not to disclose them. \deu+ではリモートユーザのユーザ名とパスワードも表示される可能性があります。 これらを外部に曝さないように注意しなければなりません。

\dew[+] [ pattern ] #

Lists foreign-data wrappers (mnemonic: <quote>external wrappers</quote>). If <replaceable class="parameter">pattern</replaceable> is specified, only those foreign-data wrappers whose name matches the pattern are listed. If the form <literal>\dew+</literal> is used, the access privileges, options, and description of the foreign-data wrapper are also shown. 外部データラッパー(つまりexternal wrappers)を一覧表示します。 patternが指定されている場合、名前がパターンにマッチする外部データラッパーのみが表示されます。 \dew+構文が使用された場合、外部データラッパーのアクセス権限、オプションおよび説明も表示されます。

\df[anptwS+] [ pattern [ arg_pattern ... ] ] #

Lists functions, together with their result data types, argument data types, and function types, which are classified as <quote>agg</quote> (aggregate), <quote>normal</quote>, <quote>procedure</quote>, <quote>trigger</quote>, or <quote>window</quote>. To display only functions of specific type(s), add the corresponding letters <literal>a</literal>, <literal>n</literal>, <literal>p</literal>, <literal>t</literal>, or <literal>w</literal> to the command. If <replaceable class="parameter">pattern</replaceable> is specified, only functions whose names match the pattern are shown. Any additional arguments are type-name patterns, which are matched to the type names of the first, second, and so on arguments of the function. (Matching functions can have more arguments than what you specify. To prevent that, write a dash <literal>-</literal> as the last <replaceable class="parameter">arg_pattern</replaceable>.) By default, only user-created objects are shown; supply a pattern or the <literal>S</literal> modifier to include system objects. If the form <literal>\df+</literal> is used, additional information about each function is shown, including volatility, parallel safety, owner, security classification, access privileges, language, internal name (for C and internal functions only), and description. Source code for a specific function can be seen using <literal>\sf</literal>. 関数とその結果のデータ型、引数のデータ型、および、agg (集約)、normalproceduretriggerwindowで分類される関数の種類の一覧を表示します。 特定種類の関数のみを表示させるには、対応する文字anptwをコマンドに付けて下さい。 patternが指定されている場合は、そのパターンに名前がマッチする関数のみが表示されます。 追加の引数は、型名のパターンで、関数の第1、第2などの引数の型名にマッチします。 (マッチする関数は指定したものよりも多くの引数を取るかもしれません。 それを防ぐには、arg_patternの最後にダッシュ-を書いてください。) デフォルトではユーザが作成したオブジェクトのみが表示されます。 システムオブジェクトを含めるためには、パターンまたはS修飾子を付与してください。 \df+構文が使われた場合、各関数の、揮発性、並列処理での安全性、所有者、セキュリティ分類、アクセス権限、言語、内部名(Cと内部関数に対してのみ)や説明を含む付加的情報も表示されます。 特定の関数のソースコードは\sfを使って見ることができます。

\dF[+] [ pattern ] #

Lists text search configurations. If <replaceable class="parameter">pattern</replaceable> is specified, only configurations whose names match the pattern are shown. If the form <literal>\dF+</literal> is used, a full description of each configuration is shown, including the underlying text search parser and the dictionary list for each parser token type. 全文検索設定を一覧表示します。 patternが指定された場合、このパターンにマッチする名前の設定のみが表示されます。 \dF+形式が使用された場合、使用される全文検索パーサや各パーサトークン型についての辞書リストなど各設定の完全な説明が表示されます。

\dFd[+] [ pattern ] #

Lists text search dictionaries. If <replaceable class="parameter">pattern</replaceable> is specified, only dictionaries whose names match the pattern are shown. If the form <literal>\dFd+</literal> is used, additional information is shown about each selected dictionary, including the underlying text search template and the option values. 全文検索辞書を一覧表示します。 patternが指定された場合、このパターンにマッチする名前の辞書のみが表示されます。 \dFd+形式が使用された場合、選択された辞書それぞれについて使用される全文検索テンプレートやオプション値など更なる情報が表示されます。

\dFp[+] [ pattern ] #

Lists text search parsers. If <replaceable class="parameter">pattern</replaceable> is specified, only parsers whose names match the pattern are shown. If the form <literal>\dFp+</literal> is used, a full description of each parser is shown, including the underlying functions and the list of recognized token types. 全文検索パーサを一覧表示します。 patternが指定された場合、このパターンにマッチする名前のパーサのみが表示されます。 \dFp+形式が使用された場合、使用される関数や認知されるトークン型のリストなど各パーサの完全な説明が表示されます。

\dFt[+] [ pattern ] #

Lists text search templates. If <replaceable class="parameter">pattern</replaceable> is specified, only templates whose names match the pattern are shown. If the form <literal>\dFt+</literal> is used, additional information is shown about each template, including the underlying function names. テキスト検索テンプレートを一覧表示します。 patternが指定された場合、このパターンにマッチする名前のテンプレートのみが表示されます。 \dFt+形式が使用された場合、テンプレートそれぞれについて使用される関数名など更なる情報が表示されます。

\dg[S+] [ pattern ] #

Lists database roles. (Since the concepts of <quote>users</quote> and <quote>groups</quote> have been unified into <quote>roles</quote>, this command is now equivalent to <literal>\du</literal>.) By default, only user-created roles are shown; supply the <literal>S</literal> modifier to include system roles. If <replaceable class="parameter">pattern</replaceable> is specified, only those roles whose names match the pattern are listed. If the form <literal>\dg+</literal> is used, additional information is shown about each role; currently this adds the comment for each role. データベースロールを一覧表示します。 (ユーザグループという概念はロールに統合されましたので、このコマンドは\duと同じものになりました。) デフォルトでは、ユーザによって作成されたロールのみが表示されます。 システムロールを含めるにはS修飾子を付与してください。 patternが指定されている場合は、そのパターンに名前がマッチするロールのみが表示されます。 \dg+構文が使用された場合、ロールそれぞれについて更なる情報が表示されます。 現時点では各ロールのコメントが追加されます。

\dl[+] #

This is an alias for <command>\lo_list</command>, which shows a list of large objects. If <literal>+</literal> is appended to the command name, each large object is listed with its associated permissions, if any. \lo_listの別名で、ラージオブジェクトの一覧を表示します。 コマンド名に+が追加されている場合は、各ラージオブジェクトが、もしあれば関連する権限とともに一覧表示されます。

\dL[S+] [ pattern ] #

Lists procedural languages. If <replaceable class="parameter">pattern</replaceable> is specified, only languages whose names match the pattern are listed. By default, only user-created languages are shown; supply the <literal>S</literal> modifier to include system objects. If <literal>+</literal> is appended to the command name, each language is listed with its call handler, validator, access privileges, and whether it is a system object. 手続き言語を一覧表示します。 patternを指定すると、パターンに名前がマッチする言語のみが表示されます。 デフォルトではユーザが作成した言語のみが表示されます。 システムオブジェクトを含めるためには、パターンまたはS修飾子を付与してください。 +をコマンド名に追加すると、呼び出しハンドラ、有効性検証関数、アクセス権限、システムオブジェクトか否かという情報を付けて各言語が表示されます。

\dn[S+] [ pattern ] #

Lists schemas (namespaces). If <replaceable class="parameter">pattern</replaceable> is specified, only schemas whose names match the pattern are listed. By default, only user-created objects are shown; supply a pattern or the <literal>S</literal> modifier to include system objects. If <literal>+</literal> is appended to the command name, each object is listed with its associated permissions and description, if any. スキーマ(名前空間)の一覧を表示します。 patternを指定すると、パターンに名前がマッチするスキーマのみが表示されます。 デフォルトではユーザが作成したオブジェクトのみが表示されます。 パターンまたはS修飾子を追加すると、システムオブジェクトが表示に追加されます。 コマンド名の後に+を付加すると、各オブジェクトに関連付けられている権限と説明が(存在すれば)表示されます。

\do[S+] [ pattern [ arg_pattern [ arg_pattern ] ] ] #

Lists operators with their operand and result types. If <replaceable class="parameter">pattern</replaceable> is specified, only operators whose names match the pattern are listed. If one <replaceable class="parameter">arg_pattern</replaceable> is specified, only prefix operators whose right argument's type name matches that pattern are listed. If two <replaceable class="parameter">arg_pattern</replaceable>s are specified, only binary operators whose argument type names match those patterns are listed. (Alternatively, write <literal>-</literal> for the unused argument of a unary operator.) By default, only user-created objects are shown; supply a pattern or the <literal>S</literal> modifier to include system objects. If <literal>+</literal> is appended to the command name, additional information about each operator is shown, currently just the name of the underlying function. 演算子と、その演算項目と結果の型を一覧表示します。 patternを指定すると、パターンに名前がマッチする演算子のみが表示されます。 arg_patternを1つ指定すると、パターンに右辺の引数の型名がマッチする前置演算子のみが表示されます。 arg_patternを2つ指定すると、パターンに引数の型名がマッチする二項演算子のみが表示されます。 (あるいは、単項演算子の使われない引数に対して-と書いてください。) デフォルトではユーザが作成したオブジェクトのみが表示されます。 システムオブジェクトを含めるためには、パターンまたはS修飾子を付与してください。 コマンド名に+を付加すると、各演算子についての追加情報が表示されますが、現在はその元になっている関数の名前だけです。

\dO[S+] [ pattern ] #

Lists collations. If <replaceable class="parameter">pattern</replaceable> is specified, only collations whose names match the pattern are listed. By default, only user-created objects are shown; supply a pattern or the <literal>S</literal> modifier to include system objects. If <literal>+</literal> is appended to the command name, each collation is listed with its associated description, if any. Note that only collations usable with the current database's encoding are shown, so the results may vary in different databases of the same installation. 照合順序を一覧表示します。 patternを指定すると、パターンに名前がマッチする照合順序のみが表示されます。 デフォルトではユーザが作成したオブジェクトのみが表示されます。 システムオブジェクトを含めるためには、パターンまたはS修飾子を付与してください。 コマンド名の後に+を付加すると、各照合順序に関連付けられている説明が(存在すれば)表示されます。 現在のデータベースの符号化方式で使用できる照合順序のみが表示されることに注意してください。 このため同じインストレーションであってもデータベースによって結果が異なる可能性があります。

\dp[S] [ pattern ] #

Lists tables, views and sequences with their associated access privileges. If <replaceable class="parameter">pattern</replaceable> is specified, only tables, views and sequences whose names match the pattern are listed. By default only user-created objects are shown; supply a pattern or the <literal>S</literal> modifier to include system objects. 集約関数と、その戻り値のデータ型、演算対象となるデータ型の一覧を表示します。 patternが指定された場合、そのパターンに名前がマッチする集約のみが表示されます。 デフォルトではユーザが作成したオブジェクトのみが表示されます。 システムオブジェクトを含めるためには、パターンまたはS修飾子を付与してください。

The <link linkend="sql-grant"><command>GRANT</command></link> and <link linkend="sql-revoke"><command>REVOKE</command></link> commands are used to set access privileges. The meaning of the privilege display is explained in <xref linkend="ddl-priv"/>. アクセス権限の設定にはGRANTコマンドとREVOKEコマンドが使われます。 権限の表示に関する意味は5.7で説明します。

\dP[itn+] [ pattern ] #

Lists partitioned relations. If <replaceable class="parameter">pattern</replaceable> is specified, only entries whose name matches the pattern are listed. The modifiers <literal>t</literal> (tables) and <literal>i</literal> (indexes) can be appended to the command, filtering the kind of relations to list. By default, partitioned tables and indexes are listed. パーティション化されたリレーションの一覧を表示します。 patternが指定されている場合は、名前がパターンにマッチするエントリのみが表示されます。 修飾子t(テーブル)とi(インデックス)をコマンドに付けて、表示されるリレーションの種類を限定できます。 デフォルトでは、パーティション化されたテーブルとインデックスの一覧が表示されます。

If the modifier <literal>n</literal> (<quote>nested</quote>) is used, or a pattern is specified, then non-root partitioned relations are included, and a column is shown displaying the parent of each partitioned relation. 修飾子n (nested)が使われた、もしくはパターンが指定された場合、ルートでないパーティション化されたリレーションが含められ、各パーティション化されたリレーションの親を表示しながら列が表示されます。

If <literal>+</literal> is appended to the command name, the sum of the sizes of each relation's partitions is also displayed, along with the relation's description. If <literal>n</literal> is combined with <literal>+</literal>, two sizes are shown: one including the total size of directly-attached leaf partitions, and another showing the total size of all partitions, including indirectly attached sub-partitions. コマンド名の後に+が付けられた場合、リレーションの説明と一緒に、各リレーションのパーティションの大きさの合計も表示されます。 n+と組み合わされた場合、大きさが2つ表示されます。1つは直接アタッチされたリーフパーティションの合計の大きさで、もう1つは間接的にアタッチされたサブパーティションを含む全パーティションの合計の大きさです。

\drds [ role-pattern [ database-pattern ] ] #

Lists defined configuration settings. These settings can be role-specific, database-specific, or both. <replaceable>role-pattern</replaceable> and <replaceable>database-pattern</replaceable> are used to select specific roles and databases to list, respectively. If omitted, or if <literal>*</literal> is specified, all settings are listed, including those not role-specific or database-specific, respectively. 定義済み設定に関する設定を一覧表示します。 これらの設定はロール固有、データベース固有、またはその両方です。 role-patternおよびdatabase-patternはそれぞれ特定のロールやデータベースを選択するために使用します。 パターンが省略された場合、または*が指定された場合、ロール固有ではない、または、データベース固有ではない設定を含め、すべての設定を表示します。

The <link linkend="sql-alterrole"><command>ALTER ROLE</command></link> and <link linkend="sql-alterdatabase"><command>ALTER DATABASE</command></link> commands are used to define per-role and per-database configuration settings. ロール単位およびデータベース単位の設定を定義するにはALTER ROLEおよびALTER DATABASEコマンドを使用します。

\drg[S] [ pattern ] #

Lists information about each granted role membership, including assigned options (<literal>ADMIN</literal>, <literal>INHERIT</literal> and/or <literal>SET</literal>) and grantor. See the <link linkend="sql-grant"><command>GRANT</command></link> command for information about role memberships. 割り当てられたオプション(ADMININHERITSET)および権限付与者を含む、付与されたロールのメンバ資格に関する情報を一覧表示します。 ロールのメンバ資格の詳細は、GRANTコマンドを参照してください。

By default, only grants to user-created roles are shown; supply the <literal>S</literal> modifier to include system roles. If <replaceable class="parameter">pattern</replaceable> is specified, only grants to those roles whose names match the pattern are listed. デフォルトではユーザが作成したロールへの権限付与のみが表示されます。システムロールを含めるにはS修飾子を付与してください。 パターンが指定されている場合は、パターンにマッチする名前のロールへの権限付与のみが表示されます。

\dRp[+] [ pattern ] #

Lists replication publications. If <replaceable class="parameter">pattern</replaceable> is specified, only those publications whose names match the pattern are listed. If <literal>+</literal> is appended to the command name, the tables and schemas associated with each publication are shown as well. レプリケーションのパブリケーションを一覧表示します。 patternが指定された場合、名前がそのパターンにマッチするパブリケーションのみが表示されます。 コマンド名の後に+が付けられた場合、各パブリケーションに関連付けられているテーブルやスキーマも表示されます。

\dRs[+] [ pattern ] #

Lists replication subscriptions. If <replaceable class="parameter">pattern</replaceable> is specified, only those subscriptions whose names match the pattern are listed. If <literal>+</literal> is appended to the command name, additional properties of the subscriptions are shown. レプリケーションのサブスクリプションを一覧を表示します。 patternが指定された場合、名前がそのパターンにマッチするサブスクリプションのみが表示されます。 コマンド名の後に+が付けられた場合、サブスクリプションの追加属性も表示されます。

\dT[S+] [ pattern ] #

Lists data types. If <replaceable class="parameter">pattern</replaceable> is specified, only types whose names match the pattern are listed. If <literal>+</literal> is appended to the command name, each type is listed with its internal name and size, its allowed values if it is an <type>enum</type> type, and its associated permissions. By default, only user-created objects are shown; supply a pattern or the <literal>S</literal> modifier to include system objects. データ型を一覧表示します。 patternを指定すると、パターンにマッチする名前を持つ型のみを表示します。 +をコマンド名に付けると、型ごとに、型の内部名、サイズ、enum型では許される値、関連する権限も表示されます。 デフォルトではユーザが作成したオブジェクトのみが表示されます。 システムオブジェクトを含めるためには、パターンまたはS修飾子を付与してください。

\du[S+] [ pattern ] #

Lists database roles. (Since the concepts of <quote>users</quote> and <quote>groups</quote> have been unified into <quote>roles</quote>, this command is now equivalent to <literal>\dg</literal>.) By default, only user-created roles are shown; supply the <literal>S</literal> modifier to include system roles. If <replaceable class="parameter">pattern</replaceable> is specified, only those roles whose names match the pattern are listed. If the form <literal>\du+</literal> is used, additional information is shown about each role; currently this adds the comment for each role. データベースロールを一覧表示します。 (ユーザグループという概念はロールに統合されましたので、このコマンドは\dgと同じものになりました。) patternが指定されている場合は、そのパターンに名前がマッチするロールのみが表示されます。 デフォルトでは、ユーザによって作成されたロールのみが表示されます。 システムロールを含めるにはS修飾子を付与してください。 \du+構文が使用された場合、ロールそれぞれについて更なる情報が表示されます。 現時点では各ロールのコメントが追加されます。

\dx[+] [ pattern ] #

Lists installed extensions. If <replaceable class="parameter">pattern</replaceable> is specified, only those extensions whose names match the pattern are listed. If the form <literal>\dx+</literal> is used, all the objects belonging to each matching extension are listed. インストールされた拡張を一覧表示します。 patternを指定すると、パターンにマッチする名前の拡張のみを表示します。 \dx+形式が使用された場合、マッチする拡張それぞれについて拡張に属するすべてのオブジェクトが表示されます。

\dX [ pattern ] #

Lists extended statistics. If <replaceable class="parameter">pattern</replaceable> is specified, only those extended statistics whose names match the pattern are listed. 拡張統計情報を一覧表示します。 patternが指定されている場合は、そのパターンに名前がマッチする拡張統計情報のみが表示されます。

The status of each kind of extended statistics is shown in a column named after its statistic kind (e.g. Ndistinct). <literal>defined</literal> means that it was requested when creating the statistics, and NULL means it wasn't requested. You can use <structname>pg_stats_ext</structname> if you'd like to know whether <link linkend="sql-analyze"><command>ANALYZE</command></link> was run and statistics are available to the planner. 拡張統計情報の各種の状態は、その統計値の種類(例えば、Ndistinct)にちなんだ名前の列に表示されます。 definedはその統計情報の作成が要求されたことを意味し、NULLは要求されていないことを意味します。 ANALYZEが実行され、統計情報がプランナで利用可能であるかどうかを知るには、pg_stats_extが使えます。

\dy[+] [ pattern ] #

Lists event triggers. If <replaceable class="parameter">pattern</replaceable> is specified, only those event triggers whose names match the pattern are listed. If <literal>+</literal> is appended to the command name, each object is listed with its associated description. イベントトリガを一覧表示します。 patternを指定すると、パターンにマッチする名前のイベントトリガのみを表示します。 +をコマンド名に追記すると、関連する説明を付けて各オブジェクトを表示します。

\eまたは\edit [ filename ] [ line_number ] #

If <replaceable class="parameter">filename</replaceable> is specified, the file is edited; after the editor exits, the file's content is copied into the current query buffer. If no <replaceable class="parameter">filename</replaceable> is given, the current query buffer is copied to a temporary file which is then edited in the same fashion. Or, if the current query buffer is empty, the most recently executed query is copied to a temporary file and edited in the same fashion. filenameが指定された場合、このファイルが編集されます。 エディタを終了した後、ファイルの内容は問い合わせバッファにコピーされます。 filenameが指定されない場合、現在の問い合わせバッファが一時ファイルにコピーされ、同様に編集されます。 現在の問い合わせバッファが空の場合、最も最近に実行された問い合わせが一時ファイルにコピーされ、同様に編集されます。

If you edit a file or the previous query, and you quit the editor without modifying the file, the query buffer is cleared. Otherwise, the new contents of the query buffer are re-parsed according to the normal rules of <application>psql</application>, treating the whole buffer as a single line. Any complete queries are immediately executed; that is, if the query buffer contains or ends with a semicolon, everything up to that point is executed and removed from the query buffer. Whatever remains in the query buffer is redisplayed. Type semicolon or <literal>\g</literal> to send it, or <literal>\r</literal> to cancel it by clearing the query buffer. ファイルや以前の問い合わせを編集していて、ファイルを変更せずにエディタを終了した場合には、問い合わせバッファはクリアされます。 そうでなければ、問い合わせバッファの新しい内容が、psqlの通常の規則に従い、全体を1行として再解析されます。 完全な問い合わせはすべて即座に実行されます。 つまり、問い合わせバッファにセミコロンが含まれるか、セミコロンで終わっている場合、そこまでの部分すべてが実行され、問い合わせバッファから削除されます。 問い合わせバッファ内に残ったものはすべて再表示されます。 送信するにはセミコロンまたは\gを、問い合わせバッファをクリアしてキャンセルするには\rを入力してください。

Treating the buffer as a single line primarily affects meta-commands: whatever is in the buffer after a meta-command will be taken as argument(s) to the meta-command, even if it spans multiple lines. (Thus you cannot make meta-command-using scripts this way. Use <command>\i</command> for that.) バッファ全体を1行として扱うので、特にメタコマンドに影響があります。 バッファ内でメタコマンドより後にある部分はすべて、それが複数行にまたがっていたとしても、メタコマンドの引数として解釈されます。 (従って、この方法ではメタコマンドを使用するスクリプトを作成できません。 その目的の場合は、\iを使ってください。)

If a line number is specified, <application>psql</application> will position the cursor on the specified line of the file or query buffer. Note that if a single all-digits argument is given, <application>psql</application> assumes it is a line number, not a file name. 行番号(line_number)が指定された場合、psqlはファイルまたは問い合わせバッファ内の指定行にカーソルを位置づけます。 すべてが数字の引数が1つだけ指定された場合、psqlはそれをファイル名ではなく行番号であるとみなすことに注意してください。

ヒント

See <xref linkend="app-psql-environment"/>, below, for how to configure and customize your editor. 使用するエディタを設定、カスタマイズする方法については、下記の環境を参照してください。

\echo text [ ... ] #

Prints the evaluated arguments to standard output, separated by spaces and followed by a newline. This can be useful to intersperse information in the output of scripts. For example: 評価された引数を空白で区切り、標準出力に出力し、改行します。 スクリプトが出力するところどころに情報を記載する場合に有用です。 使用例を次に示します。

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

If the first argument is an unquoted <literal>-n</literal> the trailing newline is not written (nor is the first argument). 最初の引数が引用符で囲まれていない-nである場合、最後の改行は出力されません(し、最初の引数も出力されません)。

ヒント

If you use the <command>\o</command> command to redirect your query output you might wish to use <command>\qecho</command> instead of this command. See also <command>\warn</command>. \oコマンドを使用して問い合わせの出力先を変更した場合、このコマンドではなく、\qechoを使用した方が良いかもしれません。 \warnコマンドも参照してください。

\ef [ function_description [ line_number ] ] #

This command fetches and edits the definition of the named function or procedure, in the form of a <command>CREATE OR REPLACE FUNCTION</command> or <command>CREATE OR REPLACE PROCEDURE</command> command. Editing is done in the same way as for <literal>\edit</literal>. If you quit the editor without saving, the statement is discarded. If you save and exit the editor, the updated command is executed immediately if you added a semicolon to it. Otherwise it is redisplayed; type semicolon or <literal>\g</literal> to send it, or <literal>\r</literal> to cancel. このコマンドは指定された関数やプロシージャの定義をCREATE OR REPLACE FUNCTIONCREATE OR REPLACE PROCEDUREコマンド構文で取り出し、編集します。 編集は\editと同様の方法で行われます。 保存しないでエディタを終了すると、その文は捨てられます。 保存してエディタを終了すると、更新されたコマンドはセミコロンを付けていれば即座に実行されます。 そうでなければ再表示されます。送信するにはセミコロンあるいは\gを、キャンセルするには\rを入力してください。

The target function can be specified by name alone, or by name and arguments, for example <literal>foo(integer, text)</literal>. The argument types must be given if there is more than one function of the same name. 対象の関数は名前だけ、または、たとえばfoo(integer, text)のように名前と引数で指定することができます。 同じ名前の関数が複数存在する場合、引数の型を指定しなければなりません。

If no function is specified, a blank <command>CREATE FUNCTION</command> template is presented for editing. 関数が指定されなかった場合、空のCREATE FUNCTIONのテンプレートが編集用に表示されます。

If a line number is specified, <application>psql</application> will position the cursor on the specified line of the function body. (Note that the function body typically does not begin on the first line of the file.) 行番号が指定された場合、psqlは関数本体における指定行にカーソルを移動します。 (関数本体は通常、ファイルの先頭から始まらないことに注意してください。)

Unlike most other meta-commands, the entire remainder of the line is always taken to be the argument(s) of <command>\ef</command>, and neither variable interpolation nor backquote expansion are performed in the arguments. 他のほとんどのメタコマンドと異なり、行の残り部分はすべて\efの引数であると常に解釈され、引数内の変数の置換も逆引用符の展開も行われません。

ヒント

See <xref linkend="app-psql-environment"/>, below, for how to configure and customize your editor. 使用するエディタを設定、カスタマイズする方法については下記の環境を参照してください。

\encoding [ encoding ] #

Sets the client character set encoding. Without an argument, this command shows the current encoding. クライアント側の文字セット符号化方式を設定します。 引数を指定しない場合、このコマンドは現在の符号化方式を表示します。

\errverbose #

Repeats the most recent server error message at maximum verbosity, as though <varname>VERBOSITY</varname> were set to <literal>verbose</literal> and <varname>SHOW_CONTEXT</varname> were set to <literal>always</literal>. 最も最近のサーバのエラーメッセージを最大の冗長さ、つまりVERBOSITYverboseに、そしてSHOW_CONTEXTalwaysに設定されているかのようにして、繰り返します。

\ev [ view_name [ line_number ] ] #

This command fetches and edits the definition of the named view, in the form of a <command>CREATE OR REPLACE VIEW</command> command. Editing is done in the same way as for <literal>\edit</literal>. If you quit the editor without saving, the statement is discarded. If you save and exit the editor, the updated command is executed immediately if you added a semicolon to it. Otherwise it is redisplayed; type semicolon or <literal>\g</literal> to send it, or <literal>\r</literal> to cancel. このコマンドは、指定したビューの定義をCREATE OR REPLACE VIEWコマンドの形式で取得して、編集します。 編集は\editの場合と同じ方法で行われます。 保存しないでエディタを終了すると、その文は捨てられます。 保存してエディタを終了すると、更新されたコマンドはセミコロンを付けていれば即座に実行されます。 そうでなければ再表示されます。送信するにはセミコロンあるいは\gを、キャンセルするには\rを入力してください。

If no view is specified, a blank <command>CREATE VIEW</command> template is presented for editing. ビューを指定しなかった場合は、空のCREATE VIEWテンプレートが編集用に提供されます。

If a line number is specified, <application>psql</application> will position the cursor on the specified line of the view definition. 行番号を指定した場合、psqlはカーソルをビュー定義の指定した行に位置づけます。

Unlike most other meta-commands, the entire remainder of the line is always taken to be the argument(s) of <command>\ev</command>, and neither variable interpolation nor backquote expansion are performed in the arguments. 他のほとんどのメタコマンドと異なり、行の残り部分はすべて\evの引数であると常に解釈され、引数内の変数の置換も逆引用符の展開も行われません。

\f [ string ] #

Sets the field separator for unaligned query output. The default is the vertical bar (<literal>|</literal>). It is equivalent to <command>\pset fieldsep</command>. 位置揃えされていない問い合わせの出力用の、フィールドの区切り文字を設定します。 デフォルトは、縦棒(|)です。 これは\pset fieldsepと同じです。

\g [ (option=value [...]) ] [ filename ]
\g [ (option=value [...]) ] [ |command ] #

Sends the current query buffer to the server for execution. 現在の問い合わせ入力バッファをサーバに送って実行します。

If parentheses appear after <literal>\g</literal>, they surround a space-separated list of <replaceable class="parameter">option</replaceable><literal>=</literal><replaceable class="parameter">value</replaceable> formatting-option clauses, which are interpreted in the same way as <literal>\pset</literal> <replaceable class="parameter">option</replaceable> <replaceable class="parameter">value</replaceable> commands, but take effect only for the duration of this query. In this list, spaces are not allowed around <literal>=</literal> signs, but are required between option clauses. If <literal>=</literal><replaceable class="parameter">value</replaceable> is omitted, the named <replaceable class="parameter">option</replaceable> is changed in the same way as for <literal>\pset</literal> <replaceable class="parameter">option</replaceable> with no explicit <replaceable class="parameter">value</replaceable>. \gの後に括弧が現れる場合は、括弧はoption=value書式オプション句の空白で区切られた一覧を囲んでいます。書式オプション句は\pset option valueコマンドと同じように解釈されますが、この問い合わせの間でのみ有効です。 この一覧の中では、空白は=の周りでは許されていませんが、オプション句の間には必要です。 =valueが省略された場合、指名されたoptionは、明示されたvalueがない\pset optionと同じように変更されます。

If a <replaceable class="parameter">filename</replaceable> or <literal>|</literal><replaceable class="parameter">command</replaceable> argument is given, the query's output is written to the named file or piped to the given shell command, instead of displaying it as usual. The file or command is written to only if the query successfully returns zero or more tuples, not if the query fails or is a non-data-returning SQL command. filename|command引数を指定すると、問い合わせ出力を通常通りに表示する代わりに、指定したファイルに書き込んだり、指定のシェルコマンドにパイプで渡します。 問い合わせが成功しゼロ以上のタプルが返る場合にのみファイルまたはコマンドに書き出されます。 問い合わせが失敗する場合やデータを返さないSQLコマンドでは書き出されません。

If the current query buffer is empty, the most recently sent query is re-executed instead. Except for that behavior, <literal>\g</literal> without any arguments is essentially equivalent to a semicolon. With arguments, <literal>\g</literal> provides a <quote>one-shot</quote> alternative to the <command>\o</command> command, and additionally allows one-shot adjustments of the output formatting options normally set by <literal>\pset</literal>. 現在の問い合わせバッファが空の場合、最も最近に送信された問い合わせが再実行されます。 その点を除けば、\gだけを指定した場合は、セミコロンと実質的に同じです。 \gに引数を指定した場合は、\oコマンドの一度限りの代替手段として使用でき、さらに通常は\psetで設定される出力書式のオプションの一度限りの調整もできます。

When the last argument begins with <literal>|</literal>, the entire remainder of the line is taken to be the <replaceable class="parameter">command</replaceable> to execute, and neither variable interpolation nor backquote expansion are performed in it. The rest of the line is simply passed literally to the shell. 最後の引数が|で始まっている場合、行の残りの部分はすべて実行するcommandであると解釈され、その中では変数の置換も逆引用符の展開も行なわれません。 行の残り部分は、単にあるがままにシェルに渡されます。

\gdesc #

Shows the description (that is, the column names and data types) of the result of the current query buffer. The query is not actually executed; however, if it contains some type of syntax error, that error will be reported in the normal way. 現在の問い合わせバッファの結果の説明(列名とデータ型)を表示します。 問い合わせは実際には実行されませんが、ある種の構文エラーが含まれている場合、そのエラーは通常の方法で報告されます。

If the current query buffer is empty, the most recently sent query is described instead. 現在の問い合わせバッファが空の場合、直近に送った問い合わせの説明が代わりに出力されます。

\getenv psql_var env_var #

Gets the value of the environment variable <replaceable class="parameter">env_var</replaceable> and assigns it to the <application>psql</application> variable <replaceable class="parameter">psql_var</replaceable>. If <replaceable class="parameter">env_var</replaceable> is not defined in the <application>psql</application> process's environment, <replaceable class="parameter">psql_var</replaceable> is not changed. Example: 環境変数env_varの値を取得し、psql変数psql_varに割り当てます。 psqlのプロセスの環境でenv_varが定義されていない場合、psql_varは変更されません。 例:

=> \getenv home HOME
=> \echo :home
/home/postgres
\gexec #

Sends the current query buffer to the server, then treats each column of each row of the query's output (if any) as an SQL statement to be executed. For example, to create an index on each column of <structname>my_table</structname>: 現在の問い合わせバッファをサーバに送信し、問い合わせの出力(あれば)の各行の各列をSQL文として実行します。 例えば、my_tableの各列にインデックスを作成するには次のようにします。

=> SELECT format('create index on my_table(%I)', attname)
-> FROM pg_attribute
-> WHERE attrelid = 'my_table'::regclass AND attnum > 0
-> ORDER BY attnum
-> \gexec
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX

The generated queries are executed in the order in which the rows are returned, and left-to-right within each row if there is more than one column. NULL fields are ignored. The generated queries are sent literally to the server for processing, so they cannot be <application>psql</application> meta-commands nor contain <application>psql</application> variable references. If any individual query fails, execution of the remaining queries continues unless <varname>ON_ERROR_STOP</varname> is set. Execution of each query is subject to <varname>ECHO</varname> processing. (Setting <varname>ECHO</varname> to <literal>all</literal> or <literal>queries</literal> is often advisable when using <command>\gexec</command>.) Query logging, single-step mode, timing, and other query execution features apply to each generated query as well. 生成された問い合わせは行が返された順番で実行され、また2つ以上の列が返された場合は、各行の中で左から右に実行されます。 NULLのフィールドは無視されます。 生成された問い合わせは、そのままサーバに送信されて処理されるため、psqlのメタコマンドとすることはできず、またpsqlの変数の参照を含むこともできません。 個別の問い合わせで失敗した場合、残りの問い合わせの実行はON_ERROR_STOPが設定されているのでなければ継続します。 個々の問い合わせの実行はECHOの処理に従います。 (\gexecを使う場合、ECHOallあるいはqueriesに設定することが推奨されることが多いでしょう。) 問い合わせのログ出力、シングルステップモード、時間表示(timing)、およびその他の問い合わせ実行に関する機能は、生成された各問い合わせにも適用されます。

If the current query buffer is empty, the most recently sent query is re-executed instead. 現在の問い合わせバッファが空の場合、最も最近に送信された問い合わせが再実行されます。

\gset [ prefix ] #

Sends the current query buffer to the server and stores the query's output into <application>psql</application> variables (see <xref linkend="app-psql-variables"/> below). The query to be executed must return exactly one row. Each column of the row is stored into a separate variable, named the same as the column. For example: 現在の問い合わせバッファをサーバに送信し、問い合わせの出力をpsql変数(下記の変数参照)に格納します。 実行される問い合わせは正確に1行を返さなければなりません。 行の各列は、列と同じ名前を持つ別々の変数に格納されます。 例えば、以下のようになります。

=> SELECT 'hello' AS var1, 10 AS var2
-> \gset
=> \echo :var1 :var2
hello 10

If you specify a <replaceable class="parameter">prefix</replaceable>, that string is prepended to the query's column names to create the variable names to use: prefixを指定した場合、使用する変数の名前を作成する時にその文字列が問い合わせの列名の前に付けられ、次のようになります。

=> SELECT 'hello' AS var1, 10 AS var2
-> \gset result_
=> \echo :result_var1 :result_var2
hello 10

If a column result is NULL, the corresponding variable is unset rather than being set. 列の結果がNULLである場合、対応する変数は設定されず未設定状態となります。

If the query fails or does not return one row, no variables are changed. 問い合わせが失敗、または1行を返さない場合、変数は変更されません。

If the current query buffer is empty, the most recently sent query is re-executed instead. 現在の問い合わせバッファが空の場合、最も最近に送信された問い合わせが再実行されます。

\gx [ (option=value [...]) ] [ filename ]
\gx [ (option=value [...]) ] [ |command ] #

<literal>\gx</literal> is equivalent to <literal>\g</literal>, except that it forces expanded output mode for this query, as if <literal>expanded=on</literal> were included in the list of <literal>\pset</literal> options. See also <literal>\x</literal>. \gxは、\psetオプションの一覧にexpanded=onが含まれているかのように、この問い合わせに対して拡張出力モードを使用することを除いて\gと同じです。 \xも参照してください。

\hまたは\help [ command ] #

Gives syntax help on the specified <acronym>SQL</acronym> command. If <replaceable class="parameter">command</replaceable> is not specified, then <application>psql</application> will list all the commands for which syntax help is available. If <replaceable class="parameter">command</replaceable> is an asterisk (<literal>*</literal>), then syntax help on all <acronym>SQL</acronym> commands is shown. 指定したSQLコマンドの構文に関するヘルプを表示します。 commandが指定されていない場合は、psqlは構文ヘルプが存在する全てのコマンドの一覧を表示します。 commandをアスタリスク(*)にすると、全てのSQLコマンドの構文ヘルプが表示されます。

Unlike most other meta-commands, the entire remainder of the line is always taken to be the argument(s) of <command>\help</command>, and neither variable interpolation nor backquote expansion are performed in the arguments. 他のほとんどのメタコマンドと異なり、行の残り部分はすべて\helpの引数であると常に解釈され、引数内の変数の置換も逆引用符の展開も行われません。

注記

To simplify typing, commands that consists of several words do not have to be quoted. Thus it is fine to type <userinput>\help alter table</userinput>. 入力を簡単にするため、複数の単語からなるコマンドを引用符で囲む必要はありません。 \help alter tableと入力するだけで十分です。

\Hまたは\html #

Turns on <acronym>HTML</acronym> query output format. If the <acronym>HTML</acronym> format is already on, it is switched back to the default aligned text format. This command is for compatibility and convenience, but see <command>\pset</command> about setting other output options. HTML問い合わせ出力形式を有効にします。 HTML形式が有効になっている場合は、デフォルトの位置揃えされたテキスト形式に戻します。 このコマンドは互換性と簡便性のために存在します。 他の出力オプションについては、\psetを参照してください。

\iまたは\include filename #

Reads input from the file <replaceable class="parameter">filename</replaceable> and executes it as though it had been typed on the keyboard. filenameファイルから入力を読み取り、キーボードから入力された場合と同じように実行します。

If <replaceable>filename</replaceable> is <literal>-</literal> (hyphen), then standard input is read until an EOF indication or <command>\q</command> meta-command. This can be used to intersperse interactive input with input from files. Note that Readline behavior will be used only if it is active at the outermost level. filename-(ハイフン)の場合、EOFを示すもの、または\qメタコマンドが読まれるまで標準入力から読み込みます。 これは対話的な入力とファイルからの入力を混在させるために使うことができます。 Readlineと同じ挙動は、それが最も外部のレベルで動作している場合にのみ利用されることに注意してください。

注記

If you want to see the lines on the screen as they are read you must set the variable <varname>ECHO</varname> to <literal>all</literal>. 読み取られた行を画面に表示させる場合は、ECHO変数をallに設定する必要があります。

\if expression
\elif expression
\else
\endif #

This group of commands implements nestable conditional blocks. A conditional block must begin with an <command>\if</command> and end with an <command>\endif</command>. In between there may be any number of <command>\elif</command> clauses, which may optionally be followed by a single <command>\else</command> clause. Ordinary queries and other types of backslash commands may (and usually do) appear between the commands forming a conditional block. このコマンド群は入れ子にすることができる条件ブロックを実現します。 条件ブロックは\ifで始まり、\endifで終わらなければなりません。 その間には\elif句をいくつでも置くことができ、さらにその後に\else句を1つだけ置くことができます。 条件ブロックを構成するコマンドの間には、通常の問い合わせや他の種類のバックスラッシュコマンドを置くことができます(通常は置きます)。

The <command>\if</command> and <command>\elif</command> commands read their argument(s) and evaluate them as a Boolean expression. If the expression yields <literal>true</literal> then processing continues normally; otherwise, lines are skipped until a matching <command>\elif</command>, <command>\else</command>, or <command>\endif</command> is reached. Once an <command>\if</command> or <command>\elif</command> test has succeeded, the arguments of later <command>\elif</command> commands in the same block are not evaluated but are treated as false. Lines following an <command>\else</command> are processed only if no earlier matching <command>\if</command> or <command>\elif</command> succeeded. \ifコマンドおよび\elifコマンドはその引数を読み取り、それを論理式であるとして評価します。 式の結果がtrueであれば、通常通りに処理が続きますが、そうでないときは、対応する\elif\elseまたは\endifに到達するまで行をスキップします。 ひとたび\ifまたは\elifの評価が真になったら、同じブロック内のそれより後にある\elifコマンドの引数は評価されず、偽であるとして扱われます。 \elseより後にある行は、それより前の対応する\if\elifが一つも真にならなかった時にのみ実行されます。

The <replaceable class="parameter">expression</replaceable> argument of an <command>\if</command> or <command>\elif</command> command is subject to variable interpolation and backquote expansion, just like any other backslash command argument. After that it is evaluated like the value of an on/off option variable. So a valid value is any unambiguous case-insensitive match for one of: <literal>true</literal>, <literal>false</literal>, <literal>1</literal>, <literal>0</literal>, <literal>on</literal>, <literal>off</literal>, <literal>yes</literal>, <literal>no</literal>. For example, <literal>t</literal>, <literal>T</literal>, and <literal>tR</literal> will all be considered to be <literal>true</literal>. \ifコマンドおよび\elifコマンドのexpression引数は、他のバックスラッシュコマンドの引数と同様、変数置換と逆引用符展開の対象となります。 その後で、on/offのオプション変数の値のように評価されます。 従って有効な値は、truefalse10onoffyesnoのいずれかに曖昧性なしに、大文字小文字を区別せずにマッチするものです。 例えば、tTtRはすべてtrueであるとみなされます。

Expressions that do not properly evaluate to true or false will generate a warning and be treated as false. 真にも偽にも適切に評価できない式には警告を発行し、偽として扱います。

Lines being skipped are parsed normally to identify queries and backslash commands, but queries are not sent to the server, and backslash commands other than conditionals (<command>\if</command>, <command>\elif</command>, <command>\else</command>, <command>\endif</command>) are ignored. Conditional commands are checked only for valid nesting. Variable references in skipped lines are not expanded, and backquote expansion is not performed either. スキップされる行も、問い合わせとバックスラッシュコマンドを特定するため、通常通り解析されますが、問い合わせはサーバには送信されず、条件コマンド(\if\elif\else\endif)以外のバックスラッシュコマンドは無視されます。 条件コマンドは入れ子の有効性の確認のためだけに検査されます。 スキップされる行の変数参照は展開されず、逆引用符の展開も実行されません。

All the backslash commands of a given conditional block must appear in the same source file. If EOF is reached on the main input file or an <command>\include</command>-ed file before all local <command>\if</command>-blocks have been closed, then <application>psql</application> will raise an error. 条件ブロック内のすべてのバックスラッシュコマンドは同じファイル内になければなりません。 ファイル内のすべての\ifブロックが閉じられるより前に、メインの入力ファイルまたは\includeされたファイルの終端に到達した場合、psqlはエラーを発生させます。

Here is an example: 例を示します。


&#45;- check for the existence of two separate records in the database and store
&#45;- the results in separate psql variables

-- データベース内に2つのレコードが存在するかどうかを検査し、
-- その結果を2つのpsql変数に格納する。
SELECT
    EXISTS(SELECT 1 FROM customer WHERE customer_id = 123) as is_customer,
    EXISTS(SELECT 1 FROM employee WHERE employee_id = 456) as is_employee
\gset
\if :is_customer
    SELECT * FROM customer WHERE customer_id = 123;
\elif :is_employee
    \echo 'is not a customer but is an employee'
    SELECT * FROM employee WHERE employee_id = 456;
\else
    \if yes
        \echo 'not a customer or employee'
    \else
        \echo 'this will never print'
    \endif
\endif
\irまたは\include_relative filename #

The <literal>\ir</literal> command is similar to <literal>\i</literal>, but resolves relative file names differently. When executing in interactive mode, the two commands behave identically. However, when invoked from a script, <literal>\ir</literal> interprets file names relative to the directory in which the script is located, rather than the current working directory. \irコマンドは\iと似ていますが、相対ファイル名の解決方法が異なります。 対話モードで実行している場合は2つのコマンドの動作は同一です。 しかし、スクリプトから呼び出す場合、\irは、現在の作業ディレクトリではなく、そのスクリプトの格納ディレクトリから見た相対ファイル名として解釈します。

\l[+] または \list[+] [ pattern ] #

List the databases in the server and show their names, owners, character set encodings, and access privileges. If <replaceable class="parameter">pattern</replaceable> is specified, only databases whose names match the pattern are listed. If <literal>+</literal> is appended to the command name, database sizes, default tablespaces, and descriptions are also displayed. (Size information is only available for databases that the current user can connect to.) サーバ内のデータベースについて、その名前、所有者、文字セット符号化方式、アクセス権限を一覧表示します。 patternを指定すると、パターンにマッチする名前を持つデータベースのみを表示します。 コマンド名に+を付けると、データベースのサイズ、デフォルトのテーブル空間、説明も表示します。 (サイズ情報は現在のユーザが接続可能なデータベースでのみ表示されます。)

\lo_export loid filename #

Reads the large object with <acronym>OID</acronym> <replaceable class="parameter">loid</replaceable> from the database and writes it to <replaceable class="parameter">filename</replaceable>. Note that this is subtly different from the server function <function>lo_export</function>, which acts with the permissions of the user that the database server runs as and on the server's file system. データベースからOIDloidであるラージオブジェクトを読み取り、filenameに書き出します。 これはlo_exportサーバ関数とは微妙に異なります。 lo_export関数は、データベースサーバを実行しているユーザ権限で、サーバ上のファイルシステムに対して動作します。

ヒント

Use <command>\lo_list</command> to find out the large object's <acronym>OID</acronym>. ラージオブジェクトのOIDを確認するには、\lo_listを使用してください。

\lo_import filename [ comment ] #

Stores the file into a <productname>PostgreSQL</productname> large object. Optionally, it associates the given comment with the object. Example: ファイルをPostgreSQLのラージオブジェクトに保存します。 オプションで、そのオブジェクトに指定したコメントを関連付けることができます。 下記に例を示します。

foo=> \lo_import '/home/peter/pictures/photo.xcf' 'a picture of me'
lo_import 152801

The response indicates that the large object received object ID 152801, which can be used to access the newly-created large object in the future. For the sake of readability, it is recommended to always associate a human-readable comment with every object. Both OIDs and comments can be viewed with the <command>\lo_list</command> command. 上の応答は、指定したラージオブジェクトがオブジェクトID 152801として受け付けられたことを示します。 今後この新規作成されたラージオブジェクトにアクセスする場合に、この番号が使用できます。 可読性を高めるために、常に全てのオブジェクトに人間がわかるようなコメントを関連付けることが推奨されます。 \lo_listコマンドではOIDとコメントの両方が表示されます。

Note that this command is subtly different from the server-side <function>lo_import</function> because it acts as the local user on the local file system, rather than the server's user and file system. このコマンドは、ローカルなユーザによってローカルなファイルシステムに対して動作します。一方、サーバ側のlo_importは、サーバのユーザによってサーバ上のファイルシステムに対して動作します。 このコマンドとサーバ側のlo_importは、この点で微妙に異なっています。

\lo_list[+] #

Shows a list of all <productname>PostgreSQL</productname> large objects currently stored in the database, along with any comments provided for them. If <literal>+</literal> is appended to the command name, each large object is listed with its associated permissions, if any. 現在データベースに保存されているすべてのPostgreSQLラージオブジェクトの一覧を、そのオブジェクトに付けられたコメントと一緒に表示します。 コマンド名に+が追加されている場合は、各ラージオブジェクトが、もしあれば関連する権限とともに一覧表示されます。

Deletes the large object with <acronym>OID</acronym> <replaceable class="parameter">loid</replaceable> from the database. OIDloidであるラージオブジェクトをデータベースから削除します。

ヒント

Use <command>\lo_list</command> to find out the large object's <acronym>OID</acronym>. ラージオブジェクトのOIDを確認するには、\lo_listを使用してください。

\oまたは\out [ filename ]
\oまたは\out [ |command ] #

Arranges to save future query results to the file <replaceable class="parameter">filename</replaceable> or pipe future results to the shell command <replaceable class="parameter">command</replaceable>. If no argument is specified, the query output is reset to the standard output. 以降の問い合わせの結果を、filenameで指定されたファイルに保存するか、またはシェルコマンドcommandにパイプで渡すようにします。 引数がない場合、問い合わせの出力はリセットされて標準出力になります。

If the argument begins with <literal>|</literal>, then the entire remainder of the line is taken to be the <replaceable class="parameter">command</replaceable> to execute, and neither variable interpolation nor backquote expansion are performed in it. The rest of the line is simply passed literally to the shell. 引数が|で始まっている場合、行の残りの部分はすべて実行するcommandであると解釈され、その中では変数の置換も逆引用符の展開も行われません。 行の残り部分は、単にあるがままにシェルに渡されます。

<quote>Query results</quote> includes all tables, command responses, and notices obtained from the database server, as well as output of various backslash commands that query the database (such as <command>\d</command>); but not error messages. 問い合わせの結果には、全てのテーブル、コマンドの応答、データベースサーバからの注意メッセージだけでなく、データベースに問い合わせを行う(\dのような)各種バックスラッシュコマンドの出力が含まれます。ただし、エラーメッセージは含まれません。

ヒント

To intersperse text output in between query results, use <command>\qecho</command>. 問い合わせの結果の間にテキストを挿入するには、\qechoを使用してください。

\pまたは\print #

Print the current query buffer to the standard output. If the current query buffer is empty, the most recently executed query is printed instead. 現在の問い合わせバッファを標準出力に書き出します。 現在の問い合わせバッファが空の場合、最も最近に実行された問い合わせが書き出されます。

\password [ username ] #

Changes the password of the specified user (by default, the current user). This command prompts for the new password, encrypts it, and sends it to the server as an <command>ALTER ROLE</command> command. This makes sure that the new password does not appear in cleartext in the command history, the server log, or elsewhere. 指定したユーザ(デフォルトは現在のユーザ)のパスワードを変更します。 このコマンドは、新しいパスワードを促し、暗号化して、それをALTER ROLEコマンドとしてサーバに送信します。 これによりコマンド履歴やサーバログなどどこにも新しいパスワードが平文では残りません。

\prompt [ text ] name #

Prompts the user to supply text, which is assigned to the variable <replaceable class="parameter">name</replaceable>. An optional prompt string, <replaceable class="parameter">text</replaceable>, can be specified. (For multiword prompts, surround the text with single quotes.) 変数nameに代入するテキストを入力するようにユーザを促します。 プロンプトtextをオプションで指定することができます。 (複数の単語をプロンプトで使用する場合はそのテキストを単一引用符でくくってください。)

By default, <literal>\prompt</literal> uses the terminal for input and output. However, if the <option>-f</option> command line switch was used, <literal>\prompt</literal> uses standard input and standard output. デフォルトでは\promptは入出力に端末を使用します。 しかし、-fコマンドラインスイッチが使用されている場合、\promptは標準入力、標準出力を使用します。

\pset [ option [ value ] ] #

This command sets options affecting the output of query result tables. <replaceable class="parameter">option</replaceable> indicates which option is to be set. The semantics of <replaceable class="parameter">value</replaceable> vary depending on the selected option. For some options, omitting <replaceable class="parameter">value</replaceable> causes the option to be toggled or unset, as described under the particular option. If no such behavior is mentioned, then omitting <replaceable class="parameter">value</replaceable> just results in the current setting being displayed. このコマンドは問い合わせ結果のテーブル出力に影響するオプションを設定します。 optionには、どのオプションを設定するのかを記述します。 valueの意味は選択したオプションにより変わります。 以下のオプション別の説明の通り、オプションの中にはvalueを省略することでトグルや設定解除を行うものがあります。 こうした動作の記載がなければ、valueを省略すると、単に現在の設定値が表示されることになります。

<command>\pset</command> without any arguments displays the current status of all printing options. 何も引数をつけずに\psetを実行すると、すべての表示オプションの現在の状態を表示します。

Adjustable printing options are: 以下は、表示の調整に関するオプションです。

border #

The <replaceable class="parameter">value</replaceable> must be a number. In general, the higher the number the more borders and lines the tables will have, but details depend on the particular format. In <acronym>HTML</acronym> format, this will translate directly into the <literal>border=...</literal> attribute. In most other formats only values 0 (no border), 1 (internal dividing lines), and 2 (table frame) make sense, and values above 2 will be treated the same as <literal>border = 2</literal>. The <literal>latex</literal> and <literal>latex-longtable</literal> formats additionally allow a value of 3 to add dividing lines between data rows. valueは数値でなければなりません。 基本的には、この数字が大きくなればなるほど、表示するテーブルが持つ境界線は増えますが、詳細はそれぞれの出力形式に依存しています。 HTML書式では、この値は直接border=...属性に反映されます。 他のほとんどの書式の場合は、0(境界線なし)、1(内側の境界線)、2(テーブル枠)という3つの数値のみ意味を持ち、2より大きな値はborder = 2と同じとして扱われます。 latexおよびlatex-longtable書式では、さらにデータ行の間に境界線を付ける、3という値をとることができます。

columns #

Sets the target width for the <literal>wrapped</literal> format, and also the width limit for determining whether output is wide enough to require the pager or switch to the vertical display in expanded auto mode. Zero (the default) causes the target width to be controlled by the environment variable <envar>COLUMNS</envar>, or the detected screen width if <envar>COLUMNS</envar> is not set. In addition, if <literal>columns</literal> is zero then the <literal>wrapped</literal> format only affects screen output. If <literal>columns</literal> is nonzero then file and pipe output is wrapped to that width as well. wrapped書式の対象幅を設定し、そして、ページャを必要とする、拡張自動モードにおける縦表示への切替えに十分な幅で出力するかどうかを決定する幅制限を設定します。 ゼロ(デフォルト)では、環境変数COLUMNS、もしCOLUMNSが設定されていなければ、検出したスクリーンの幅、により対象幅が制御されます。 さらにcolumnsがゼロの場合、wrapped書式はスクリーン出力にのみ影響を与えることになります。 columnsが非ゼロの場合は、ファイルやパイプへの出力も同様に折り返されます。

csv_fieldsep #

Specifies the field separator to be used in <acronym>CSV</acronym> output format. If the separator character appears in a field's value, that field is output within double quotes, following standard <acronym>CSV</acronym> rules. The default is a comma. CSV出力形式で使われるフィールド区切り文字を指定します。 区切り文字がフィールドの値中に現れる場合には、標準のCSV規則に従ってそのフィールドは二重引用符内に出力されます。 デフォルトはコンマです。

expanded (またはx) #

If <replaceable class="parameter">value</replaceable> is specified it must be either <literal>on</literal> or <literal>off</literal>, which will enable or disable expanded mode, or <literal>auto</literal>. If <replaceable class="parameter">value</replaceable> is omitted the command toggles between the on and off settings. When expanded mode is enabled, query results are displayed in two columns, with the column name on the left and the data on the right. This mode is useful if the data wouldn't fit on the screen in the normal <quote>horizontal</quote> mode. In the auto setting, the expanded mode is used whenever the query output has more than one column and is wider than the screen; otherwise, the regular mode is used. The auto setting is only effective in the aligned and wrapped formats. In other formats, it always behaves as if the expanded mode is off. valueを指定する場合は、拡張(expanded)モードを有効または無効にするonまたはoff、あるいはautoのいずれかでなければなりません。 valueを省略した場合、このコマンドは通常モードと拡張モードの設定をトグルします。 拡張モードを有効にした場合、問い合わせ結果は左に列名、右にデータという2つの列で出力されます。 このモードは、データが通常の水平(horizontal)モードによる画面表示に適していない場合に有用です。 自動(auto)設定の場合、問い合わせの出力が2列以上でかつ画面幅より広ければ拡張モードが使用され、そうでなければ通常モードが使用されます。 自動設定は位置揃え書式または折り返し書式でのみ有効です。 この他の書式では、常に拡張モードが無効の場合と同様に動作します。

fieldsep #

Specifies the field separator to be used in unaligned output format. That way one can create, for example, tab-separated output, which other programs might prefer. To set a tab as field separator, type <literal>\pset fieldsep '\t'</literal>. The default field separator is <literal>'|'</literal> (a vertical bar). 位置揃えなしの出力書式で使用されるフィールド区切り文字を指定します。 これにより、例えばタブ区切りといった他プログラムに要求される形式を作成することができます。 タブをフィールド区切り文字として使用するには、\pset fieldsep '\t'と入力します。 デフォルトのフィールド区切り文字は'|'(縦棒)です。

fieldsep_zero #

Sets the field separator to use in unaligned output format to a zero byte. 位置揃えなしの出力書式で使用されるフィールド区切り文字をゼロバイトに指定します。

If <replaceable class="parameter">value</replaceable> is specified it must be either <literal>on</literal> or <literal>off</literal> which will enable or disable display of the table footer (the <literal>(<replaceable>n</replaceable> rows)</literal> count). If <replaceable class="parameter">value</replaceable> is omitted the command toggles footer display on or off. valueを指定する場合、それぞれテーブルフッタの表示((n rows)数)を有効にするonまたは無効にするoffのいずれかでなければなりません。 valueを省略した場合、このコマンドはフッタの表示、非表示をトグルします。

format #

Sets the output format to one of <literal>aligned</literal>, <literal>asciidoc</literal>, <literal>csv</literal>, <literal>html</literal>, <literal>latex</literal>, <literal>latex-longtable</literal>, <literal>troff-ms</literal>, <literal>unaligned</literal>, or <literal>wrapped</literal>. Unique abbreviations are allowed. 出力形式をalignedasciidoccsvhtmllatexlatex-longtabletroff-msunalignedwrappedのいずれかに設定します。 一意に判別できる範囲で省略が可能です。

<para><literal>aligned</literal> format is the standard, human-readable, nicely formatted text output; this is the default.

aligned書式は、標準的で人間が読みやすいように、美しく整形されたテキスト出力です。 これがデフォルトです。

<para><literal>unaligned</literal> format writes all columns of a row on one line, separated by the currently active field separator. This is useful for creating output that might be intended to be read in by other programs, for example, tab-separated or comma-separated format. However, the field separator character is not treated specially if it appears in a column's value; so <acronym>CSV</acronym> format may be better suited for such purposes.

unaligned書式は、表示行の1行に1つの行の全列を、現在有効なフィールド区切り文字で区切って書き出します。 これは他のプログラムに読み込ませることを目的とした出力、例えばタブ区切りやカンマ区切り書式を生成する場合に有用です。 しかし、列の値にフィールド区切り文字が現れても、特別扱いはしません。ですので、そのような目的には、CSV書式の方がより相応しいでしょう。

<para><literal>csv</literal> format

csv書式は writes column values separated by commas, applying the quoting rules described in <ulink url="https://tools.ietf.org/html/rfc4180">RFC 4180</ulink>. This output is compatible with the CSV format of the server's <command>COPY</command> command. A header line with column names is generated unless the <literal>tuples_only</literal> parameter is <literal>on</literal>. Titles and footers are not printed. Each row is terminated by the system-dependent end-of-line character, which is typically a single newline (<literal>\n</literal>) for Unix-like systems or a carriage return and newline sequence (<literal>\r\n</literal>) for Microsoft Windows. Field separator characters other than comma can be selected with <command>\pset csv_fieldsep</command>. RFC 4180で記述された引用規則を適用して、列の値をコンマで区切って書きます。 この出力はサーバのCOPYコマンドのCSV書式と互換性があります。 列名が書かれたヘッダ行は、tuples_onlyonでなければ生成されます。 タイトルとフッタは出力されません。 各行はシステム依存の改行文字で終わります。改行文字は、Unix系のシステムでは典型的には単独の改行(\n)であり、Microsoft Windowsでは復帰と改行の並び(\r\n)です。 コンマ以外のフィールド区切り文字は\pset csv_fieldsepで選べます。

<para><literal>wrapped</literal> format is like <literal>aligned</literal> but wraps wide data values across lines to make the output fit in the target column width. The target width is determined as described under the <literal>columns</literal> option. Note that <application>psql</application> will not attempt to wrap column header titles; therefore, <literal>wrapped</literal> format behaves the same as <literal>aligned</literal> if the total width needed for column headers exceeds the target.

wrapped書式はalignedと似ていますが、幅の広いデータ値を複数行に折り返して対象の列幅に合うように出力します。 対象の幅はcolumnsオプションの項に記述されているように決定されます。 psqlは列ヘッダタイトルを折り返さないことに注意して下さい。 このためwrapped書式は列ヘッダに必要とする幅全体が対象より長い場合、alignedと動作が同じになります。

The <literal>asciidoc</literal>, <literal>html</literal>, <literal>latex</literal>, <literal>latex-longtable</literal>, and <literal>troff-ms</literal> formats put out tables that are intended to be included in documents using the respective mark-up language. They are not complete documents! This might not be necessary in <acronym>HTML</acronym>, but in <application>LaTeX</application> you must have a complete document wrapper. The <literal>latex</literal> format uses <application>LaTeX</application>'s <literal>tabular</literal> environment. The <literal>latex-longtable</literal> format requires the <application>LaTeX</application> <literal>longtable</literal> and <literal>booktabs</literal> packages. asciidochtmllatexlatex-longtableおよびtroff-ms書式は対応するマークアップ言語を使用する文書内に含めることを目的とした表を出力します。 出力自体は完全な文書ではありません。 HTMLでは必要性がないかもしれませんが、LaTeXでは完全な文書ラッパーを持たせなければなりません。 latex書式はLaTeXtabular環境を使います。 latex-longtable書式ではLaTeXlongtableおよびbooktabsパッケージも必要です。

linestyle #

Sets the border line drawing style to one of <literal>ascii</literal>, <literal>old-ascii</literal>, or <literal>unicode</literal>. Unique abbreviations are allowed. (That would mean one letter is enough.) The default setting is <literal>ascii</literal>. This option only affects the <literal>aligned</literal> and <literal>wrapped</literal> output formats. 境界線の表示形式をasciiold-asciiまたはunicodeのいずれかに設定します。 一意になれば省略形が許されます。(つまり一文字で十分であることを意味します。) デフォルトの設定はasciiです。 このオプションはalignedおよびwrapped出力書式のみで有効です。

<para><literal>ascii</literal> style uses plain <acronym>ASCII</acronym> characters. Newlines in data are shown using a <literal>+</literal> symbol in the right-hand margin. When the <literal>wrapped</literal> format wraps data from one line to the next without a newline character, a dot (<literal>.</literal>) is shown in the right-hand margin of the first line, and again in the left-hand margin of the following line.

ascii形式は通常のASCIIを使用します。 データ内の改行は右側余白に+を使用して表します。 wrapped書式で、改行文字のない行が2行にまたがるときは、先頭行の右側余白にドット(.)を表示し、次の行の左側余白にもドットを表示します。

<para><literal>old-ascii</literal> style uses plain <acronym>ASCII</acronym> characters, using the formatting style used in <productname>PostgreSQL</productname> 8.4 and earlier. Newlines in data are shown using a <literal>:</literal> symbol in place of the left-hand column separator. When the data is wrapped from one line to the next without a newline character, a <literal>;</literal> symbol is used in place of the left-hand column separator.

old-ascii形式は通常のASCII文字を使用して、PostgreSQL 8.4以前で使用されていた方法で整形します。 データ内の改行は列区切りの左側に:記号を使用して表します。 データを改行文字なしに折り返す際には、列区切りの左側に;記号を使用して表します。

<para><literal>unicode</literal> style uses Unicode box-drawing characters. Newlines in data are shown using a carriage return symbol in the right-hand margin. When the data is wrapped from one line to the next without a newline character, an ellipsis symbol is shown in the right-hand margin of the first line, and again in the left-hand margin of the following line.

unicode形式はUnicode矩形描画文字を使用します。 データ内の改行は右側の余白に復帰記号を使用して表します。 データを改行文字なしに折り返す際には、省略記号を先頭行の右側余白に表示し、次の行の左側余白にも表示します。

When the <literal>border</literal> setting is greater than zero, the <literal>linestyle</literal> option also determines the characters with which the border lines are drawn. Plain <acronym>ASCII</acronym> characters work everywhere, but Unicode characters look nicer on displays that recognize them. border設定がゼロより大きい場合、linestyleオプションはまた、境界線を描画する文字も決定します。 通常のASCII文字はどのような場合でも動作しますが、Unicode文字が表示できる環境では、その方が見た目が良くなります。

null #

Sets the string to be printed in place of a null value. The default is to print nothing, which can easily be mistaken for an empty string. For example, one might prefer <literal>\pset null '(null)'</literal>. null値の代わりに表示する文字列を設定します。 デフォルトでは何も表示しません。 そのため、よく空の文字列と間違うことがあります。 例えば\pset null '(null)'とする人もいます。

numericlocale #

If <replaceable class="parameter">value</replaceable> is specified it must be either <literal>on</literal> or <literal>off</literal> which will enable or disable display of a locale-specific character to separate groups of digits to the left of the decimal marker. If <replaceable class="parameter">value</replaceable> is omitted the command toggles between regular and locale-specific numeric output. valueを指定する場合、それぞれ10進数マーカーの左に桁のくくりを分離するロケール固有の文字を表示するonまたは表示しないoffのいずれかでなければなりません。 valueを省略した場合、このコマンドは通常出力かロケール固有の数値出力かをトグルします。

pager #

Controls use of a pager program for query and <application>psql</application> help output. When the <literal>pager</literal> option is <literal>off</literal>, the pager program is not used. When the <literal>pager</literal> option is <literal>on</literal>, the pager is used when appropriate, i.e., when the output is to a terminal and will not fit on the screen. The <literal>pager</literal> option can also be set to <literal>always</literal>, which causes the pager to be used for all terminal output regardless of whether it fits on the screen. <literal>\pset pager</literal> without a <replaceable class="parameter">value</replaceable> toggles pager use on and off. 問い合わせおよびpsqlのヘルプを出力する際の、ページャプログラムの使用を制御します。 pagerオプションがoffの場合、ページャプログラムは使用されません。 pagerオプションがonの場合、ページャは適切な場合、つまり出力先が端末であり、その画面に収まらない場合に使用されます。 またpagerオプションはalwaysに設定することもできます。 こうすると画面に収まるかどうかに関わらずすべての端末出力でページャが使用されます。 valueを指定しない\pset pagerはページャの使用をトグルします。

If the environment variable <envar>PSQL_PAGER</envar> or <envar>PAGER</envar> is set, output to be paged is piped to the specified program. Otherwise a platform-dependent default program (such as <filename>more</filename>) is used. 環境変数PSQL_PAGERまたはPAGERが設定されている場合、出力は指定したプログラムにパイプで渡されます。 設定されていない場合は、プラットフォーム依存のデフォルト(moreなど)が使用されます。

When using the <literal>\watch</literal> command to execute a query repeatedly, the environment variable <envar>PSQL_WATCH_PAGER</envar> is used to find the pager program instead, on Unix systems. This is configured separately because it may confuse traditional pagers, but can be used to send output to tools that understand <application>psql</application>'s output format (such as <filename>pspg &#45;-stream</filename>). \watchコマンドを使用して問い合わせを繰り返し実行する場合、Unixシステムでは環境変数PSQL_WATCH_PAGERがページャプログラムを検索するために代わりに使用されます。 これは従来のページャを混乱させる可能性があるため別に設定されていますが、psqlの出力フォーマットを理解するツール(pspg --streamなど)に出力を送るために使用できます。

pager_min_lines #

If <literal>pager_min_lines</literal> is set to a number greater than the page height, the pager program will not be called unless there are at least this many lines of output to show. The default setting is 0. pager_min_linesがページ高より大きな数に設定されている場合、少なくともこれに設定されている行数の出力がなければ、ページャプログラムを呼び出しません。 デフォルトの設定は0です。

recordsep #

Specifies the record (line) separator to use in unaligned output format. The default is a newline character. 位置揃えなしの出力書式で使用されるレコード(行)の区切り文字を指定します。 デフォルトは改行文字です。

recordsep_zero #

Sets the record separator to use in unaligned output format to a zero byte. 位置揃えなしの出力書式で使用されるレコードの区切り文字をゼロバイトに指定します。

tableattr (または T) #

In <acronym>HTML</acronym> format, this specifies attributes to be placed inside the <sgmltag>table</sgmltag> tag. This could for example be <literal>cellpadding</literal> or <literal>bgcolor</literal>. Note that you probably don't want to specify <literal>border</literal> here, as that is already taken care of by <literal>\pset border</literal>. If no <replaceable class="parameter">value</replaceable> is given, the table attributes are unset. HTML出力書式では、これはtableタグ内に記述する属性を指定します。 これを使用して、例えば、cellpaddingbgcolorを指定することができます。 border属性は既に\pset borderによって処理されているので、このコマンドでborderを指定する必要はないでしょう。 valueの指定がない場合、テーブル属性の設定は解除されます。

In <literal>latex-longtable</literal> format, this controls the proportional width of each column containing a left-aligned data type. It is specified as a whitespace-separated list of values, e.g., <literal>'0.2 0.2 0.6'</literal>. Unspecified output columns use the last specified value. latex-longtable書式では、これは 左揃えされたデータ型を含む各列の幅の比率を制御します。 空白文字で区切られた値のリスト、例えば'0.2 0.2 0.6'として指定します。 指定がない出力列は最後に指定された値を使用します。

title (または C) #

Sets the table title for any subsequently printed tables. This can be used to give your output descriptive tags. If no <replaceable class="parameter">value</replaceable> is given, the title is unset. 今後表示される全てのテーブル用にテーブルタイトルを設定します。 これは出力に説明のためのタグを付けたい場合に有用です。 valueがない場合、タイトルの設定が解除されます。

tuples_only (または t) #

If <replaceable class="parameter">value</replaceable> is specified it must be either <literal>on</literal> or <literal>off</literal> which will enable or disable tuples-only mode. If <replaceable class="parameter">value</replaceable> is omitted the command toggles between regular and tuples-only output. Regular output includes extra information such as column headers, titles, and various footers. In tuples-only mode, only actual table data is shown. valueを指定する場合、それぞれタプルのみの表示を有効にする、onまたは無効にするoffのいずれかでなければなりません。 valueを省略した場合、このコマンドはタプルのみの表示と通常表示をトグルします。 通常表示では列のヘッダ、タイトル、各種フッタなどのその他の情報が追加されます。 タプルのみのモードでは、テーブルの実データのみが表示されます。

unicode_border_linestyle #

Sets the border drawing style for the <literal>unicode</literal> line style to one of <literal>single</literal> or <literal>double</literal>. unicodeの線の形式の境界の形式をsingleまたはdoubleのどちらかに設定します。

unicode_column_linestyle #

Sets the column drawing style for the <literal>unicode</literal> line style to one of <literal>single</literal> or <literal>double</literal>. unicodeの線の形式の列の形式をsingleまたはdoubleのどちらかに設定します。

unicode_header_linestyle #

Sets the header drawing style for the <literal>unicode</literal> line style to one of <literal>single</literal> or <literal>double</literal>. unicodeの線の形式のヘッダの形式をsingleまたはdoubleのどちらかに設定します。

xheader_width #

Sets the maximum width of the header for expanded output to one of <literal>full</literal> (the default value), <literal>column</literal>, <literal>page</literal>, or an <replaceable class="parameter">integer value</replaceable>. 拡張出力のヘッダの最大幅を、full(デフォルト値)、columnpage、または整数値のいずれかに設定します。

<literal>full</literal>: the expanded header is not truncated, and will be as wide as the widest output line. full: 拡張ヘッダは切り詰められることなく、最も広い出力行と同じ幅になります。

<literal>column</literal>: truncate the header line to the width of the first column. column: ヘッダ行を最初の列の横幅に切り詰めます。

<literal>page</literal>: truncate the header line to the terminal width. page: ヘッダ行を端末の幅に切り詰めます。

<replaceable class="parameter">integer value</replaceable>: specify the exact maximum width of the header line. 整数値: ヘッダ行の正確な最大幅を指定します。

Illustrations of how these different formats look can be seen in <xref linkend="app-psql-examples"/>, below. これらの異なる書式がどのように見えるかを示した実例が、下記のにあります。

ヒント

There are various shortcut commands for <command>\pset</command>. See <command>\a</command>, <command>\C</command>, <command>\f</command>, <command>\H</command>, <command>\t</command>, <command>\T</command>, and <command>\x</command>. \psetには各種のショートカットコマンドがあります。 \a\C\f\H\t\T\xを参照してください。

\qまたは\quit #

Quits the <application>psql</application> program. In a script file, only execution of that script is terminated. psqlプログラムを終了します。 スクリプトファイルでは、そのスクリプトの実行のみが終了します。

\qecho text [ ... ] #

This command is identical to <command>\echo</command> except that the output will be written to the query output channel, as set by <command>\o</command>. このコマンドは、\echoと同じです。 ただし、出力が\oにより設定された問い合わせ出力チャネルに書き出される点が異なります。

\rまたは\reset #

Resets (clears) the query buffer. 問い合わせバッファをリセット(クリア)します。

\s [ filename ] #

Print <application>psql</application>'s command line history to <replaceable class="parameter">filename</replaceable>. If <replaceable class="parameter">filename</replaceable> is omitted, the history is written to the standard output (using the pager if appropriate). This command is not available if <application>psql</application> was built without <application>Readline</application> support. psqlのコマンドラインの履歴をfilenameに出力します。 filenameが省略された場合、履歴は標準出力に書き出されます(適切であればページャを使います)。 このコマンドは、psqlReadlineサポートなしの状態でビルドされた場合は利用できません。

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

Sets the <application>psql</application> variable <replaceable class="parameter">name</replaceable> to <replaceable class="parameter">value</replaceable>, or if more than one value is given, to the concatenation of all of them. If only one argument is given, the variable is set to an empty-string value. To unset a variable, use the <command>\unset</command> command. psqlの変数namevalue、または複数のvalueが与えられた場合はそれらを連結したものに設定します。 第一引数しか指定されない場合は、変数に空文字列の値が設定されます。 変数を未設定とするには、\unsetコマンドを使用してください。

<para><command>\set</command> without any arguments displays the names and values of all currently-set <application>psql</application> variables.

引数をまったく取らない\setは、現在設定されているpsql変数すべての名前と値を表示します。

Valid variable names can contain letters, digits, and underscores. See <xref linkend="app-psql-variables"/> below for details. Variable names are case-sensitive. 変数名には、文字、数字、アンダースコアを使用することができます。 詳細は、後述の変数を参照してください。 変数名は大文字小文字を区別します。

Certain variables are special, in that they control <application>psql</application>'s behavior or are automatically set to reflect connection state. These variables are documented in <xref linkend="app-psql-variables"/>, below. psqlの動作を制御する、あるいは接続状態を表す値に自動的に設定される、という点で特別な変数がいくつかあります。 これらの変数については、以下の変数に記載されています。

注記

This command is unrelated to the <acronym>SQL</acronym> command <link linkend="sql-set"><command>SET</command></link>. このコマンドはSQLSETコマンドとは関係ありません。

\setenv name [ value ] #

Sets the environment variable <replaceable class="parameter">name</replaceable> to <replaceable class="parameter">value</replaceable>, or if the <replaceable class="parameter">value</replaceable> is not supplied, unsets the environment variable. Example: 環境変数namevalueに設定します。 valueが与えられない場合は、その環境変数を未設定状態にします。 以下に例を示します。

testdb=> \setenv PAGER less
testdb=> \setenv LESS -imx4F
\sf[+] function_description #

This command fetches and shows the definition of the named function or procedure, in the form of a <command>CREATE OR REPLACE FUNCTION</command> or <command>CREATE OR REPLACE PROCEDURE</command> command. The definition is printed to the current query output channel, as set by <command>\o</command>. このコマンドは、CREATE OR REPLACE FUNCTIONコマンドやCREATE OR REPLACE PROCEDUREコマンドの形式で、指定された関数やプロシージャの定義を抽出し表示します。 この定義は、\oで設定された現在の問い合わせ出力チャネルに出力されます。

The target function can be specified by name alone, or by name and arguments, for example <literal>foo(integer, text)</literal>. The argument types must be given if there is more than one function of the same name. 対象の関数は、名前だけまたは、例えばfoo(integer, text)のように名前と引数で指定することができます。 同じ名前の関数が複数存在する場合は、引数の型を指定しなければなりません。

If <literal>+</literal> is appended to the command name, then the output lines are numbered, with the first line of the function body being line 1. コマンド名に+を付けると、出力行に関数本体の先頭行を1行目と数える行番号が付けられます。

Unlike most other meta-commands, the entire remainder of the line is always taken to be the argument(s) of <command>\sf</command>, and neither variable interpolation nor backquote expansion are performed in the arguments. 他のほとんどのメタコマンドと異なり、行の残り部分はすべて\sfの引数であると常に解釈され、引数内の変数の置換も逆引用符の展開も行われません。

\sv[+] view_name #

This command fetches and shows the definition of the named view, in the form of a <command>CREATE OR REPLACE VIEW</command> command. The definition is printed to the current query output channel, as set by <command>\o</command>. このコマンドは、指定したビューの定義をCREATE OR REPLACE VIEWコマンドの形式で取得して表示します。 定義は現在の問い合わせの出力チャネルに表示されます。 これは\oで設定できます。

If <literal>+</literal> is appended to the command name, then the output lines are numbered from 1. コマンド名の後に+が付加された場合は、出力行に1から番号が付けられます。

Unlike most other meta-commands, the entire remainder of the line is always taken to be the argument(s) of <command>\sv</command>, and neither variable interpolation nor backquote expansion are performed in the arguments. 他のほとんどのメタコマンドと異なり、行の残り部分はすべて\svの引数であると常に解釈され、引数内の変数の置換も逆引用符の展開も行われません。

\t #

Toggles the display of output column name headings and row count footer. This command is equivalent to <literal>\pset tuples_only</literal> and is provided for convenience. 出力列名ヘッダと行数フッタの表示を切り替えます。 このコマンドは\pset tuples_onlyと同じで、簡便性のために用意されています。

\T table_options #

Specifies attributes to be placed within the <sgmltag>table</sgmltag> tag in <acronym>HTML</acronym> output format. This command is equivalent to <literal>\pset tableattr <replaceable class="parameter">table_options</replaceable></literal>. HTML出力書式におけるtableタグ内部に記述する属性を指定します。 このコマンドは\pset tableattr table_optionsと同じ効力を持ちます。

\timing [ on | off ] #

With a parameter, turns displaying of how long each SQL statement takes on or off. Without a parameter, toggles the display between on and off. The display is in milliseconds; intervals longer than 1 second are also shown in minutes:seconds format, with hours and days fields added if needed. パラメータがある場合、各SQL文にかかる時間の表示の有無をonまたはoffに設定します。 パラメータがない場合、表示をonとoffの間で切り替えます。 表示はミリセカンド単位です。 1秒より長い時間は 分:秒 の形式で表示され、必要なら時間と日のフィールドが追加されます。

\unset name #

Unsets (deletes) the <application>psql</application> variable <replaceable class="parameter">name</replaceable>. psql変数nameを未設定状態にします(削除します)。

Most variables that control <application>psql</application>'s behavior cannot be unset; instead, an <literal>\unset</literal> command is interpreted as setting them to their default values. See <xref linkend="app-psql-variables"/> below. psqlの動作を制御するほとんどの変数は未設定にすることができず、\unsetはそれをデフォルト値に設定するものとして解釈されます。 以下の変数を参照してください。

\wまたは\write filename
\wまたは\write |command #

Writes the current query buffer to the file <replaceable class="parameter">filename</replaceable> or pipes it to the shell command <replaceable class="parameter">command</replaceable>. If the current query buffer is empty, the most recently executed query is written instead. 現在の問い合わせバッファを、filenameファイルに書き出すか、もしくは、シェルコマンドcommandにパイプで渡します。 現在の問い合わせバッファが空の場合、最も最近に実行された問い合わせを書き出します。

If the argument begins with <literal>|</literal>, then the entire remainder of the line is taken to be the <replaceable class="parameter">command</replaceable> to execute, and neither variable interpolation nor backquote expansion are performed in it. The rest of the line is simply passed literally to the shell. 引数が|で始まっている場合、行の残りの部分はすべて実行するcommandであると解釈され、その中では変数の置換も逆引用符の展開も行われません。 行の残り部分は、単にあるがままにシェルに渡されます。

\warn text [ ... ] #

This command is identical to <command>\echo</command> except that the output will be written to <application>psql</application>'s standard error channel, rather than standard output. このコマンドは、出力が標準出力ではなくpsqlの標準エラーチャネルに書かれることを除いて\echoと同一です。

\watch [ i[nterval]=seconds ] [ c[ount]=times ] [ seconds ] #

Repeatedly execute the current query buffer (as <literal>\g</literal> does) until interrupted, or the query fails, or the execution count limit (if given) is reached. Wait the specified number of seconds (default 2) between executions. For backwards compatibility, <replaceable class="parameter">seconds</replaceable> can be specified with or without an <literal>interval=</literal> prefix. Each query result is displayed with a header that includes the <literal>\pset title</literal> string (if any), the time as of query start, and the delay interval. 中断するか、問い合わせが失敗するか、(指定されていれば)実行回数の上限に達するまで、現在の問い合わせバッファを繰り返し(\gと同じように)実行します。 実行の間に指定秒数(デフォルトは2)の休止が入ります。 後方互換性のため、secondsは前にinterval=を付けても付けなくても指定できます。 各問い合わせの結果には、\pset titleの文字列(あれば)、問い合わせ開始時の時刻、および遅延間隔を含むヘッダとともに表示されます。

If the current query buffer is empty, the most recently sent query is re-executed instead. 現在の問い合わせバッファが空の場合、最も最近に送信された問い合わせが再実行されます。

\x [ on | off | auto ] #

Sets or toggles expanded table formatting mode. As such it is equivalent to <literal>\pset expanded</literal>. 拡張テーブル形式モードを設定またはトグルします。 従って、このコマンドは\pset expandedと同じ効力を持ちます。

\z[S] [ pattern ] #

Lists tables, views and sequences with their associated access privileges. If a <replaceable class="parameter">pattern</replaceable> is specified, only tables, views and sequences whose names match the pattern are listed. By default only user-created objects are shown; supply a pattern or the <literal>S</literal> modifier to include system objects. テーブル、ビュー、シーケンスを、関連付けられているアクセス権限とともに一覧表示します。 patternを指定すると、パターンに名前がマッチするテーブル、ビュー、シーケンスのみが表示されます。 デフォルトではユーザが作成したオブジェクトのみが表示されます。 システムオブジェクトを含めるためには、パターンまたはS修飾子を付与してください。

This is an alias for <command>\dp</command> (<quote>display privileges</quote>). これは\dp権限の表示(display privileges))の別名です。

\! [ command ] #

With no argument, escapes to a sub-shell; <application>psql</application> resumes when the sub-shell exits. With an argument, executes the shell command <replaceable class="parameter">command</replaceable>. 引数がないときはサブシェルに制御を渡し、サブシェルが終了したらpsqlが再開されます。 引数があるときは、シェルコマンドcommandを実行します。

Unlike most other meta-commands, the entire remainder of the line is always taken to be the argument(s) of <command>\!</command>, and neither variable interpolation nor backquote expansion are performed in the arguments. The rest of the line is simply passed literally to the shell. 他のほとんどのメタコマンドと異なり、行の残り部分はすべて\!の引数であると常に解釈され、引数内の変数の置換も逆引用符の展開も行われません。 行の残りの部分は単にあるがままにシェルに渡されます。

\? [ topic ] #

Shows help information. The optional <replaceable class="parameter">topic</replaceable> parameter (defaulting to <literal>commands</literal>) selects which part of <application>psql</application> is explained: <literal>commands</literal> describes <application>psql</application>'s backslash commands; <literal>options</literal> describes the command-line options that can be passed to <application>psql</application>; and <literal>variables</literal> shows help about <application>psql</application> configuration variables. ヘルプ情報を表示します。 オプションのtopicパラメータ(デフォルトはcommands)はpsqlのどの部分を説明するかを選択します。 commandspsqlのバックスラッシュコマンドについて、optionspsqlに渡すことができるコマンド行オプションについて、variablespsqlの設定変数についてのヘルプを表示します。

\; #

Backslash-semicolon is not a meta-command in the same way as the preceding commands; rather, it simply causes a semicolon to be added to the query buffer without any further processing. バックスラッシュ-セミコロンは前述のコマンドと同じ位置づけのメタコマンドではありません。そうではなく単にセミコロンを追加処理無しで問い合わせバッファに加えます。

Normally, <application>psql</application> will dispatch an SQL command to the server as soon as it reaches the command-ending semicolon, even if more input remains on the current line. Thus for example entering 通常、psqlは、コマンド終了のセミコロンに到達したら、更なる入力が現在行に残っていても、SQLコマンドをすぐにサーバに送ります。 よって、例えば、

select 1; select 2; select 3;

will result in the three SQL commands being individually sent to the server, with each one's results being displayed before continuing to the next command. However, a semicolon entered as <literal>\;</literal> will not trigger command processing, so that the command before it and the one after are effectively combined and sent to the server in one request. So for example 上記は3つのSQLコマンドが個々にサーバに送られることになり、各々の結果は続く次コマンドの前に表示されます。 しかしながら、\;として挿入されたセミコロンはコマンド処理を誘発せず、その後、そのさらに後のコマンドは事実上結合されて、サーバに一つのリクエストとして送られます。 したがって、例えば、

select 1\; select 2\; select 3;

results in sending the three SQL commands to the server in a single request, when the non-backslashed semicolon is reached. The server executes such a request as a single transaction, unless there are explicit <command>BEGIN</command>/<command>COMMIT</command> commands included in the string to divide it into multiple transactions. (See <xref linkend="protocol-flow-multi-statement"/> for more details about how the server handles multi-query strings.) 上記は、バックスラッシュの無いセミコロンに達したときに、3つのSQLコマンドがサーバに単一リクエストでサーバに送られます。 文字列にそれを複数トランザクションに分けるための明示的なBEGIN/COMMITが含まれているのでない限り、サーバはこのようなリクエストを単一トランザクションとして実行します。 (複数問い合わせの文字列をどのようにサーバが処理するかについて、詳しくは55.2.2.1を参照してください。)

<refsect3 id="app-psql-patterns" xreflabel="Patterns">

パターン

<title>Patterns</title>

The various <literal>\d</literal> commands accept a <replaceable class="parameter">pattern</replaceable> parameter to specify the object name(s) to be displayed. In the simplest case, a pattern is just the exact name of the object. The characters within a pattern are normally folded to lower case, just as in SQL names; for example, <literal>\dt FOO</literal> will display the table named <literal>foo</literal>. As in SQL names, placing double quotes around a pattern stops folding to lower case. Should you need to include an actual double quote character in a pattern, write it as a pair of double quotes within a double-quote sequence; again this is in accord with the rules for SQL quoted identifiers. For example, <literal>\dt "FOO""BAR"</literal> will display the table named <literal>FOO"BAR</literal> (not <literal>foo"bar</literal>). Unlike the normal rules for SQL names, you can put double quotes around just part of a pattern, for instance <literal>\dt FOO"FOO"BAR</literal> will display the table named <literal>fooFOObar</literal>. 各種\dコマンドでは、patternパラメータを渡して、表示するオブジェクト名を指定することができます。 最も単純な場合では、パターンが正確にオブジェクト名に一致します。 パターン内の文字は、SQLの名前と同様、通常小文字に変換されます。 例えば\dt FOOfooという名前のテーブルを表示します。 SQLの名前と同様、パターンを二重引用符で括ることで小文字への変換が取り止められます。 二重引用符自体をパターン内に含めなければならない場合、二重引用符で括った文字列の中で二重引用符を二重に記載してください。 これもSQLの引用符付き識別子の規則に従ったものです。 例えば、\dt "FOO""BAR"FOO"BARという名前のテーブルを表示します(foo"barではありません)。 SQLの名前と異なり、パターンの一部を二重引用符で括ることができます。 例えば、\dt FOO"FOO"BARfooFOObarという名前のテーブルを表示します。

Whenever the <replaceable class="parameter">pattern</replaceable> parameter is omitted completely, the <literal>\d</literal> commands display all objects that are visible in the current schema search path &mdash; this is equivalent to using <literal>*</literal> as the pattern. (An object is said to be <firstterm>visible</firstterm> if its containing schema is in the search path and no object of the same kind and name appears earlier in the search path. This is equivalent to the statement that the object can be referenced by name without explicit schema qualification.) To see all objects in the database regardless of visibility, use <literal>*.*</literal> as the pattern. patternパラメータが完全に省略されている場合、\dコマンドは現在のスキーマ検索パス内で可視のオブジェクトを全て表示します。 これは*というパターンを使用することと同じです。 (オブジェクトを含むスキーマが検索パス上にあり、同じ種類かつ同じ名前のオブジェクトが検索パス上それより前に存在しない場合、そのオブジェクトは可視であるといいます。 これは明示的なスキーマ修飾がない名前でオブジェクトを参照できるということと同じです。) 可視か否かに関わらずデータベース内の全てのオブジェクトを表示するには、*.*というパターンを使用します。

Within a pattern, <literal>*</literal> matches any sequence of characters (including no characters) and <literal>?</literal> matches any single character. (This notation is comparable to Unix shell file name patterns.) For example, <literal>\dt int*</literal> displays tables whose names begin with <literal>int</literal>. But within double quotes, <literal>*</literal> and <literal>?</literal> lose these special meanings and are just matched literally. パターン内部では、*は(0文字を含む)任意の文字の並びにマッチし、?は任意の1文字にマッチします。 (この記法はUnixシェルのファイル名パターンと似ています。) 例えば、\dt int*は、intから始まる名前を持つテーブルを表示します。 しかし、二重引用符の中では、*?はその特別な意味を失い、文字そのものにマッチします。

A relation pattern that contains a dot (<literal>.</literal>) is interpreted as a schema name pattern followed by an object name pattern. For example, <literal>\dt foo*.*bar*</literal> displays all tables whose table name includes <literal>bar</literal> that are in schemas whose schema name starts with <literal>foo</literal>. When no dot appears, then the pattern matches only objects that are visible in the current schema search path. Again, a dot within double quotes loses its special meaning and is matched literally. A relation pattern that contains two dots (<literal>.</literal>) is interpreted as a database name followed by a schema name pattern followed by an object name pattern. The database name portion will not be treated as a pattern and must match the name of the currently connected database, else an error will be raised. ドット(.)を含むリレーションパターンは、スキーマ名にオブジェクト名が続くパターンとして解釈されます。 例えば、\dt foo*.*bar*は、スキーマ名がfooで始まるスキーマ内のテーブル名がbarを含むテーブルを全て表示します。 ドットがない場合、パターンは現行のスキーマ検索パス内で可視的なオブジェクトのみにマッチします。 ここでも、二重引用符で括られた文字列内のドットは特別な意味を失い、文字そのものにマッチすることになります。 ドット(.)を2つ含むリレーションパターンは、データベース名にスキーマ名が続き、オブジェクト名が続くパターンとして解釈されます。 データベース名の部分はパターンとしては扱われず、現在接続しているデータベースの名前に一致しなければなりません。さもないとエラーが発生します。

A schema pattern that contains a dot (<literal>.</literal>) is interpreted as a database name followed by a schema name pattern. For example, <literal>\dn mydb.*foo*</literal> displays all schemas whose schema name includes <literal>foo</literal>. The database name portion will not be treated as a pattern and must match the name of the currently connected database, else an error will be raised. ドット(.)を含むスキーマパターンは、データベース名にスキーマ名が続くパターンとして解釈されます。 例えば、\dn mydb.*foo*は、スキーマ名がfooを含むスキーマを全て表示します。 データベース名の部分はパターンとしては扱われず、現在接続しているデータベースの名前に一致しなければなりません。さもないとエラーが発生します。

Advanced users can use regular-expression notations such as character classes, for example <literal>[0-9]</literal> to match any digit. All regular expression special characters work as specified in <xref linkend="functions-posix-regexp"/>, except for <literal>.</literal> which is taken as a separator as mentioned above, <literal>*</literal> which is translated to the regular-expression notation <literal>.*</literal>, <literal>?</literal> which is translated to <literal>.</literal>, and <literal>$</literal> which is matched literally. You can emulate these pattern characters at need by writing <literal>?</literal> for <literal>.</literal>, <literal>(<replaceable class="parameter">R</replaceable>+|)</literal> for <literal><replaceable class="parameter">R</replaceable>*</literal>, or <literal>(<replaceable class="parameter">R</replaceable>|)</literal> for <literal><replaceable class="parameter">R</replaceable>?</literal>. <literal>$</literal> is not needed as a regular-expression character since the pattern must match the whole name, unlike the usual interpretation of regular expressions (in other words, <literal>$</literal> is automatically appended to your pattern). Write <literal>*</literal> at the beginning and/or end if you don't wish the pattern to be anchored. Note that within double quotes, all regular expression special characters lose their special meanings and are matched literally. Also, the regular expression special characters are matched literally in operator name patterns (i.e., the argument of <literal>\do</literal>). 上級者は文字クラス(例えば任意の数にマッチする[0-9])などの正規表現を使用することができます。 ほぼすべての正規表現の特殊文字は9.7.3の規定通りに動作しますが、上述のように.が区切り文字となる点、*は正規表現の.*になる点、?.になる点、$がそのまま扱われる点は例外です。 .の代わりに?と、R*の代わりに(R+|)と、R?の代わりに(R|)と記述することで、これらのパターン文字を模擬することができます。 通常の正規表現の解釈と異なり、パターンは常に名前全体にマッチするため、$を正規表現文字として扱う必要はありません。 (言い替えると、$は自動的にパターンに追加されます。) パターンの適用位置を決められない場合は、*を先頭や末尾に記載してください。 二重引用符の内側では、正規表現の特殊文字はその意味を失い、文字そのものにマッチすることになる点に注意してください。 また、正規表現の特殊文字は、演算子名のパターン(つまり\doの引数)では文字そのものにマッチします。

高度な機能

<title>Advanced Features</title> <refsect3 id="app-psql-variables" xreflabel="Variables">

変数

<title>Variables</title>

<application>psql</application> provides variable substitution features similar to common Unix command shells. Variables are simply name/value pairs, where the value can be any string of any length. The name must consist of letters (including non-Latin letters), digits, and underscores. psqlは一般的なUnixコマンドシェルに似た変数の置換機能を提供します。 変数とは名前と値の組み合わせです。 値として任意の長さの任意の文字列を使用できます。 名前は文字(非ラテン文字を含む)、数字、アンダースコアから構成されなければなりません。

To set a variable, use the <application>psql</application> meta-command <command>\set</command>. For example, 変数を設定するには、psql\setメタコマンドを以下のように使用します。

testdb=> \set foo bar

sets the variable <literal>foo</literal> to the value <literal>bar</literal>. To retrieve the content of the variable, precede the name with a colon, for example: この例では、変数foobarという値に設定しています。 変数の内容を取り出すには、以下のように変数名の前にコロンを付けます。

testdb=> \echo :foo
bar

This works in both regular SQL commands and meta-commands; there is more detail in <xref linkend="app-psql-interpolation"/>, below. これは通常のSQLコマンド内とメタコマンド内の両方で動作します。 後述のSQL差し替えで詳しく説明します。

If you call <command>\set</command> without a second argument, the variable is set to an empty-string value. To unset (i.e., delete) a variable, use the command <command>\unset</command>. To show the values of all variables, call <command>\set</command> without any argument. 第二引数なしで\setを呼び出すと、その変数には空文字列の値が設定されます。 変数を未設定状態にする(つまり削除する)ためには、\unsetコマンドを使用してください。 すべての変数の値を表示するためには、引数なしで\setを呼び出してください。

注記

The arguments of <command>\set</command> are subject to the same substitution rules as with other commands. Thus you can construct interesting references such as <literal>\set :foo 'something'</literal> and get <quote>soft links</quote> or <quote>variable variables</quote> of <productname>Perl</productname> or <productname><acronym>PHP</acronym></productname> fame, respectively. Unfortunately (or fortunately?), there is no way to do anything useful with these constructs. On the other hand, <literal>\set bar :foo</literal> is a perfectly valid way to copy a variable. \setの引数は他のコマンドと同じ置換規則に従います。 このため、\set :foo 'something'のような参照を作成して、PerlにおけるソフトリンクPHPにおける可変変数に当たるものを得られます。 しかし、残念ながら(あるいは幸運にも)、このような構成をうまく使用する方法はありません。 一方、\set bar :fooのようにして変数をコピーするのは、完全に有効な方法です。

A number of these variables are treated specially by <application>psql</application>. They represent certain option settings that can be changed at run time by altering the value of the variable, or in some cases represent changeable state of <application>psql</application>. By convention, all specially treated variables' names consist of all upper-case ASCII letters (and possibly digits and underscores). To ensure maximum compatibility in the future, avoid using such variable names for your own purposes. これらの変数の多くは、psqlに特別扱いされています。 これらは、変数の値を変更することにより、実行時に変更可能なオプションの設定を表現します。 またpsqlの変更可能な状態を表現しているものもあります。 慣習上、特別視される変数の名前はすべてASCII大文字(と数字とアンダースコア)からなります。 将来的な互換性を最大限考慮するために、自分で作成した変数にはこのような変数名を使用しないでください。

Variables that control <application>psql</application>'s behavior generally cannot be unset or set to invalid values. An <literal>\unset</literal> command is allowed but is interpreted as setting the variable to its default value. A <literal>\set</literal> command without a second argument is interpreted as setting the variable to <literal>on</literal>, for control variables that accept that value, and is rejected for others. Also, control variables that accept the values <literal>on</literal> and <literal>off</literal> will also accept other common spellings of Boolean values, such as <literal>true</literal> and <literal>false</literal>. psqlの動作を制御する変数は、一般に未設定にしたり、無効な値に設定したりすることができません。 \unsetコマンドの実行は許されますが、変数をデフォルト値に設定するものとして解釈されます。 第2引数なしの\setコマンドは、onの値を受け付ける制御変数では変数をonに設定するものとして解釈され、それ以外の場合は拒絶されます。 また、 onoffの値を受け付ける制御変数では、truefalseなどそれ以外の論理値の共通で使われる綴りも受け付けます。

The specially treated variables are: 特別に扱われる変数を以下に示します。

AUTOCOMMIT #

When <literal>on</literal> (the default), each SQL command is automatically committed upon successful completion. To postpone commit in this mode, you must enter a <command>BEGIN</command> or <command>START TRANSACTION</command> SQL command. When <literal>off</literal> or unset, SQL commands are not committed until you explicitly issue <command>COMMIT</command> or <command>END</command>. The autocommit-off mode works by issuing an implicit <command>BEGIN</command> for you, just before any command that is not already in a transaction block and is not itself a <command>BEGIN</command> or other transaction-control command, nor a command that cannot be executed inside a transaction block (such as <command>VACUUM</command>). この変数の値がonの場合(これがデフォルトです)、各SQLコマンドの実行が成功すると、自動的にコミットされます。 コミットを延期するには、BEGINもしくはSQLのSTART TRANSACTIONコマンドを入力する必要があります。 値がoffもしくは未設定の場合、明示的にCOMMITもしくはENDを発行するまで、SQLコマンドはコミットされません。 自動コミット無効モードでは、トランザクションブロック以外でコマンドが発行されると、そのコマンドを実行する前に、自動的にBEGINコマンドが発行されます(ただし、そのコマンド自体がBEGINコマンドやその他のトランザクション制御コマンドである場合、トランザクションブロック内で実行することができないコマンド(VACUUMなど)である場合は除きます)

注記

In autocommit-off mode, you must explicitly abandon any failed transaction by entering <command>ABORT</command> or <command>ROLLBACK</command>. Also keep in mind that if you exit the session without committing, your work will be lost. 自動コミット無効モードでは、ABORTROLLBACKを発行して、明示的に失敗したトランザクションを放棄しなければなりません。 また、コミットせずにセッションを終了した場合は、作業が失われてしまうので注意してください。

注記

The autocommit-on mode is <productname>PostgreSQL</productname>'s traditional behavior, but autocommit-off is closer to the SQL spec. If you prefer autocommit-off, you might wish to set it in the system-wide <filename>psqlrc</filename> file or your <filename>~/.psqlrc</filename> file. PostgreSQLは、伝統的に自動コミット有効モードで動作していましたが、自動コミット無効モードの方がよりSQLの仕様に近いものです。 自動コミット無効モードは、システム全体に対するpsqlrcファイル、もしくは、個人用の~/.psqlrcファイルで設定すれば実現できます。

COMP_KEYWORD_CASE #

Determines which letter case to use when completing an SQL key word. If set to <literal>lower</literal> or <literal>upper</literal>, the completed word will be in lower or upper case, respectively. If set to <literal>preserve-lower</literal> or <literal>preserve-upper</literal> (the default), the completed word will be in the case of the word already entered, but words being completed without anything entered will be in lower or upper case, respectively. SQLキーワードを補完する時に大文字小文字のどちらを使用するかを決定します。 lowerまたはupperが設定された場合、補完された単語はそれぞれ小文字または大文字になります。 preserve-lowerまたはpreserve-upper(デフォルト)が設定された場合、 補完された単語は入力済みの文字の大文字小文字を引き継ぎますが、何も入力されていない場合はそれぞれ小文字または大文字に補完されます。

DBNAME #

The name of the database you are currently connected to. This is set every time you connect to a database (including program start-up), but can be changed or unset. 現在接続しているデータベース名です。 この変数は(プログラム起動時も含め)データベースに接続する度に設定されますが、変更したり、未設定にすることもできます。

ECHO #

If set to <literal>all</literal>, all nonempty input lines are printed to standard output as they are read. (This does not apply to lines read interactively.) To select this behavior on program start-up, use the switch <option>-a</option>. If set to <literal>queries</literal>, <application>psql</application> prints each query to standard output as it is sent to the server. The switch to select this behavior is <option>-e</option>. If set to <literal>errors</literal>, then only failed queries are displayed on standard error output. The switch for this behavior is <option>-b</option>. If set to <literal>none</literal> (the default), then no queries are displayed. allに設定された場合、空でない全ての入力行は、標準出力に書き出されます。 (これは対話式に読み込まれる行には適用されません。) この動作をプログラム起動時に設定するには、-aスイッチを使用してください。 queriesに設定された場合、psqlは各問い合わせがサーバに送信されるときに表示します。 この動作を選択するオプションは-eです。 errorsに設定された場合、失敗した問い合わせのみが標準エラー出力に出力されます。 この動作に対応するオプションは-bです。 none(デフォルトです)に設定された場合、どの問い合わせも表示されません。

ECHO_HIDDEN #

When this variable is set to <literal>on</literal> and a backslash command queries the database, the query is first shown. This feature helps you to study <productname>PostgreSQL</productname> internals and provide similar functionality in your own programs. (To select this behavior on program start-up, use the switch <option>-E</option>.) If you set this variable to the value <literal>noexec</literal>, the queries are just shown but are not actually sent to the server and executed. The default value is <literal>off</literal>. この変数がonに設定されている場合、バックスラッシュコマンドがデータベースに問い合わせを行う時、最初にその問い合わせが表示されます。 この機能は、PostgreSQL内部動作について調べたり、自作プログラム内で同様の関数機能を用意したりするのに役立つでしょう。 (この動作をプログラム起動時に選択するには-Eスイッチを使用してください)。 この変数をnoexecという値に設定した場合、問い合わせは実際にサーバに送信、実行されずに、単に表示されるだけになります。 デフォルト値はoffです。

ENCODING #

The current client character set encoding. This is set every time you connect to a database (including program start-up), and when you change the encoding with <literal>\encoding</literal>, but it can be changed or unset. 現在のクライアント側の文字セット符号化方式です。 これは(プログラムの起動時を含め)データベースに接続する度に、また符号化方式を\encodingで変更した時に設定されますが、変更したり、未設定にすることができます。

ERROR #

<literal>true</literal> if the last SQL query failed, <literal>false</literal> if it succeeded. See also <varname>SQLSTATE</varname>. 最後のSQL問い合わせが失敗したならtrue、成功したならfalseSQLSTATEも参照してください。

FETCH_COUNT #

If this variable is set to an integer value greater than zero, the results of <command>SELECT</command> queries are fetched and displayed in groups of that many rows, rather than the default behavior of collecting the entire result set before display. Therefore only a limited amount of memory is used, regardless of the size of the result set. Settings of 100 to 1000 are commonly used when enabling this feature. Keep in mind that when using this feature, a query might fail after having already displayed some rows. この変数が0より大きな整数値に設定されている場合、SELECT問い合わせの結果は、指定した行数の集合として取り出され、表示されます。 デフォルトの動作では、表示する前にすべての結果が取り出されます。 したがって、結果セットの大きさに関係なくメモリの使用量が限定されます。 この機能を有効とする場合に100から1000までの値がよく使用されます。 この機能を使用する際には、既に一部の行が表示されている場合、問い合わせが失敗する可能性があることに注意してください。

ヒント

Although you can use any output format with this feature, the default <literal>aligned</literal> format tends to look bad because each group of <varname>FETCH_COUNT</varname> rows will be formatted separately, leading to varying column widths across the row groups. The other output formats work better. 任意の出力書式でこの機能を使用することができますが、デフォルトのaligned書式は適していません。 FETCH_COUNT行のグループそれぞれが別々に整形されてしまい、行のグループによって列幅が異なることになるためです。 他の出力書式は適切に動作します。

HIDE_TABLEAM #

If this variable is set to <literal>true</literal>, a table's access method details are not displayed. This is mainly useful for regression tests. この変数がtrueに設定されていれば、テーブルのアクセスメソッドの詳細は表示されません。 これは主にリグレッションテストで有用です。

HIDE_TOAST_COMPRESSION #

If this variable is set to <literal>true</literal>, column compression method details are not displayed. This is mainly useful for regression tests. この変数がtrueに設定されていれば、列の圧縮法の詳細は表示されません。 これは主にリグレッションテストで有用です。

HISTCONTROL #

If this variable is set to <literal>ignorespace</literal>, lines which begin with a space are not entered into the history list. If set to a value of <literal>ignoredups</literal>, lines matching the previous history line are not entered. A value of <literal>ignoreboth</literal> combines the two options. If set to <literal>none</literal> (the default), all lines read in interactive mode are saved on the history list. この変数をignorespaceに設定した場合、空白文字から始まる行は履歴リストには入りません。 ignoredupsに設定した場合、直前の履歴と同じ行は履歴リストに入りません。 ignorebothに設定した場合は、上記の2つを組み合わせたものになります。 none(デフォルトです)に設定した場合は、対話モードで読まれる全ての行が履歴リストに保存されます。

注記

This feature was shamelessly plagiarized from <application>Bash</application>. この機能はBashの機能を真似たものです。

HISTFILE #

The file name that will be used to store the history list. If unset, the file name is taken from the <envar>PSQL_HISTORY</envar> environment variable. If that is not set either, the default is <filename>~/.psql_history</filename>, or <filename>%APPDATA%\postgresql\psql_history</filename> on Windows. For example, putting: 履歴を格納するために使用されるファイルの名前です。 未設定にすると、ファイル名は環境変数PSQL_HISTORYから取得されます。 それも設定されていない場合、デフォルトは~/.psql_history、またはWindowsでは%APPDATA%\postgresql\psql_historyです。 例えば、以下を

\set HISTFILE ~/.psql_history-:DBNAME

in <filename>~/.psqlrc</filename> will cause <application>psql</application> to maintain a separate history for each database. ~/.psqlrc内に指定すると、psqlはデータベースごとに別々の履歴を保持します。

注記

This feature was shamelessly plagiarized from <application>Bash</application>. この機能はBashの機能を真似たものです。

HISTSIZE #

The maximum number of commands to store in the command history (default 500). If set to a negative value, no limit is applied. コマンド履歴に保存するコマンドの最大数(デフォルトは500)です。 負の値に設定すると、制限がなくなります。

注記

This feature was shamelessly plagiarized from <application>Bash</application>. この機能はBashの機能を真似たものです。

HOST #

The database server host you are currently connected to. This is set every time you connect to a database (including program start-up), but can be changed or unset. 接続中のデータベースサーバホストです。 この変数は(プログラム起動時も含め)データベースに接続する度に設定されますが、変更したり、未設定にすることもできます。

IGNOREEOF #

If set to 1 or less, sending an <acronym>EOF</acronym> character (usually <keycombo action="simul"><keycap>Control</keycap><keycap>D</keycap></keycombo>) to an interactive session of <application>psql</application> will terminate the application. If set to a larger numeric value, that many consecutive <acronym>EOF</acronym> characters must be typed to make an interactive session terminate. If the variable is set to a non-numeric value, it is interpreted as 10. The default is 0. この変数を1以下に設定すると、対話式セッションにEOF文字(通常Control+D)が送信された時、psqlが終了します。 1より大きな数値を設定すると、対話的セッションを終了するには、指定された数だけ、続けてEOF文字を送信しなければなりません。 数値以外を設定した場合は、10と解釈されます。 デフォルトは0です。

注記

This feature was shamelessly plagiarized from <application>Bash</application>. この機能はBashの機能を真似たものです。

LASTOID #

The value of the last affected OID, as returned from an <command>INSERT</command> or <command>\lo_import</command> command. This variable is only guaranteed to be valid until after the result of the next <acronym>SQL</acronym> command has been displayed. <productname>PostgreSQL</productname> servers since version 12 do not support OID system columns anymore, thus LASTOID will always be 0 following <command>INSERT</command> when targeting such servers. INSERT\lo_importコマンドによって返された、最後に影響を受けたOIDの値です。 この変数は、次のSQLコマンドの結果が表示されるまでの間のみ保証されています。 バージョン12からPostgreSQLサーバはOIDシステム列をサポートしませんので、そのようなサーバを対象とした場合INSERTの後は、LASTOIDは常に0です。

LAST_ERROR_MESSAGE
LAST_ERROR_SQLSTATE #

The primary error message and associated SQLSTATE code for the most recent failed query in the current <application>psql</application> session, or an empty string and <literal>00000</literal> if no error has occurred in the current session. 現在のpsqlセッションの直近の失敗した問い合わせに対する主エラーメッセージと関連するSQLSTATEコード。あるいは、現在セッションでエラーが無い場合、空文字列と00000

ON_ERROR_ROLLBACK #

When set to <literal>on</literal>, if a statement in a transaction block generates an error, the error is ignored and the transaction continues. When set to <literal>interactive</literal>, such errors are only ignored in interactive sessions, and not when reading script files. When set to <literal>off</literal> (the default), a statement in a transaction block that generates an error aborts the entire transaction. The error rollback mode works by issuing an implicit <command>SAVEPOINT</command> for you, just before each command that is in a transaction block, and then rolling back to the savepoint if the command fails. onに設定されている場合、トランザクションブロック内である文がエラーとなった時に、そのエラーは無視され、トランザクションは継続します。 interactiveに設定されている場合、対話式セッション内の場合にのみエラーは無視されます。スクリプトファイルを読み込んでいる場合は無視されません。 off(デフォルトです)に設定されている場合、トランザクションブロック内の文がエラーになると、トランザクション全体をアボートします。 エラーロールバックのモードは、トランザクションブロック内で各コマンドの実行直前に暗黙的なSAVEPOINTを行い、コマンドが失敗した時にこのセーブポイントにロールバックすることで実現されています。

ON_ERROR_STOP #

By default, command processing continues after an error. When this variable is set to <literal>on</literal>, processing will instead stop immediately. In interactive mode, <application>psql</application> will return to the command prompt; otherwise, <application>psql</application> will exit, returning error code 3 to distinguish this case from fatal error conditions, which are reported using error code 1. In either case, any currently running scripts (the top-level script, if any, and any other scripts which it may have in invoked) will be terminated immediately. If the top-level command string contained multiple SQL commands, processing will stop with the current command. デフォルトではエラーの後もコマンド処理は続行されます。 この変数がonに設定されていると、代わりに即座に停止します。 対話モードではpsqlはコマンドプロンプトに戻ります。 これ以外ではpsqlは終了し、エラーコード1を返す致命的エラー条件と区別できるように、エラーコード3を返します。 どちらの場合でも、現在実行中のスクリプト(トップレベルのスクリプト、もしあれば関連性を持つ他のスクリプトすべて)は即座に終了します。 トップレベルのコマンド文字列が複数のSQLコマンドを含む場合、その時点のコマンドで処理は終了します。

PORT #

The database server port to which you are currently connected. This is set every time you connect to a database (including program start-up), but can be changed or unset. 接続中のデータベースサーバのポートです。 この変数は(プログラム起動時も含め)データベースに接続する度に設定されますが、変更することも未設定にすることもできます。

PROMPT1
PROMPT2
PROMPT3 #

These specify what the prompts <application>psql</application> issues should look like. See <xref linkend="app-psql-prompting"/> below. これらの変数は、psqlが発行するプロンプトの見た目を指定します。 後述のプロンプトを参照してください。

QUIET #

Setting this variable to <literal>on</literal> is equivalent to the command line option <option>-q</option>. It is probably not too useful in interactive mode. この変数をonに設定することはコマンドラインオプション-qと同じ効力を持ちます。 対話式モードではあまり役立ちません。

ROW_COUNT #

The number of rows returned or affected by the last SQL query, or 0 if the query failed or did not report a row count. 最後のSQL問い合わせにより、返された、あるいは、影響をうけた行数。あるいは、問い合わせが失敗したか行数が報告されていない場合、0。

SERVER_VERSION_NAME
SERVER_VERSION_NUM #

The server's version number as a string, for example <literal>9.6.2</literal>, <literal>10.1</literal> or <literal>11beta1</literal>, and in numeric form, for example <literal>90602</literal> or <literal>100001</literal>. These are set every time you connect to a database (including program start-up), but can be changed or unset. 文字列としてのサーバのバージョン番号、例えば9.6.210.111beta1など、および数値形式でのバージョン番号、例えば90602100001などです。 これらは(プログラムの起動時を含め)データベースに接続する度に設定されますが、変更することも未設定にすることもできます。

SHELL_ERROR #

<literal>true</literal> if the last shell command failed, <literal>false</literal> if it succeeded. This applies to shell commands invoked via the <literal>\!</literal>, <literal>\g</literal>, <literal>\o</literal>, <literal>\w</literal>, and <literal>\copy</literal> meta-commands, as well as backquote (<literal>`</literal>) expansion. Note that for <literal>\o</literal>, this variable is updated when the output pipe is closed by the next <literal>\o</literal> command. See also <varname>SHELL_EXIT_CODE</varname>. 最後のシェルコマンドが失敗した場合はtrue、成功した場合はfalse。 これは、\!\g\o\w、および\copyメタコマンドを介して呼び出されたシェルコマンドと、逆引用符(`)展開に適用されます。 \oの場合、次の\oコマンドによって出力パイプが閉じられた時に、この変数が更新されることに注意してください。 SHELL_EXIT_CODEも参照してください。

SHELL_EXIT_CODE #

The exit status returned by the last shell command. 0&ndash;127 represent program exit codes, 128&ndash;255 indicate termination by a signal, and -1 indicates failure to launch a program or to collect its exit status. This applies to shell commands invoked via the <literal>\!</literal>, <literal>\g</literal>, <literal>\o</literal>, <literal>\w</literal>, and <literal>\copy</literal> meta-commands, as well as backquote (<literal>`</literal>) expansion. Note that for <literal>\o</literal>, this variable is updated when the output pipe is closed by the next <literal>\o</literal> command. See also <varname>SHELL_ERROR</varname>. 最後のシェルコマンドによって返された終了ステータス。 0–127はプログラム終了コードを表し、128–255はシグナルによる終了を示し、-1はプログラムの起動またはその終了ステータスの収集に失敗したことを示します。 これは、\!\g\o\w、および\copyメタコマンドを介して呼び出されたシェルコマンドと、逆引用符(`)展開に適用されます。 \oの場合、この変数は、次の\oコマンドによって出力パイプが閉じられた時に、更新されます。 SHELL_ERRORも参照してください。

SHOW_ALL_RESULTS #

When this variable is set to <literal>off</literal>, only the last result of a combined query (<literal>\;</literal>) is shown instead of all of them. The default is <literal>on</literal>. The off behavior is for compatibility with older versions of psql. この変数がoffに設定されている場合は、結合された問い合わせ(\;)の最後の結果だけが表示されます。すべての結果は表示されません。 デフォルトはonです。 offの動作は古いバージョンのpsqlとの互換性のためです。

SHOW_CONTEXT #

This variable can be set to the values <literal>never</literal>, <literal>errors</literal>, or <literal>always</literal> to control whether <literal>CONTEXT</literal> fields are displayed in messages from the server. The default is <literal>errors</literal> (meaning that context will be shown in error messages, but not in notice or warning messages). This setting has no effect when <varname>VERBOSITY</varname> is set to <literal>terse</literal> or <literal>sqlstate</literal>. (See also <command>\errverbose</command>, for use when you want a verbose version of the error you just got.) この変数は値nevererrors、あるいはalwaysに設定することができ、CONTEXTフィールドがサーバからのメッセージに表示されるかどうかを制御します。 デフォルトはerrorsです(CONTEXTはエラーメッセージ内では表示されますが、注意や警告メッセージでは表示されません)。 この設定はVERBOSITYterseまたはsqlstateに設定されている場合は効果がありません。 (\errverboseも参照してください。こちらは受け取ったばかりのエラーについて、冗長なメッセージが必要なときに使えます。)

SINGLELINE #

Setting this variable to <literal>on</literal> is equivalent to the command line option <option>-S</option>. この変数をonに設定することはコマンドラインオプション-Sと同じ効力を持ちます。

SINGLESTEP #

Setting this variable to <literal>on</literal> is equivalent to the command line option <option>-s</option>. この変数をonに設定することはコマンドラインオプション-sと同じ効力を持ちます。

SQLSTATE #

The error code (see <xref linkend="errcodes-appendix"/>) associated with the last SQL query's failure, or <literal>00000</literal> if it succeeded. 最後のSQL問い合わせの失敗に関するエラーコード(付録Aを参照)、あるいは、SQLが成功した場合には00000

USER #

The database user you are currently connected as. This is set every time you connect to a database (including program start-up), but can be changed or unset. 接続中のデータベースユーザです。 この変数は(プログラム起動時も含め)データベースに接続する度に設定されますが、変更することも未設定にすることもできます。

VERBOSITY #

This variable can be set to the values <literal>default</literal>, <literal>verbose</literal>, <literal>terse</literal>, or <literal>sqlstate</literal> to control the verbosity of error reports. (See also <command>\errverbose</command>, for use when you want a verbose version of the error you just got.) この変数をdefaultverbosetersesqlstateのいずれかに設定することで、エラー報告の冗長性を制御できます。 (\errverboseも参照してください。こちらは受け取ったばかりのエラーについて、冗長なメッセージが必要なときに使えます。)

VERSION
VERSION_NAME
VERSION_NUM #

These variables are set at program start-up to reflect <application>psql</application>'s version, respectively as a verbose string, a short string (e.g., <literal>9.6.2</literal>, <literal>10.1</literal>, or <literal>11beta1</literal>), and a number (e.g., <literal>90602</literal> or <literal>100001</literal>). They can be changed or unset. これらの変数はプログラムの起動時にpsqlのバージョンを表すために設定され、それぞれ冗長な文字列、短い文字列(例:9.6.210.111beta1)、数字(例:90602100001)です。 これらは変更することも未設定にすることもできます。

<refsect3 id="app-psql-interpolation" xreflabel="SQL Interpolation">

SQL差し替え

<title><acronym>SQL</acronym> Interpolation</title>

A key feature of <application>psql</application> variables is that you can substitute (<quote>interpolate</quote>) them into regular <acronym>SQL</acronym> statements, as well as the arguments of meta-commands. Furthermore, <application>psql</application> provides facilities for ensuring that variable values used as SQL literals and identifiers are properly quoted. The syntax for interpolating a value without any quoting is to prepend the variable name with a colon (<literal>:</literal>). For example, psqlの変数には、通常のSQL文やメタコマンドの引数の中で使用(差し替え:interpolate)できるという重要な機能があります。 さらにpsqlは、 SQLリテラルと識別子として使用される変数の値が適切に引用符付けされていることを保証する機能を提供します。 引用符付けをまったく行わずに差し替えるための構文は、変数名の前にコロン(:)を付けることです。 以下に例を示します。

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

would query the table <literal>my_table</literal>. Note that this may be unsafe: the value of the variable is copied literally, so it can contain unbalanced quotes, or even backslash commands. You must make sure that it makes sense where you put it. この例では、問い合わせはmy_tableテーブルに対して行われます。 これが安全ではない場合があることに注意して下さい。 変数の値はそのままコピーされるので、対応のとれていない引用符やバックスラッシュコマンドさえも含めることができます。 挿入した場所で変数が展開された時に、確実に正しい意味になるようにしなければなりません。

When a value is to be used as an SQL literal or identifier, it is safest to arrange for it to be quoted. To quote the value of a variable as an SQL literal, write a colon followed by the variable name in single quotes. To quote the value as an SQL identifier, write a colon followed by the variable name in double quotes. These constructs deal correctly with quotes and other special characters embedded within the variable value. The previous example would be more safely written this way: 値がSQLリテラルや識別子内で使用される場合、それが引用符付けされるように調整することがもっとも安全です。 SQLリテラルとして変数値を引用符付けするためには、コロンの後に変数名を単一引用符で括って記述してください。 SQL識別子として値を引用符付けするためには、コロン後に変数名を二重引用符で括って記述してください。 これらの式は正しく引用符と変数値内に埋め込まれた特殊文字を扱います。 前の例は以下のように記述することでより安全になります。

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

Variable interpolation will not be performed within quoted <acronym>SQL</acronym> literals and identifiers. Therefore, a construction such as <literal>':foo'</literal> doesn't work to produce a quoted literal from a variable's value (and it would be unsafe if it did work, since it wouldn't correctly handle quotes embedded in the value). 変数差し替えは、引用符付けされたSQLリテラルと識別子の中では行われません。 したがって':foo'などの式は、変数の値から引用符付けしたリテラルを生成するようには動作しません。 (値の中に埋め込まれた引用符を正しく取り扱えませんので、もし動作したとしたら安全ではありません。)

One example use of this mechanism is to copy the contents of a file into a table column. First load the file into a variable and then interpolate the variable's value as a quoted string: この機能の有効な利用方法の例は、ファイルの内容をテーブル列にコピーする場合も利用することができます。 その際は、ファイルをまず変数に読み込み、引用符付けした文字列として変数名を差し替えます。

testdb=> \set content `cat my_file.txt`
testdb=> INSERT INTO my_table VALUES (:'content');

(Note that this still won't work if <filename>my_file.txt</filename> contains NUL bytes. <application>psql</application> does not support embedded NUL bytes in variable values.) (my_file.txtにNULバイトが含まれている場合、これはうまく動作しないことに注意してください。 psqlは変数値内に埋め込まれたNULバイトをサポートしません。)

Since colons can legally appear in SQL commands, an apparent attempt at interpolation (that is, <literal>:name</literal>, <literal>:'name'</literal>, or <literal>:"name"</literal>) is not replaced unless the named variable is currently set. In any case, you can escape a colon with a backslash to protect it from substitution. コロン(:)もSQLコマンド内で正規に使用できますので、 指定した変数が現在設定されていない場合、差し替え時の見かけの置換(:name:'name':"name")は行われません。 コロンをバックスラッシュでエスケープすれば、常に差し替えから保護することができます。

The <literal>:{?<replaceable>name</replaceable>}</literal> special syntax returns TRUE or FALSE depending on whether the variable exists or not, and is thus always substituted, unless the colon is backslash-escaped. :{?name}特別構文は、その変数が存在しているかどうかに応じてTRUEかFALSEを返します。従って、コロンがバックスラッシュでエスケープされていない限り、常に置き換えられます。

The colon syntax for variables is standard <acronym>SQL</acronym> for embedded query languages, such as <application>ECPG</application>. The colon syntaxes for array slices and type casts are <productname>PostgreSQL</productname> extensions, which can sometimes conflict with the standard usage. The colon-quote syntax for escaping a variable's value as an SQL literal or identifier is a <application>psql</application> extension. 変数用のコロン構文は、ECPGのような組み込みの問い合わせ言語用の標準SQLとして規定されています。 配列の一部の切り出し、および型キャスト用のコロン構文はPostgreSQLの拡張であり、標準での使用方法と競合することがあります。 SQLリテラルまたは識別子として変数の値をエスケープさせる引用符付きコロン構文はpsqlの拡張です。

<refsect3 id="app-psql-prompting" xreflabel="Prompting">

プロンプト

<title>Prompting</title>

The prompts <application>psql</application> issues can be customized to your preference. The three variables <varname>PROMPT1</varname>, <varname>PROMPT2</varname>, and <varname>PROMPT3</varname> contain strings and special escape sequences that describe the appearance of the prompt. Prompt 1 is the normal prompt that is issued when <application>psql</application> requests a new command. Prompt 2 is issued when more input is expected during command entry, for example because the command was not terminated with a semicolon or a quote was not closed. Prompt 3 is issued when you are running an <acronym>SQL</acronym> <command>COPY FROM STDIN</command> command and you need to type in a row value on the terminal. psqlが発行するプロンプトは好みに応じてカスタマイズできます。 PROMPT1PROMPT2PROMPT3という3つの変数はプロンプトの表示内容を示す文字列や特別なエスケープシーケンスを持ちます。 プロンプト1はpsqlが新しいコマンドを受け付ける際に発行される通常のプロンプトです。 プロンプト2は、例えばコマンドがセミコロンで終わっていない、または、引用符が閉じていないなど、コマンドの入力中にさらなる入力が期待される際に発行されます。 プロンプト3はSQLCOPY FROM STDINコマンドを実行中で、端末上で行の値の入力が必要な際に発行されます。

The value of the selected prompt variable is printed literally, except where a percent sign (<literal>%</literal>) is encountered. Depending on the next character, certain other text is substituted instead. Defined substitutions are: 選択されたプロンプト変数の値はそのまま文字として表示されます。 ただし、パーセント(%)が含まれる場合は例外です。 この場合は、次の文字に従って、特定のテキストに置換されます。 置換対象として定義されているのは次のものです。

%M #

The full host name (with domain name) of the database server, or <literal>[local]</literal> if the connection is over a Unix domain socket, or <literal>[local:<replaceable>/dir/name</replaceable>]</literal>, if the Unix domain socket is not at the compiled in default location. データベースサーバの(ドメイン名付きの)完全なホスト名です。その接続がUnixドメインソケットの場合は[local]となります。 ただし、Unixドメインソケットがコンパイル時に設定したデフォルトの場所に存在しない場合は、[local:/dir/name]となります。

%m #

The host name of the database server, truncated at the first dot, or <literal>[local]</literal> if the connection is over a Unix domain socket. 最初のドット以降を省略したデータベースサーバのホスト名です。その接続がUnixドメインソケットの場合は[local]となります。

%> #

データベースサーバが監視するポート番号です。

%n #

The database session user name. (The expansion of this value might change during a database session as the result of the command <command>SET SESSION AUTHORIZATION</command>.) データベースセッションユーザの名前です (この値の展開結果は、SET SESSION AUTHORIZATIONコマンドの実行によってデータベースセッション中に変わることがあります)。

%/ #

接続中のデータベース名です。

%~ #

デフォルトデータベースの場合に~(チルダ)が出力される点を除いて、%/と同じです。

%# #

If the session user is a database superuser, then a <literal>#</literal>, otherwise a <literal>&gt;</literal>. (The expansion of this value might change during a database session as the result of the command <command>SET SESSION AUTHORIZATION</command>.) セッションユーザがデータベーススーパーユーザである場合は#、それ以外の場合は>となります (この値の展開結果は、SET SESSION AUTHORIZATIONコマンドの実行によってデータベースセッション中に変わることがあります)。

%p #
<para>The process ID of the backend currently connected to.</para>

現在接続しているバックエンドのプロセスIDです。

%R #

In prompt 1 normally <literal>=</literal>, but <literal>@</literal> if the session is in an inactive branch of a conditional block, or <literal>^</literal> if in single-line mode, or <literal>!</literal> if the session is disconnected from the database (which can happen if <command>\connect</command> fails). In prompt 2 <literal>%R</literal> is replaced by a character that depends on why <application>psql</application> expects more input: <literal>-</literal> if the command simply wasn't terminated yet, but <literal>*</literal> if there is an unfinished <literal>/* ... */</literal> comment, a single quote if there is an unfinished quoted string, a double quote if there is an unfinished quoted identifier, a dollar sign if there is an unfinished dollar-quoted string, or <literal>(</literal> if there is an unmatched left parenthesis. In prompt 3 <literal>%R</literal> doesn't produce anything. プロンプト1の場合、通常は=ですが、条件ブロックの使われない部分では@、シングル行モードでは^、また、データベースとの接続が切れたセッションでは!になります(\connectが失敗した場合に発生します)。 プロンプト2の場合、%Rは、なぜpsqlがさらなる入力を要求しているかによって決まる文字に置き換えられます。 これは、単にコマンドがまだ終了していない場合は-ですが、/* ... */のコメントがまだ終了していない場合は*、引用符付きの文字列が終了していない場合は単一引用符、引用符付きの識別子が終了していない場合は二重引用符、ドル引用文字列が終了していない場合はドル記号、そして閉じられていない左括弧がある場合は(となります。 プロンプト3の場合、%Rに対しては何も表示されません。

%x #

Transaction status: an empty string when not in a transaction block, or <literal>*</literal> when in a transaction block, or <literal>!</literal> when in a failed transaction block, or <literal>?</literal> when the transaction state is indeterminate (for example, because there is no connection). トランザクションの状態です。 トランザクションブロックの外にいる場合は空文字列に、トランザクションブロックの中にいる場合は*に、失敗したトランザクションブロックの中にいる場合は!に、(接続されていないなど)トランザクションの状態が不定の場合は?になります。

%l #

The line number inside the current statement, starting from <literal>1</literal>. 現在の文の内部での行番号で、1から始まります。

%digits #

The character with the indicated octal code is substituted. 指定された8進の数値コードの文字に置換されます。

%:name: #

The value of the <application>psql</application> variable <replaceable class="parameter">name</replaceable>. See <xref linkend="app-psql-variables"/>, above, for details. psqlの変数nameの値です。 詳細は上記の変数を参照してください。

%`command` #

The output of <replaceable class="parameter">command</replaceable>, similar to ordinary <quote>back-tick</quote> substitution. 通常の逆引用符による置き換えと同様で、commandの出力です。

%[ ... %] #

Prompts can contain terminal control characters which, for example, change the color, background, or style of the prompt text, or change the title of the terminal window. In order for the line editing features of <application>Readline</application> to work properly, these non-printing control characters must be designated as invisible by surrounding them with <literal>%[</literal> and <literal>%]</literal>. Multiple pairs of these can occur within the prompt. For example: プロンプトには端末制御文字を含めることができます。 具体的には、色、背景、プロンプトテキストの様式の変更、端末ウィンドウのタイトルの変更などが指定できます。 Readlineの行編集機能を適切に動作させるためには、印字されない制御文字を%[%]で囲んで、不可視であることを明示しなければなりません。 この記号の組み合わせはプロンプト内に複数記述することができます。 以下に例を示します。

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

results in a boldfaced (<literal>1;</literal>) yellow-on-black (<literal>33;40</literal>) prompt on VT100-compatible, color-capable terminals. これにより、VT100互換のカラー端末では、太字フォントで(1;)、黒地に黄色の(33;40)プロンプトが表示されます。

%w #

Whitespace of the same width as the most recent output of <varname>PROMPT1</varname>. This can be used as a <varname>PROMPT2</varname> setting, so that multi-line statements are aligned with the first line, but there is no visible secondary prompt. PROMPT1の直近の出力と同じ幅の空白です。 これは、複数行の文が最初の行とそろっているが第2のプロンプトが見えないようにするためにPROMPT2の設定として使えます。

To insert a percent sign into your prompt, write <literal>%%</literal>. The default prompts are <literal>'%/%R%x%# '</literal> for prompts 1 and 2, and <literal>'&gt;&gt; '</literal> for prompt 3. プロンプトにパーセント記号を入れる場合は、%%と記述してください。 デフォルトのプロンプトは、プロンプト1と2が'%/%R%x%# '、プロンプト3が'>> 'です。

注記

This feature was shamelessly plagiarized from <application>tcsh</application>. この機能はtcshの機能を真似たものです。

コマンドライン編集

<title>Command-Line Editing</title>

<application>psql</application> uses the <application>Readline</application> or <application>libedit</application> library, if available, for convenient line editing and retrieval. The command history is automatically saved when <application>psql</application> exits and is reloaded when <application>psql</application> starts up. Type up-arrow or control-P to retrieve previous lines. psqlReadlineまたはlibeditライブラリがあれば、それを使って行の編集と検索を行ないます。 コマンド履歴はpsqlの終了時に自動的に保存され、psqlの起動時に再読み込みされます。 前の行を取得するには、上矢印またはcontrol-Pと入力します。

You can also use tab completion to fill in partially-typed keywords and SQL object names in many (by no means all) contexts. For example, at the start of a command, typing <literal>ins</literal> and pressing TAB will fill in <literal>insert into </literal>. Then, typing a few characters of a table or schema name and pressing <literal>TAB</literal> will fill in the unfinished name, or offer a menu of possible completions when there's more than one. (Depending on the library in use, you may need to press <literal>TAB</literal> more than once to get a menu.) タブ補完を使用して、多くの(すべてではない)コンテキストで部分的に入力されたキーワードやSQLオブジェクト名を入力することもできます。 たとえば、コマンドの開始時にinsと入力してTABキーを押すとinsert into が入力されます。 次に、テーブル名またはスキーマ名の数文字を入力してTABキーを押すと、入力されていない名前が入力されたり、複数の補完候補がある場合に補完候補のメニューが表示されます。 (使用しているライブラリによっては、メニューを表示するにはTABキーを複数回押す必要があります。)

Tab completion for SQL object names requires sending queries to the server to find possible matches. In some contexts this can interfere with other operations. For example, after <command>BEGIN</command> it will be too late to issue <command>SET TRANSACTION ISOLATION LEVEL</command> if a tab-completion query is issued in between. If you do not want tab completion at all, you can turn it off permanently by putting this in a file named <filename>.inputrc</filename> in your home directory: SQLオブジェクト名のタブ補完は、マッチする可能性のあるものを見つけるためサーバへの問い合わせの送信が必要です。 コンテクストによっては、これが他の操作と干渉することもあります。 たとえば、BEGINの後、タブ補完の問い合わせがその間に発行されれば、SET TRANSACTION ISOLATION LEVELを発行するには遅いでしょう。 タブ補完を何らかの事情により使用したくなければ、ホームディレクトリ内の.inputrcというファイルに以下のように書き込むことで無効にできます。

$if psql
set disable-completion on
$endif

(This is not a <application>psql</application> but a <application>Readline</application> feature. Read its documentation for further details.) (これはpsqlの機能ではなく、Readlineの機能です。 詳細についてはReadlineのドキュメントを参照してください。)

The <option>-n</option> (<option>&#45;-no-readline</option>) command line option can also be useful to disable use of <application>Readline</application> for a single run of <application>psql</application>. This prevents tab completion, use or recording of command line history, and editing of multi-line commands. It is particularly useful when you need to copy-and-paste text that contains <literal>TAB</literal> characters. -n(--no-readline)コマンドラインオプションは、Readlineの使用を、psqlのその回の実行に限って無効にする場合にも便利です。 これにより、タブ補完、コマンドライン履歴の使用または記録、複数行コマンドの編集が防止されます。 TAB文字を含むテキストをコピーして貼り付ける必要がある場合に特に便利です。

<refsect1 id="app-psql-environment" xreflabel="Environment">

環境

<title>Environment</title>
COLUMNS #

If <literal>\pset columns</literal> is zero, controls the width for the <literal>wrapped</literal> format and width for determining if wide output requires the pager or should be switched to the vertical format in expanded auto mode. \pset columnsがゼロの場合、wrapped書式の幅、および、幅の広い出力がページャを必要とするかどうかを決める幅を制御します。 また自動拡張モードでは縦書式に切り替えるべきかどうかを制御します。

PGDATABASE
PGHOST
PGPORT
PGUSER #

Default connection parameters (see <xref linkend="libpq-envars"/>). デフォルトの接続パラメータです(34.15を参照)。

PG_COLOR #

Specifies whether to use color in diagnostic messages. Possible values are <literal>always</literal>, <literal>auto</literal> and <literal>never</literal>. 診断メッセージで色を使うかどうかを指定します。 可能な値はalwaysautoneverです。

PSQL_EDITOR
EDITOR
VISUAL #

Editor used by the <command>\e</command>, <command>\ef</command>, and <command>\ev</command> commands. These variables are examined in the order listed; the first that is set is used. If none of them is set, the default is to use <filename>vi</filename> on Unix systems or <filename>notepad.exe</filename> on Windows systems. \eコマンド、\efコマンド、\evコマンドで使用されるエディタです。 変数はこの順に検索され、設定された最初のものが使用されます。 いずれも設定されていない場合、デフォルトでUnixシステムではviを、Windowsシステムではnotepad.exeを使用します。

PSQL_EDITOR_LINENUMBER_ARG #

When <command>\e</command>, <command>\ef</command>, or <command>\ev</command> is used with a line number argument, this variable specifies the command-line argument used to pass the starting line number to the user's editor. For editors such as <productname>Emacs</productname> or <productname>vi</productname>, this is a plus sign. Include a trailing space in the value of the variable if there needs to be space between the option name and the line number. Examples: \e\efまたは\evが行番号引数を付けて使用された場合、この変数は、ユーザのエディタに開始行番号を渡すために使用されるコマンドライン引数を指定します。 Emacsまたはviのようなエディタでは、これはプラス(+)記号です。 オプション名と行番号の間に空白文字が必要な場合は、変数の値の最後に空白文字を含めてください。 以下に例を示します。

PSQL_EDITOR_LINENUMBER_ARG='+'
PSQL_EDITOR_LINENUMBER_ARG='--line '

The default is <literal>+</literal> on Unix systems (corresponding to the default editor <filename>vi</filename>, and useful for many other common editors); but there is no default on Windows systems. Unixシステム上のデフォルトは+です。 (デフォルトのエディタviに対応するものですが、他のよく使われる多くのエディタでも役に立ちます。) 一方Windowsシステムではデフォルトはありません。

PSQL_HISTORY #

Alternative location for the command history file. Tilde (<literal>~</literal>) expansion is performed. コマンド履歴ファイルの場所を指定します。 チルダ(~)展開が行われます。

PSQL_PAGER
PAGER #

If a query's results do not fit on the screen, they are piped through this command. Typical values are <literal>more</literal> or <literal>less</literal>. Use of the pager can be disabled by setting <envar>PSQL_PAGER</envar> or <envar>PAGER</envar> to an empty string, or by adjusting the pager-related options of the <command>\pset</command> command. These variables are examined in the order listed; the first that is set is used. If neither of them is set, the default is to use <literal>more</literal> on most platforms, but <literal>less</literal> on Cygwin. 問い合わせ結果が画面に入り切らない場合、このコマンドによって結果をパイプします。 一般的に指定される値は、more、またはlessです。 ページャの使用を無効にするにはPSQL_PAGERPAGERを空文字列にするか、\psetコマンドのページャ関連のオプションを調整します。 これらの変数は列挙した順で検査され、最初の設定されているものが使われます。 いずれも設定されていない場合、デフォルトで大部分のプラットフォームではmoreが使われ、しかし、Cygwinではlessが使われます。

PSQL_WATCH_PAGER #

When a query is executed repeatedly with the <command>\watch</command> command, a pager is not used by default. This behavior can be changed by setting <envar>PSQL_WATCH_PAGER</envar> to a pager command, on Unix systems. The <literal>pspg</literal> pager (not part of <productname>PostgreSQL</productname> but available in many open source software distributions) can display the output of <command>\watch</command> if started with the option <literal>&#45;-stream</literal>. \watchコマンドを使用して問い合わせを繰り返し実行する場合、デフォルトではページャは使用されません。 この動作は、UnixシステムではPSQL_WATCH_PAGERをページャコマンドに設定することで変更できます。 pspgページャ(PostgreSQLの一部ではありませんが、多くのオープンソースソフトウェアディストリビューションで利用可能です)は、オプション--streamで起動すると、\watchの出力を表示できます。

PSQLRC #

Alternative location of the user's <filename>.psqlrc</filename> file. Tilde (<literal>~</literal>) expansion is performed. ユーザの.psqlrcファイルの場所を指定します。 チルダ(~)展開が行われます。

SHELL #

Command executed by the <command>\!</command> command. \!コマンドが実行するコマンドです。

TMPDIR #

Directory for storing temporary files. The default is <filename>/tmp</filename>. 一時ファイルを格納するディレクトリです。 デフォルトは/tmpです。

This utility, like most other <productname>PostgreSQL</productname> utilities, also uses the environment variables supported by <application>libpq</application> (see <xref linkend="libpq-envars"/>). このユーティリティは、他のほとんどのPostgreSQLユーティリティと同様、libpqでサポートされる環境変数を使用します(34.15を参照してください)。

ファイル

<title>Files</title>
psqlrc and ~/.psqlrc #

Unless it is passed an <option>-X</option> option, <application>psql</application> attempts to read and execute commands from the system-wide startup file (<filename>psqlrc</filename>) and then the user's personal startup file (<filename>~/.psqlrc</filename>), after connecting to the database but before accepting normal commands. These files can be used to set up the client and/or the server to taste, typically with <command>\set</command> and <command>SET</command> commands. -Xオプションが渡されない場合、psqlは、データベースに接続した後、通常のコマンドを受け付け始める前に、システム全体用の開始ファイル(psqlrc)のコマンドを、続いてユーザ用の開始ファイル(~/.psqlrc)のコマンドを読み込み、実行しようとします。 これらのファイルは、\setSETコマンドを使用して、好みに応じたクライアントやサーバを設定するために使用することができます。

The system-wide startup file is named <filename>psqlrc</filename>. By default it is sought in the installation's <quote>system configuration</quote> directory, which is most reliably identified by running <literal>pg_config &#45;-sysconfdir</literal>. Typically this directory will be <filename>../etc/</filename> relative to the directory containing the <productname>PostgreSQL</productname> executables. The directory to look in can be set explicitly via the <envar>PGSYSCONFDIR</envar> environment variable. システム全体の開始ファイルはpsqlrcという名前です。 デフォルトでは、インストレーションのシステム設定ディレクトリの中で探されます。このディレクトリを特定するにはpg_config --sysconfdirを実行するのが最も確実です。 通常は、PostgreSQLの実行ファイルを含むディレクトリからの相対パスで../etc/になります。 調べるディレクトリは、環境変数PGSYSCONFDIRを使って明示的に設定できます。

The user's personal startup file is named <filename>.psqlrc</filename> and is sought in the invoking user's home directory. On Windows the personal startup file is instead named <filename>%APPDATA%\postgresql\psqlrc.conf</filename>. In either case, this default file path can be overridden by setting the <envar>PSQLRC</envar> environment variable. ユーザの個人用の開始ファイルは.psqlrcという名前で、実行しているユーザのホームディレクトリの中で探されます。 Windowsでは、個人用の開始ファイルは、その代わりに%APPDATA%\postgresql\psqlrc.confという名前になります。 どちらの場合でも、デフォルトのファイルパスは環境変数PSQLRCを設定することで上書きできます。

Both the system-wide startup file and the user's personal startup file can be made <application>psql</application>-version-specific by appending a dash and the <productname>PostgreSQL</productname> major or minor release identifier to the file name, for example <filename>~/.psqlrc-&majorversion;</filename> or <filename>~/.psqlrc-&version;</filename>. The most specific version-matching file will be read in preference to a non-version-specific file. These version suffixes are added after determining the file path as explained above. システム全体用の開始ファイルとユーザの個人用の開始ファイルに、たとえば~/.psqlrc-16~/.psqlrc-16.0のように、ダッシュ記号とPostgreSQLのメジャーリリース番号またはマイナーリリース番号をファイル名に付加することで、特定バージョンのpsql向けのファイルとすることができます。 マッチするバージョンのファイルはバージョン指定のないファイルよりも優先して読み込まれます。 このバージョンの接尾辞は上で説明したファイルパスの決定の後に追加されます。

.psql_history #

The command-line history is stored in the file <filename>~/.psql_history</filename>, or <filename>%APPDATA%\postgresql\psql_history</filename> on Windows. コマンドライン履歴はファイル~/.psql_history、Windowsの場合は%APPDATA%\postgresql\psql_historyに格納されます。

The location of the history file can be set explicitly via the <varname>HISTFILE</varname> <application>psql</application> variable or the <envar>PSQL_HISTORY</envar> environment variable. 履歴ファイルの場所はpsql変数のHISTFILEまたは環境変数PSQL_HISTORYを介して明示的に設定することができます。

注釈

<title>Notes</title>
  • <para><application>psql</application> works best with servers of the same or an older major version. Backslash commands are particularly likely to fail if the server is of a newer version than <application>psql</application> itself. However, backslash commands of the <literal>\d</literal> family should work with servers of versions back to 9.2, though not necessarily with servers newer than <application>psql</application> itself. The general functionality of running SQL commands and displaying query results should also work with servers of a newer major version, but this cannot be guaranteed in all cases.

    psqlは、同じまたはより古いメジャーバージョンのサーバと稼働させることが最善です。 特にバックスラッシュコマンドは、サーバがpsql自身のバージョンより新しいと失敗しやすくなります。 \d系列のバックスラッシュコマンドは9.2までさかのぼるバージョンのサーバで動作するはずですが、psql自身よりもサーバが新しい場合は、必ずしもそうではありません。 SQLコマンドの実行ならびに問い合わせ結果の表示といった一般的な機能はより新しいメジャーバージョンのサーバとでも動作するはずですが、すべての場合において保証することはできません。

    If you want to use <application>psql</application> to connect to several servers of different major versions, it is recommended that you use the newest version of <application>psql</application>. Alternatively, you can keep around a copy of <application>psql</application> from each major version and be sure to use the version that matches the respective server. But in practice, this additional complication should not be necessary. メジャーバージョンが異なる複数のサーバとの接続のためにpsqlを使用したいのであれば、psqlの最新版を使用することを勧めます。 他の方法として、各メジャーバージョンのpsqlのコピーを保持し、確実にそれぞれのサーバに対応するバージョンを使用することができます。 しかし実際には、この複雑さを追加することは必要ではないはずです。

  • Before <productname>PostgreSQL</productname> 9.6, the <option>-c</option> option implied <option>-X</option> (<option>&#45;-no-psqlrc</option>); this is no longer the case. PostgreSQLの9.6より前では、-cオプションが-X (--no-psqlrc)を暗示しましたが、現在ではそうなっていません。

  • Before <productname>PostgreSQL</productname> 8.4, <application>psql</application> allowed the first argument of a single-letter backslash command to start directly after the command, without intervening whitespace. Now, some whitespace is required. PostgreSQLの8.4より前では、psqlで1文字のバックスラッシュコマンドの最初の引数をコマンドの直後に空白文字を挟むことなく記述できました。 現在では何らかの空白が必要になっています。

Windowsユーザ向けの注意

<title>Notes for Windows Users</title>

<application>psql</application> is built as a <quote>console application</quote>. Since the Windows console windows use a different encoding than the rest of the system, you must take special care when using 8-bit characters within <application>psql</application>. If <application>psql</application> detects a problematic console code page, it will warn you at startup. To change the console code page, two things are necessary: psqlコンソールアプリケーションとしてコンパイルされます。 Windowsのコンソールウィンドウは、システムの他の部分とは異なる符号化方式を使用しているので、psqlで8ビット文字を使用する時には特別な配慮が必要です。 psqlは、コンソール用コードページとして問題があることを検出すると、起動時に警告を発します。 コンソール用コードページを変更するためには、以下の2つが必要です。

  • Set the code page by entering <userinput>cmd.exe /c chcp 1252</userinput>. (1252 is a code page that is appropriate for German; replace it with your value.) If you are using Cygwin, you can put this command in <filename>/etc/profile</filename>. cmd.exe /c chcp 1252と入力して、コードページを設定します (1252はドイツ圏における適切なコードページです。システムに合わせて変更してください)。 Cygwinを使用しているのであれば、このコマンドを/etc/profileに追加してください。

  • Set the console font to <literal>Lucida Console</literal>, because the raster font does not work with the ANSI code page. コンソール用フォントをLucida Consoleに設定してください。 ラスタフォントは、ANSIコードページでは正しく動作しないためです。

<refsect1 id="app-psql-examples" xreflabel="Examples">

<title>Examples</title>

The first example shows how to spread a command over several lines of input. Notice the changing prompt: 最初に、複数行にわたるコマンドの入力例を示します。 プロンプトの変化に注意してください。

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

Now look at the table definition again: さて、ここでテーブル定義を再度確認してみます。

testdb=> \d my_table
              Table "public.my_table"
 Column |  Type   | Collation | Nullable | Default
--------+---------+-----------+----------+---------
 first  | integer |           | not null | 0
 second | text    |           |          |

Now we change the prompt to something more interesting: 次に、プロンプトをもっと面白いものに変更してみます。

testdb=> \set PROMPT1 '%n@%m %~%R%# '
peter@localhost testdb=>

Let's assume you have filled the table with data and want to take a look at it: テーブルにデータを入力したものと考えてください。データを見る場合は次のようにします。

peter@localhost testdb=> SELECT * FROM my_table;
 first | second
-------+--------
     1 | one
     2 | two
     3 | three
     4 | four
(4 rows)

You can display tables in different ways by using the <command>\pset</command> command: \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 csv
Output format is csv.
peter@localhost testdb=> \pset tuples_only
Tuples only is on.
peter@localhost testdb=> SELECT second, first FROM my_table;
one,1
two,2
three,3
four,4
peter@localhost testdb=> \pset format unaligned
Output format is unaligned.
peter@localhost testdb=> \pset fieldsep '\t'
Field separator is "    ".
peter@localhost testdb=> SELECT second, first FROM my_table;
one     1
two     2
three   3
four    4

Alternatively, use the short commands: その他の方法として、短縮されたコマンドを使用してみます。

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

Also, these output format options can be set for just one query by using <literal>\g</literal>: また、この出力書式オプションは\gを使って1つの問い合わせにだけ設定できます。

peter@localhost testdb=> SELECT * FROM my_table
peter@localhost testdb-> \g (format=aligned tuples_only=off expanded=on)
-[ RECORD 1 ]-
first  | 1
second | one
-[ RECORD 2 ]-
first  | 2
second | two
-[ RECORD 3 ]-
first  | 3
second | three
-[ RECORD 4 ]-
first  | 4
second | four

Here is an example of using the <command>\df</command> command to find only functions with names matching <literal>int*pl</literal> and whose second argument is of type <type>bigint</type>: これは、\dfコマンドを使って、名前がint*plにマッチし、2番目の引数の型がbigintである関数のみを見つける例です。

testdb=> \df int*pl * bigint
                          List of functions
   Schema   |  Name   | Result data type | Argument data types | Type
------------+---------+------------------+---------------------+------
 pg_catalog | int28pl | bigint           | smallint, bigint    | func
 pg_catalog | int48pl | bigint           | integer, bigint     | func
 pg_catalog | int8pl  | bigint           | bigint, bigint      | func
(3 rows)

When suitable, query results can be shown in a crosstab representation with the <command>\crosstabview</command> command: 問い合わせの結果が適していれば、以下のように\crosstabviewコマンドを使用してクロス表形式で表示することができます。

testdb=> SELECT first, second, first > 2 AS gt2 FROM my_table;
 first | second | gt2
-------+--------+-----
     1 | one    | f
     2 | two    | f
     3 | three  | t
     4 | four   | t
(4 rows)

testdb=> \crosstabview first second
 first | one | two | three | four
-------+-----+-----+-------+------
     1 | f   |     |       |
     2 |     | f   |       |
     3 |     |     | t     |
     4 |     |     |       | t
(4 rows)

This second example shows a multiplication table with rows sorted in reverse numerical order and columns with an independent, ascending numerical order. この2つ目の例では、掛け算の表を、行は逆順にソートし、列はそれとは別に昇順に示しています。

testdb=> SELECT t1.first as "A", t2.first+100 AS "B", t1.first*(t2.first+100) as "AxB",
testdb(> row_number() over(order by t2.first) AS ord
testdb(> FROM my_table t1 CROSS JOIN my_table t2 ORDER BY 1 DESC
testdb(> \crosstabview "A" "B" "AxB" ord
 A | 101 | 102 | 103 | 104
---+-----+-----+-----+-----
 4 | 404 | 408 | 412 | 416
 3 | 303 | 306 | 309 | 312
 2 | 202 | 204 | 206 | 208
 1 | 101 | 102 | 103 | 104
(4 rows)