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

9.26. システム情報関数と演算子 #

<title>System Information Functions and Operators</title>

The functions described in this section are used to obtain various information about a <productname>PostgreSQL</productname> installation. 本節で説明する関数は、PostgreSQLのインストレーションに関するさまざまな情報を取得するために使用されます。

9.26.1. セッション情報関数 #

<title>Session Information Functions</title>

<xref linkend="functions-info-session-table"/> shows several functions that extract session and system information. 表 9.67に、セッションおよびシステムの情報を抽出する関数を示します。

In addition to the functions listed in this section, there are a number of functions related to the statistics system that also provide system information. See <xref linkend="monitoring-stats-views"/> for more information. 本節で列挙されている関数のほかに、同様にシステム情報を提供する統計システムに関連した数多くの関数があります。 28.2.2にさらに情報があります。

表9.67 セッション情報関数

<title>Session Information Functions</title>

Function 関数

Description 説明

current_catalogname

current_database () → name

Returns the name of the current database. (Databases are called <quote>catalogs</quote> in the SQL standard, so <function>current_catalog</function> is the standard's spelling.) 現在のデータベースの名前を返します。 (データベースはSQL標準ではカタログと呼ばれています。ですから標準での記述はcurrent_catalogとなります。)

current_query () → text

Returns the text of the currently executing query, as submitted by the client (which might contain more than one statement). クライアントから送信された現在実行中問い合わせのテキスト(複数の文を含むことあります)を返します。

current_rolename

This is equivalent to <function>current_user</function>. current_userと同じです。

current_schemaname

current_schema () → name

Returns the name of the schema that is first in the search path (or a null value if the search path is empty). This is the schema that will be used for any tables or other named objects that are created without specifying a target schema. サーチパスの先頭にあるスキーマの名前を返します。(サーチパスが空ならNULL値を返します。) これはターゲットスキーマを指定せずに作成されるすべてのテーブルあるいは名前付きのオブジェクトで使われるスキーマです。

current_schemas ( include_implicit boolean ) → name[]

Returns an array of the names of all schemas presently in the effective search path, in their priority order. (Items in the current <xref linkend="guc-search-path"/> setting that do not correspond to existing, searchable schemas are omitted.) If the Boolean argument is <literal>true</literal>, then implicitly-searched system schemas such as <literal>pg_catalog</literal> are included in the result. 現在有効な検索パス中にあるすべてのスキーマの名前を優先順に配列で返します。 (現在のsearch_path設定にある項目で、存在する検索可能なスキーマに関連しないものは無視されます。) 論理値引数がならpg_catalogのような暗黙的に検索されるシステムスキーマは結果に含まれます。

current_username

Returns the user name of the current execution context. 現在の実行コンテキストのユーザ名を返します。

inet_client_addr () → inet

Returns the IP address of the current client, or <literal>NULL</literal> if the current connection is via a Unix-domain socket. 現在のクライアントのIPアドレスを返します。UNIXドメインソケット経由の接続ならNULLが返ります。

inet_client_port () → integer

Returns the IP port number of the current client, or <literal>NULL</literal> if the current connection is via a Unix-domain socket. 現在のクライアントのIPポート番号を返します。UNIXドメインソケット経由の接続ならNULLが返ります。

inet_server_addr () → inet

Returns the IP address on which the server accepted the current connection, or <literal>NULL</literal> if the current connection is via a Unix-domain socket. サーバが受け付けている現在の接続のIPアドレスを返します。UNIXドメインソケット経由の接続ならNULLが返ります。

inet_server_port () → integer

Returns the IP port number on which the server accepted the current connection, or <literal>NULL</literal> if the current connection is via a Unix-domain socket. サーバが受け付けている現在の接続のIPポート番号を返します。UNIXドメインソケット経由の接続ならNULLが返ります。

pg_backend_pid () → integer

Returns the process ID of the server process attached to the current session. 現在のセッションに結びついているサーバプロセスのプロセスIDを返します。

pg_blocking_pids ( integer ) → integer[]

Returns an array of the process ID(s) of the sessions that are blocking the server process with the specified process ID from acquiring a lock, or an empty array if there is no such server process or it is not blocked. 指定したサーバプロセスIDによるロック取得をブロックしているプロセスIDを配列で返します。そのようなサーバプロセスが存在しないかあるいはブロックしていない場合は空の配列が返ります。

One server process blocks another if it either holds a lock that conflicts with the blocked process's lock request (hard block), or is waiting for a lock that would conflict with the blocked process's lock request and is ahead of it in the wait queue (soft block). When using parallel queries the result always lists client-visible process IDs (that is, <function>pg_backend_pid</function> results) even if the actual lock is held or awaited by a child worker process. As a result of that, there may be duplicated PIDs in the result. Also note that when a prepared transaction holds a conflicting lock, it will be represented by a zero process ID. あるサーバプロセスが別のサーバプロセスをブロックするのは、ブロックされるプロセスのロック要求と競合するロックを保持している場合(ハードブロック)、あるいは、ブロックされるプロセスのロック要求と競合するロックを待っていて、かつロック待ちキュー内でより前方にいる場合(ソフトブロック)です。 パラレルクエリを使っている場合、実際のロックを子ワーカープロセスが保持または待っている場合であっても、この結果には必ずクライアントから可視のプロセスID(つまり、pg_backend_pidの結果)が示されます。 そのような仕様なので、この結果には重複するPIDが含まれることもあります。 また、プリペアドのトランザクションが競合するロックを保持している場合、この関数の結果ではプロセスIDがゼロとして示されることにも注意して下さい。

Frequent calls to this function could have some impact on database performance, because it needs exclusive access to the lock manager's shared state for a short time. 頻繁にこの関数を呼び出すとデータベースの性能に影響があるかも知れません。ロックマネージャの共有状態への短期的な排他ロックの取得が必要だからです。

pg_conf_load_time () → timestamp with time zone

Returns the time when the server configuration files were last loaded. If the current session was alive at the time, this will be the time when the session itself re-read the configuration files (so the reading will vary a little in different sessions). Otherwise it is the time when the postmaster process re-read the configuration files. サーバ設定ファイルが最後に読み込まれた時の時刻を返します。 現在のセッションがそのときに活動中だった場合、これはそのセッション自身が設定ファイルを再読み込みした時刻になります。(ですからその結果はセッションによって少し異なるかもしれません。) それ以外の場合は、postmasterプロセスが設定ファイルを再読み込みした時刻になります。

pg_current_logfile ( [ text ] ) → text

Returns the path name of the log file currently in use by the logging collector. The path includes the <xref linkend="guc-log-directory"/> directory and the individual log file name. The result is <literal>NULL</literal> if the logging collector is disabled. When multiple log files exist, each in a different format, <function>pg_current_logfile</function> without an argument returns the path of the file having the first format found in the ordered list: <literal>stderr</literal>, <literal>csvlog</literal>, <literal>jsonlog</literal>. <literal>NULL</literal> is returned if no log file has any of these formats. To request information about a specific log file format, supply either <literal>csvlog</literal>, <literal>jsonlog</literal> or <literal>stderr</literal> as the value of the optional parameter. The result is <literal>NULL</literal> if the log format requested is not configured in <xref linkend="guc-log-destination"/>. The result reflects the contents of the <filename>current_logfiles</filename> file. ログ収集機構が現在使用しているログファイルのパス名を返します。 パスにはlog_directoryディレクトリとログファイルの名前が含まれます。 ログ収集が無効ならば戻り値はNULLになります。 複数のログファイルがそれぞれ異なる形式で存在する場合、引数なしのpg_current_logfileは、順序リスト(stderrcsvlogjsonlog)の最初に出てくる形式のファイルのパスを返します。 これらの形式のログファイルがないときはNULLが返されます。 特定のファイル形式を要求するには、オプションパラメータの値としてcsvlogjsonlog、またはstderrをオプション引数の値として渡してください。 指定のログ形式がlog_destinationで設定されていない場合は、戻り値がNULLとなります。 結果はcurrent_logfilesファイルの内容を反映します。

pg_my_temp_schema () → oid

Returns the OID of the current session's temporary schema, or zero if it has none (because it has not created any temporary tables). 現在のセッションの一時スキーマのOIDを返します。(一時テーブルをまだ1つも作成しておらず)存在しなければゼロを返します。

pg_is_other_temp_schema ( oid ) → boolean

Returns true if the given OID is the OID of another session's temporary schema. (This can be useful, for example, to exclude other sessions' temporary tables from a catalog display.) 指定したOIDが他のセッションの一時スキーマのOIDであれば、真を返します。 (例えば、他のセッションの一時テーブルをカタログ表示から除外したい場合などで有用です。)

pg_jit_available () → boolean

Returns true if a <acronym>JIT</acronym> compiler extension is available (see <xref linkend="jit"/>) and the <xref linkend="guc-jit"/> configuration parameter is set to <literal>on</literal>. JITコンパイラ拡張が利用可能で(第32章参照)、jit設定パラメータがonなら真を返します。

pg_listening_channels () → setof text

Returns the set of names of asynchronous notification channels that the current session is listening to. 今のセッションにおいて現在待ち受け中の非同期通知チャンネル名の集合を返します。

pg_notification_queue_usage () → double precision

Returns the fraction (0&ndash;1) of the asynchronous notification queue's maximum size that is currently occupied by notifications that are waiting to be processed. See <xref linkend="sql-listen"/> and <xref linkend="sql-notify"/> for more information. 非同期通知キューの最大サイズのうち、処理待ちの通知によって占められている現在の割合(0から1まで)を返します。 詳細はLISTENNOTIFYをご覧ください。

pg_postmaster_start_time () → timestamp with time zone

Returns the time when the server started. サーバの起動時刻を返します。

pg_safe_snapshot_blocking_pids ( integer ) → integer[]

Returns an array of the process ID(s) of the sessions that are blocking the server process with the specified process ID from acquiring a safe snapshot, or an empty array if there is no such server process or it is not blocked. 指定のサーバプロセスIDによる安全なスナップショットの取得をブロックしているセッションのサーバプロセスIDの配列を返します。そのようなサーバプロセスがないか、ブロックされていない場合は空の配列が返ります。

A session running a <literal>SERIALIZABLE</literal> transaction blocks a <literal>SERIALIZABLE READ ONLY DEFERRABLE</literal> transaction from acquiring a snapshot until the latter determines that it is safe to avoid taking any predicate locks. See <xref linkend="xact-serializable"/> for more information about serializable and deferrable transactions. SERIALIZABLEトランザクションを実行しているセッションは、SERIALIZABLE READ ONLY DEFERRABLEトランザクションが述語ロックの取得をすべて回避しても安全であると決定するまで、後者がスナップショットを取得するのをブロックします。 シリアライザブルトランザクションおよび遅延可能トランザクションについてのさらなる情報については13.2.3を参照してください。

Frequent calls to this function could have some impact on database performance, because it needs access to the predicate lock manager's shared state for a short time. この関数を頻繁に呼び出すと、短時間に述語ロックマネージャの共有状態にアクセスする必要があるため、データベースのパフォーマンスに若干の影響が出るかもしれません。

pg_trigger_depth () → integer

Returns the current nesting level of <productname>PostgreSQL</productname> triggers (0 if not called, directly or indirectly, from inside a trigger). PostgreSQLのトリガの現在の入れ子の深さを返します。(直接的であれ間接的であれ、トリガ内部から呼ばれていなければ0を返します)。

session_username

Returns the session user's name. セッションのユーザ名を返します。

system_usertext

Returns the authentication method and the identity (if any) that the user presented during the authentication cycle before they were assigned a database role. It is represented as <literal>auth_method:identity</literal> or <literal>NULL</literal> if the user has not been authenticated (for example if <link linkend="auth-trust">Trust authentication</link> has been used). 認証方式と、データベースロールが割り当てられる前にユーザが認証サイクル中に提示したID(存在する場合)を戻します。 ユーザが認証されている場合はauth_method:identityとして表示します。ユーザが認証されていない場合(たとえばTrust認証が使用されている場合)はNULLとして表示します。

username

This is equivalent to <function>current_user</function>. current_userと等価です。

version () → text

Returns a string describing the <productname>PostgreSQL</productname> server's version. You can also get this information from <xref linkend="guc-server-version"/>, or for a machine-readable version use <xref linkend="guc-server-version-num"/>. Software developers should use <varname>server_version_num</varname> (available since 8.2) or <xref linkend="libpq-PQserverVersion"/> instead of parsing the text version. PostgreSQLサーバのバージョンを説明する文字列を返します。 情報はserver_versionからも得られます。 機械読み取り可能なバージョンはserver_version_numを使ってください。 ソフトウェア開発者は文字列バージョンを解析するのではなく、server_version_num (8.2以降で利用可能)かPQserverVersionを使うべきです。


注記

<function>current_catalog</function>, <function>current_role</function>, <function>current_schema</function>, <function>current_user</function>, <function>session_user</function>, and <function>user</function> have special syntactic status in <acronym>SQL</acronym>: they must be called without trailing parentheses. In PostgreSQL, parentheses can optionally be used with <function>current_schema</function>, but not with the others. current_catalogcurrent_rolecurrent_schemacurrent_usersession_userおよびuserSQLにおいて特殊な構文上の地位を持っており、最後に括弧を付けずに呼び出さなければなりません。 PostgreSQLではcurrent_schemaの場合括弧を使用することができますが、他は使えません。

The <function>session_user</function> is normally the user who initiated the current database connection; but superusers can change this setting with <xref linkend="sql-set-session-authorization"/>. The <function>current_user</function> is the user identifier that is applicable for permission checking. Normally it is equal to the session user, but it can be changed with <xref linkend="sql-set-role"/>. It also changes during the execution of functions with the attribute <literal>SECURITY DEFINER</literal>. In Unix parlance, the session user is the <quote>real user</quote> and the current user is the <quote>effective user</quote>. <function>current_role</function> and <function>user</function> are synonyms for <function>current_user</function>. (The SQL standard draws a distinction between <function>current_role</function> and <function>current_user</function>, but <productname>PostgreSQL</productname> does not, since it unifies users and roles into a single kind of entity.) session_userは、通常、現在のデータベース接続を開始したユーザです。しかし、スーパーユーザはこの設定をSET SESSION AUTHORIZATIONを使用して変更することができます。 current_userは、権限の検査に適用されるユーザ識別子です。 通常はセッションユーザと同じですが、SET ROLEを使用して変更可能です。 SECURITY DEFINER属性を持つ関数の実行中にも変わります。 Unix用語で言うと、セッションユーザは実ユーザで、現在のユーザは実効ユーザです。 current_roleusercurrent_userの同義語です。 (標準SQLではcurrent_rolecurrent_userを区別していますが、PostgreSQLではユーザとロールを1種類のエンティティに統合しているため、両者に区別はありません。)

9.26.2. アクセス権限照会関数 #

<title>Access Privilege Inquiry Functions</title>

<xref linkend="functions-info-access-table"/> lists functions that allow querying object access privileges programmatically. (See <xref linkend="ddl-priv"/> for more information about privileges.) In these functions, the user whose privileges are being inquired about can be specified by name or by OID (<structname>pg_authid</structname>.<structfield>oid</structfield>), or if the name is given as <literal>public</literal> then the privileges of the PUBLIC pseudo-role are checked. Also, the <parameter>user</parameter> argument can be omitted entirely, in which case the <function>current_user</function> is assumed. The object that is being inquired about can be specified either by name or by OID, too. When specifying by name, a schema name can be included if relevant. The access privilege of interest is specified by a text string, which must evaluate to one of the appropriate privilege keywords for the object's type (e.g., <literal>SELECT</literal>). Optionally, <literal>WITH GRANT OPTION</literal> can be added to a privilege type to test whether the privilege is held with grant option. Also, multiple privilege types can be listed separated by commas, in which case the result will be true if any of the listed privileges is held. (Case of the privilege string is not significant, and extra whitespace is allowed between but not within privilege names.) Some examples: 表 9.68に列挙した関数を使用して、ユーザはオブジェクトのアクセス権限をプログラムから問い合わせることができます。 権限についての詳細は、5.7を参照してください。 これらの関数では権限を検査されるユーザは名前かOID(pg_authid.oid)で指定できます。 名前がpublicとして与えられるとPUBLIC仮想ロールの権限が検査されます。 また、user引数を完全に省略できます。この場合はcurrent_userを指定したと見なされます。 検査されるオブジェクトも名前かOIDで指定できます。 名前で指定する時は関連するスキーマ名を含んでも構いません。 対象となるアクセス権限はテキスト文字列で指定します。その文字列はオブジェクト型(たとえばSELECT)へと評価されなければならない適切なアクセスキーワードで指定します。 その権限が許可オプションで保持されるかどうかをテストするためにオプションでWITH GRANT OPTIONを権限型に追加できます。 また、複数の権限型をカンマで区切って列挙できます。この場合はどれかの権限が保持されていれば結果は真となります。 (権限文字列は大文字小文字の区別がなく、追加の空白を権限文字列の間に入れることができますが、権限名の中に入れることはできません。)

SELECT has_table_privilege('myschema.mytable', 'select');
SELECT has_table_privilege('joe', 'mytable', 'INSERT, SELECT WITH GRANT OPTION');

表9.68 アクセス権限照会関数

<title>Access Privilege Inquiry Functions</title>

Function 関数

Description 説明

has_any_column_privilege ( [ user name or oid, ] table text or oid, privilege text ) → boolean

Does user have privilege for any column of table? This succeeds either if the privilege is held for the whole table, or if there is a column-level grant of the privilege for at least one column. Allowable privilege types are <literal>SELECT</literal>, <literal>INSERT</literal>, <literal>UPDATE</literal>, and <literal>REFERENCES</literal>. ユーザがテーブルのどれか1つの列に対して権限を所有しているか? テーブル全体あるいは列レベルの権限が少なくとも1つの列に与えられていれば成功します。 可能な権限型はSELECTINSERTUPDATEREFERENCESです。

has_column_privilege ( [ user name or oid, ] table text or oid, column text or smallint, privilege text ) → boolean

Does user have privilege for the specified table column? This succeeds either if the privilege is held for the whole table, or if there is a column-level grant of the privilege for the column. The column can be specified by name or by attribute number (<structname>pg_attribute</structname>.<structfield>attnum</structfield>). Allowable privilege types are <literal>SELECT</literal>, <literal>INSERT</literal>, <literal>UPDATE</literal>, and <literal>REFERENCES</literal>. ユーザがテーブルの指定された(1つの)列に対して権限を所有しているか? テーブル全体あるいはその列に対して列レベルの権限が与えられていれば成功します。 名前かアトリビュート番号(pg_attribute.attnum)で列を指定できます。 可能な権限型はSELECTINSERTUPDATEREFERENCESです。

has_database_privilege ( [ user name or oid, ] database text or oid, privilege text ) → boolean

Does user have privilege for database? Allowable privilege types are <literal>CREATE</literal>, <literal>CONNECT</literal>, <literal>TEMPORARY</literal>, and <literal>TEMP</literal> (which is equivalent to <literal>TEMPORARY</literal>). ユーザはデータベースに対する権限があるか? 可能な権限型はCREATECONNECTTEMPORARYTEMP (TEMPORARYと同じです)です。

has_foreign_data_wrapper_privilege ( [ user name or oid, ] fdw text or oid, privilege text ) → boolean

Does user have privilege for foreign-data wrapper? The only allowable privilege type is <literal>USAGE</literal>. 現在のユーザは外部データラッパーに対する権限があるか? 可能な権限型はUSAGEだけです。

has_function_privilege ( [ user name or oid, ] function text or oid, privilege text ) → boolean

Does user have privilege for function? The only allowable privilege type is <literal>EXECUTE</literal>. ユーザは関数に対する権限があるか? 可能な権限型はEXECUTEだけです。

When specifying a function by name rather than by OID, the allowed input is the same as for the <type>regprocedure</type> data type (see <xref linkend="datatype-oid"/>). An example is: 関数をOIDではなく名前で指定する場合、regprocedureデータ型(8.19を参照)と同じ入力が可能です。 例を示します。

SELECT has_function_privilege('joeuser', 'myfunc(int, text)', 'execute');

has_language_privilege ( [ user name or oid, ] language text or oid, privilege text ) → boolean

Does user have privilege for language? The only allowable privilege type is <literal>USAGE</literal>. ユーザは言語に対する権限があるか? 可能な権限型はUSAGEだけです。

has_parameter_privilege ( [ user name or oid, ] parameter text, privilege text ) → boolean

Does user have privilege for configuration parameter? The parameter name is case-insensitive. Allowable privilege types are <literal>SET</literal> and <literal>ALTER SYSTEM</literal>. ユーザーに構成パラメータに対する権限があるか? パラメータ名では大文字と小文字が区別されません。 使用可能な権限タイプはSETおよびALTER SYSTEMです。

has_schema_privilege ( [ user name or oid, ] schema text or oid, privilege text ) → boolean

Does user have privilege for schema? Allowable privilege types are <literal>CREATE</literal> and <literal>USAGE</literal>. ユーザはスキーマに対する権限があるか? 可能な権限型はCREATEUSAGEです。

has_sequence_privilege ( [ user name or oid, ] sequence text or oid, privilege text ) → boolean

Does user have privilege for sequence? Allowable privilege types are <literal>USAGE</literal>, <literal>SELECT</literal>, and <literal>UPDATE</literal>. ユーザはシーケンスに対する権限があるか? 可能な権限型はUSAGESELECTUPDATEです。

has_server_privilege ( [ user name or oid, ] server text or oid, privilege text ) → boolean

Does user have privilege for foreign server? The only allowable privilege type is <literal>USAGE</literal>. ユーザは外部サーバに対する権限があるか? 可能な権限型はUSAGEだけです。

has_table_privilege ( [ user name or oid, ] table text or oid, privilege text ) → boolean

Does user have privilege for table? Allowable privilege types are <literal>SELECT</literal>, <literal>INSERT</literal>, <literal>UPDATE</literal>, <literal>DELETE</literal>, <literal>TRUNCATE</literal>, <literal>REFERENCES</literal>, and <literal>TRIGGER</literal>. ユーザはテーブルに対する権限があるか? 可能な権限型はSELECTINSERTUPDATEDELETETRUNCATEREFERENCESTRIGGERです。

has_tablespace_privilege ( [ user name or oid, ] tablespace text or oid, privilege text ) → boolean

Does user have privilege for tablespace? The only allowable privilege type is <literal>CREATE</literal>. ユーザはテーブル空間に対する権限があるか? 可能な権限型はCREATEです。

has_type_privilege ( [ user name or oid, ] type text or oid, privilege text ) → boolean

Does user have privilege for data type? The only allowable privilege type is <literal>USAGE</literal>. When specifying a type by name rather than by OID, the allowed input is the same as for the <type>regtype</type> data type (see <xref linkend="datatype-oid"/>). ユーザにデータ型に対する権限があるか? 可能な権限型はUSAGEだけです。 OIDではなく名前で型を指定する際は、可能な入力はregtypeデータ型に対するのと同じものです(8.19参照)。

pg_has_role ( [ user name or oid, ] role text or oid, privilege text ) → boolean

Does user have privilege for role? Allowable privilege types are <literal>MEMBER</literal>, <literal>USAGE</literal>, and <literal>SET</literal>. <literal>MEMBER</literal> denotes direct or indirect membership in the role without regard to what specific privileges may be conferred. <literal>USAGE</literal> denotes whether the privileges of the role are immediately available without doing <command>SET ROLE</command>, while <literal>SET</literal> denotes whether it is possible to change to the role using the <literal>SET ROLE</literal> command. This function does not allow the special case of setting <parameter>user</parameter> to <literal>public</literal>, because the PUBLIC pseudo-role can never be a member of real roles. ユーザにロールに対する権限があるか? 可能な権限型はMEMBERUSAGESETです。 特定の権限が与えられているかどうかにかかわらず、MEMBERは直接あるいは間接的にそのロールのメンバであることを示します。(すなわち、SET ROLEを実行する権限です) SETSET ROLEコマンドを用いてロールに変更を加えることができるかどうかを示すのに対し、USAGEは、そのロールの権限がSET ROLEを実行することなく、直ちに利用可能であることを示します。 この関数はuserpublicに設定する特別なケースを許可しません。 PUBLIC仮想ロールは実在するロールのメンバには決してなれないからです。

row_security_active ( table text or oid ) → boolean

Is row-level security active for the specified table in the context of the current user and current environment? 現在のユーザと環境のコンテキストにおいて、指定のテーブルに対して行単位セキュリティは有効か?


<xref linkend="functions-aclitem-op-table"/> shows the operators available for the <type>aclitem</type> type, which is the catalog representation of access privileges. See <xref linkend="ddl-priv"/> for information about how to read access privilege values. アクセス権限のカタログ表現であるaclitem型で利用可能な演算子を表 9.69に示します。 アクセス権限値を解釈する方法に関する情報は5.7をご覧ください。

表9.69 aclitem演算子

<title><type>aclitem</type> Operators</title>

Operator 演算子

Description 説明

Example(s)

aclitem = aclitemboolean

Are <type>aclitem</type>s equal? (Notice that type <type>aclitem</type> lacks the usual set of comparison operators; it has only equality. In turn, <type>aclitem</type> arrays can only be compared for equality.) aclitemは等しいか? (aclitem型には通常の比較演算子の組がありません。等値だけです。 同じようにaclitemの配列は等値比較だけが可能です。)

'calvin=r*w/hobbes'::aclitem = 'calvin=r*w*/hobbes'::aclitemf

aclitem[] @> aclitemboolean

Does array contain the specified privileges? (This is true if there is an array entry that matches the <type>aclitem</type>'s grantee and grantor, and has at least the specified set of privileges.) 配列は指定した権限を含んでいるか? (これはaclitemを与えられる側と与える側にマッチする配列のエントリを含んでいて、少なくとも指定した権限の集合を持つ場合に真となります。)

'{calvin=r*w/hobbes,hobbes=r*w*/postgres}'::aclitem[] @> 'calvin=r*/hobbes'::aclitemt

aclitem[] ~ aclitemboolean

This is a deprecated alias for <literal>@&gt;</literal>. これは@>の廃止予定の別名です。

'{calvin=r*w/hobbes,hobbes=r*w*/postgres}'::aclitem[] ~ 'calvin=r*/hobbes'::aclitemt


<xref linkend="functions-aclitem-fn-table"/> shows some additional functions to manage the <type>aclitem</type> type. 表 9.70aclitem型を管理する追加の関数を示します。

表9.70 aclitem関数

<title><type>aclitem</type> Functions</title>

Function 関数

Description 説明

acldefault ( type "char", ownerId oid ) → aclitem[]

Constructs an <type>aclitem</type> array holding the default access privileges for an object of type <parameter>type</parameter> belonging to the role with OID <parameter>ownerId</parameter>. This represents the access privileges that will be assumed when an object's ACL entry is null. (The default access privileges are described in <xref linkend="ddl-priv"/>.) The <parameter>type</parameter> parameter must be one of 'c' for <literal>COLUMN</literal>, 'r' for <literal>TABLE</literal> and table-like objects, 's' for <literal>SEQUENCE</literal>, 'd' for <literal>DATABASE</literal>, 'f' for <literal>FUNCTION</literal> or <literal>PROCEDURE</literal>, 'l' for <literal>LANGUAGE</literal>, 'L' for <literal>LARGE OBJECT</literal>, 'n' for <literal>SCHEMA</literal>, 'p' for <literal>PARAMETER</literal>, 't' for <literal>TABLESPACE</literal>, 'F' for <literal>FOREIGN DATA WRAPPER</literal>, 'S' for <literal>FOREIGN SERVER</literal>, or 'T' for <literal>TYPE</literal> or <literal>DOMAIN</literal>. ownerIdのOIDを持つロールに所属するtype型のオブジェクトのデフォルト権限を持つaclitem配列を作成します。 これはオブジェクトのACL権限がnullであるときに想定されるアクセス権限を示します。 (デフォルトアクセス権限については5.7で述べています。) typeパラメータは以下のどれかでなければなりません。 'c'でCOLUMN、'r'でTABLEおよびテーブルに見えるオブジェクト、's'でSEQUENCE、'd'でDATABASE、'f'でFUNCTIONあるいはPROCEDURE、'l'でLANGUAGE、'L'でLARGE OBJECT、'n'でSCHEMA、'p'でPARAMETER、't'でTABLESPACE、'F'でFOREIGN DATA WRAPPER、'S'でFOREIGN SERVER、'T'でTYPEあるいはDOMAINを表します。

aclexplode ( aclitem[] ) → setof record ( grantor oid, grantee oid, privilege_type text, is_grantable boolean )

Returns the <type>aclitem</type> array as a set of rows. If the grantee is the pseudo-role PUBLIC, it is represented by zero in the <parameter>grantee</parameter> column. Each granted privilege is represented as <literal>SELECT</literal>, <literal>INSERT</literal>, etc (see <xref linkend="privilege-abbrevs-table"/> for a full list). Note that each privilege is broken out as a separate row, so only one keyword appears in the <parameter>privilege_type</parameter> column. 行の集合としてaclitem配列を返します。 アクセス権を与えられる側が仮想ロールPUBLICなら、grantee列でgranteeはゼロで表現されます。 各々の与えられた権限はSELECTINSERTなどで表現されます。(完全なリストは表 5.1を参照してください)。 各々の権限は別々の行に分解され、privilege_type列には一つのキーワードだけが現れることに注意してください。

makeaclitem ( grantee oid, grantor oid, privileges text, is_grantable boolean ) → aclitem

Constructs an <type>aclitem</type> with the given properties. <parameter>privileges</parameter> is a comma-separated list of privilege names such as <literal>SELECT</literal>, <literal>INSERT</literal>, etc, all of which are set in the result. (Case of the privilege string is not significant, and extra whitespace is allowed between but not within privilege names.) 与えられた属性でaclitemを作成します。 privilegesは、結果中に設定されるSELECTINSERTなどのカンマで区切られた権限名のリストです。 (権限文字列の大文字小文字の区別は無視されます。権限文字の間に余分な空白が合っても構いませんが、権限文字列中に空白があってはいけません。)


9.26.3. スキーマ可視性問い合わせ関数 #

<title>Schema Visibility Inquiry Functions</title>

<xref linkend="functions-info-schema-table"/> shows functions that determine whether a certain object is <firstterm>visible</firstterm> in the current schema search path. For example, a table is said to be visible if its containing schema is in the search path and no table of the same name appears earlier in the search path. This is equivalent to the statement that the table can be referenced by name without explicit schema qualification. Thus, to list the names of all visible tables: 表 9.71に、特定のオブジェクトが、現行スキーマの検索パスにおいて可視かどうかを判別する関数を示します。 例えば、あるテーブルを含むスキーマが検索パス内に存在し、検索パス内の前方に同じ名前のテーブルがない場合、そのテーブルは可視であると言います。 つまり、これは、テーブルが明示的なスキーマ修飾なしで名前によって参照可能であるということです。 ですから全ての可視テーブルの名前を列挙するには以下のようにします。

SELECT relname FROM pg_class WHERE pg_table_is_visible(oid);

For functions and operators, an object in the search path is said to be visible if there is no object of the same name <emphasis>and argument data type(s)</emphasis> earlier in the path. For operator classes and families, both the name and the associated index access method are considered. 関数および演算子では、パスの前方に同じ名前かつ同じ引数のデータ型を持つオブジェクトが存在しなければ、検索パス内のオブジェクトは可視と言えます。 演算子クラスと(演算子)族では、名前と関連するインデックスアクセスメソッドが考慮されます。

表9.71 スキーマ可視性照会関数

<title>Schema Visibility Inquiry Functions</title>

Function 関数

Description 説明

pg_collation_is_visible ( collation oid ) → boolean

Is collation visible in search path? 照合順序が検索パスにおいて可視か?

pg_conversion_is_visible ( conversion oid ) → boolean

Is conversion visible in search path? 変換が検索パスにおいて可視か?

pg_function_is_visible ( function oid ) → boolean

Is function visible in search path? (This also works for procedures and aggregates.) 関数が検索パスにおいて可視か? (これはプロシージャと集約にも使えます。)

pg_opclass_is_visible ( opclass oid ) → boolean

Is operator class visible in search path? 演算子クラスが検索パスにおいて可視か?

pg_operator_is_visible ( operator oid ) → boolean

Is operator visible in search path? 演算子が検索パスにおいて可視か?

pg_opfamily_is_visible ( opclass oid ) → boolean

Is operator family visible in search path? 演算子族が可視か?

pg_statistics_obj_is_visible ( stat oid ) → boolean

Is statistics object visible in search path? 統計情報オブジェクトが検索パスにおいて可視か?

pg_table_is_visible ( table oid ) → boolean

Is table visible in search path? (This works for all types of relations, including views, materialized views, indexes, sequences and foreign tables.) テーブルが検索パスにおいて可視か? (これはビュー、マテリアライズドビュー、インデックス、シーケンス、外部テーブルを含むべての形式のリレーションで使用できます。)

pg_ts_config_is_visible ( config oid ) → boolean

Is text search configuration visible in search path? テキスト検索設定が検索パスにおいて可視か?

pg_ts_dict_is_visible ( dict oid ) → boolean

Is text search dictionary visible in search path? テキスト検索辞書が検索パスにおいて可視か?

pg_ts_parser_is_visible ( parser oid ) → boolean

Is text search parser visible in search path? テキスト検索パーサが検索パスにおいて可視か?

pg_ts_template_is_visible ( template oid ) → boolean

Is text search template visible in search path? テキスト検索テンプレートが検索パスにおいて可視か?

pg_type_is_visible ( type oid ) → boolean

Is type (or domain) visible in search path? 型(またはドメイン)が検索パスにおいて可視か?


All these functions require object OIDs to identify the object to be checked. If you want to test an object by name, it is convenient to use the OID alias types (<type>regclass</type>, <type>regtype</type>, <type>regprocedure</type>, <type>regoperator</type>, <type>regconfig</type>, or <type>regdictionary</type>), for example: これらの関数は全て、検査するオブジェクトを識別するために、オブジェクトのOIDを必要とします。 オブジェクトを名前でテストする場合、OID別名型(regclassregtyperegprocedureregoperatorregconfig、またはregdictionary)を使用すると便利です。 例えば、以下のようにします。

SELECT pg_type_is_visible('myschema.widget'::regtype);

Note that it would not make much sense to test a non-schema-qualified type name in this way &mdash; if the name can be recognized at all, it must be visible. ただし、このようなやり方でスキーマ修飾されていない型名をテストしても、あまり意味がないことに注意してください。名前が認識されれば、それは必ず可視ということになります。

9.26.4. システムカタログ情報関数 #

<title>System Catalog Information Functions</title>

<xref linkend="functions-info-catalog-table"/> lists functions that extract information from the system catalogs. 表 9.72に、システムカタログから情報を抽出する関数を列挙します。

表9.72 システムカタログ情報関数

<title>System Catalog Information Functions</title>

Function 関数

Description 説明

format_type ( type oid, typemod integer ) → text

Returns the SQL name for a data type that is identified by its type OID and possibly a type modifier. Pass NULL for the type modifier if no specific modifier is known. 型OIDと型修飾子で決まるデータ型のSQL名を返します。 型修飾子が不明な場合はNULLを型修飾子に渡してください。

pg_char_to_encoding ( encoding name ) → integer

Converts the supplied encoding name into an integer representing the internal identifier used in some system catalog tables. Returns <literal>-1</literal> if an unknown encoding name is provided. 指定されたエンコード名を、一部のシステムカタログテーブルで使用されている内部識別子を表す整数に変換します。 不明なエンコード名が指定された場合は-1を返します。

pg_encoding_to_char ( encoding integer ) → name

Converts the integer used as the internal identifier of an encoding in some system catalog tables into a human-readable string. Returns an empty string if an invalid encoding number is provided. システムカタログテーブル内のエンコーディングの内部識別子として使用されている整数を、読み取り可能な文字列に変換します。 無効なエンコーディング番号が指定されている場合は、空の文字列を返します。

pg_get_catalog_foreign_keys () → setof record ( fktable regclass, fkcols text[], pktable regclass, pkcols text[], is_array boolean, is_opt boolean )

Returns a set of records describing the foreign key relationships that exist within the <productname>PostgreSQL</productname> system catalogs. The <parameter>fktable</parameter> column contains the name of the referencing catalog, and the <parameter>fkcols</parameter> column contains the name(s) of the referencing column(s). Similarly, the <parameter>pktable</parameter> column contains the name of the referenced catalog, and the <parameter>pkcols</parameter> column contains the name(s) of the referenced column(s). If <parameter>is_array</parameter> is true, the last referencing column is an array, each of whose elements should match some entry in the referenced catalog. If <parameter>is_opt</parameter> is true, the referencing column(s) are allowed to contain zeroes instead of a valid reference. PostgreSQLシステムカタログ中に存在する外部キー関係を記述するレコードの集合を返します。 fktable列は参照するカタログの名前を示し、fkcols列は参照する列の名前を示します。 同様に、pktableは参照されるカタログの名前を示し、pkcolsは参照される列の名前を示します。 is_arrayが真なら、最後の参照列は配列で、各要素は参照カタログにマッチします。 is_optが真なら、参照される列は有効な参照の代わりにゼロを含んでも構いません。

pg_get_constraintdef ( constraint oid [, pretty boolean ] ) → text

Reconstructs the creating command for a constraint. (This is a decompiled reconstruction, not the original text of the command.) 制約を作成したコマンドを再構築します。 (これは逆コンパイルで構成したもので、元のコマンドのテキストではありません。)

pg_get_expr ( expr pg_node_tree, relation oid [, pretty boolean ] ) → text

Decompiles the internal form of an expression stored in the system catalogs, such as the default value for a column. If the expression might contain Vars, specify the OID of the relation they refer to as the second parameter; if no Vars are expected, passing zero is sufficient. 列のデフォルト値のような、システムカタログに格納された内部表現式を逆コンパイルします。 式に変数が含まれている場合は2番目の引数として参照されているリレーションのOIDを指定してください。変数が含まれていない場合は、ゼロを渡しておけば十分です。

pg_get_functiondef ( func oid ) → text

Reconstructs the creating command for a function or procedure. (This is a decompiled reconstruction, not the original text of the command.) The result is a complete <command>CREATE OR REPLACE FUNCTION</command> or <command>CREATE OR REPLACE PROCEDURE</command> statement. 関数あるいはプロシージャの作成コマンドを再構築します。 (これは逆コンパイルによる再構築で、元のコマンドのテキストではありません。) 結果は完全なCREATE OR REPLACE FUNCTIONあるいはCREATE OR REPLACE PROCEDURE文です。

pg_get_function_arguments ( func oid ) → text

Reconstructs the argument list of a function or procedure, in the form it would need to appear in within <command>CREATE FUNCTION</command> (including default values). CREATE FUNCTION中に現れる形で関数あるいはプロシージャの引数のリストを再構築します。 (デフォルト値を含みます。)

pg_get_function_identity_arguments ( func oid ) → text

Reconstructs the argument list necessary to identify a function or procedure, in the form it would need to appear in within commands such as <command>ALTER FUNCTION</command>. This form omits default values. ALTER FUNCTIONのようなコマンド中に現れる形で関数あるいはプロシージャの引数のリストを再構築します。 この形式ではデフォルト値は省略します。

pg_get_function_result ( func oid ) → text

Reconstructs the <literal>RETURNS</literal> clause of a function, in the form it would need to appear in within <command>CREATE FUNCTION</command>. Returns <literal>NULL</literal> for a procedure. CREATE FUNCTION中に現れる形で関数のRETURNS句を再構築します。 プロシージャに対してNULLを返します。

pg_get_indexdef ( index oid [, column integer, pretty boolean ] ) → text

Reconstructs the creating command for an index. (This is a decompiled reconstruction, not the original text of the command.) If <parameter>column</parameter> is supplied and is not zero, only the definition of that column is reconstructed. インデックスを作成するコマンドを再構築します。 (これは逆コンパイルによる再構築で、元のコマンドのテキストではありません。) columnが渡されていてゼロでないなら、その列の定義だけが再構築されます。

pg_get_keywords () → setof record ( word text, catcode "char", barelabel boolean, catdesc text, baredesc text )

Returns a set of records describing the SQL keywords recognized by the server. The <parameter>word</parameter> column contains the keyword. The <parameter>catcode</parameter> column contains a category code: <literal>U</literal> for an unreserved keyword, <literal>C</literal> for a keyword that can be a column name, <literal>T</literal> for a keyword that can be a type or function name, or <literal>R</literal> for a fully reserved keyword. The <parameter>barelabel</parameter> column contains <literal>true</literal> if the keyword can be used as a <quote>bare</quote> column label in <command>SELECT</command> lists, or <literal>false</literal> if it can only be used after <literal>AS</literal>. The <parameter>catdesc</parameter> column contains a possibly-localized string describing the keyword's category. The <parameter>baredesc</parameter> column contains a possibly-localized string describing the keyword's column label status. サーバが認識するSQLキーワードを記述するレコードの集合を返します。 word列にはキーワードが含まれます。 catcode列にはカテゴリーコードが含まれます。Uは非予約キーワード、Cは列名になり得るキーワード、Tは型あるいは関数名になり得るキーワード、Rは完全な予約キーワードです。 barelabel列は、キーワードがbare列ラベルとしてSELECTリスト中で使えるならtrueで、ASの後にのみ使えるのならfalseです。 catdesc列にはキーワードカテゴリーを記述する、ローカライズ化されることもある文字列が含まれます。 baredesc列にはキーワードの列ラベル状態を記述する、ローカライズ化されることもある文字列が含まれます。

pg_get_partkeydef ( table oid ) → text

Reconstructs the definition of a partitioned table's partition key, in the form it would have in the <literal>PARTITION BY</literal> clause of <command>CREATE TABLE</command>. (This is a decompiled reconstruction, not the original text of the command.) パーティション化テーブルのパーティションキーの定義を、CREATE TABLEPARTITION BY句の形式で再構成します。(これは逆コンパイルされた再構成であり、コマンドのオリジナルテキストではありません。 )

pg_get_ruledef ( rule oid [, pretty boolean ] ) → text

Reconstructs the creating command for a rule. (This is a decompiled reconstruction, not the original text of the command.) ルールを作成するコマンドを再構築します。 (これは逆コンパイルによる再構築で、元のコマンドのテキストではありません。)

pg_get_serial_sequence ( table text, column text ) → text

Returns the name of the sequence associated with a column, or NULL if no sequence is associated with the column. If the column is an identity column, the associated sequence is the sequence internally created for that column. For columns created using one of the serial types (<type>serial</type>, <type>smallserial</type>, <type>bigserial</type>), it is the sequence created for that serial column definition. In the latter case, the association can be modified or removed with <command>ALTER SEQUENCE OWNED BY</command>. (This function probably should have been called <function>pg_get_owned_sequence</function>; its current name reflects the fact that it has historically been used with serial-type columns.) The first parameter is a table name with optional schema, and the second parameter is a column name. Because the first parameter potentially contains both schema and table names, it is parsed per usual SQL rules, meaning it is lower-cased by default. The second parameter, being just a column name, is treated literally and so has its case preserved. The result is suitably formatted for passing to the sequence functions (see <xref linkend="functions-sequence"/>). 列に関連するシーケンスの名前を返します。 列に関連するシーケンスが存在しなければ、NULLを返します。 列がIDENTITY列の場合、関連するシーケンスはIDENTITY列に対して内部的に作成されたシーケンスとなります。 SERIAL型(serialsmallserialbigserial)の一つを使って作られた列については、そのSERIAL列の定義に対して作られたシーケンスとなります。 後者の場合、この関連付けはALTER SEQUENCE OWNED BYで修正または削除することができます。 (この関数はおそらくpg_get_owned_sequenceと呼ばれるべきだったのでしょうが、現在の名前はそれが主にserial列またはbigserial列と一緒に使われていたという事実によります。) 最初の入力パラメータはテーブル名で、スキーマを付けることもできます。 2番目のパラメータは列名です。 最初のパラメータは普通はスキーマとテーブルですので、二重引用符付の識別子としては解釈されません。 つまり、デフォルトで小文字に変換されます。 一方2番目のパラメータは単なる列名であり、二重引用符付として解釈され、その大文字小文字は保持されます。 この関数は、シーケンス関数(9.17を参照)に渡すことができるよう適切な書式で値を返します。

A typical use is in reading the current value of the sequence for an identity or serial column, for example: 典型的な使用法はIDENTITY列またはSERIAL列のシーケンスの現在値を読み取ることです。例を示します。

SELECT currval(pg_get_serial_sequence('sometable', 'id'));

pg_get_statisticsobjdef ( statobj oid ) → text

Reconstructs the creating command for an extended statistics object. (This is a decompiled reconstruction, not the original text of the command.) 拡張統計情報オブジェクトを作成するコマンドを再構築します。 (これは逆コンパイルによる再構築で、元のコマンドのテキストではありません。)

pg_get_triggerdef ( trigger oid [, pretty boolean ] ) → text

Reconstructs the creating command for a trigger. (This is a decompiled reconstruction, not the original text of the command.) トリガを作成するコマンドを再構築します。 (これは逆コンパイルによる再構築で、元のコマンドのテキストではありません。)

pg_get_userbyid ( role oid ) → name

Returns a role's name given its OID. OIDで指定されるロール名を返します。

pg_get_viewdef ( view oid [, pretty boolean ] ) → text

Reconstructs the underlying <command>SELECT</command> command for a view or materialized view. (This is a decompiled reconstruction, not the original text of the command.) ビューあるいはマテリアライズドビューの背後にあるSELECTコマンドを再構築します。 (これは逆コンパイルによる再構築で、元のコマンドのテキストではありません。)

pg_get_viewdef ( view oid, wrap_column integer ) → text

Reconstructs the underlying <command>SELECT</command> command for a view or materialized view. (This is a decompiled reconstruction, not the original text of the command.) In this form of the function, pretty-printing is always enabled, and long lines are wrapped to try to keep them shorter than the specified number of columns. ビューあるいはマテリアライズドビューの背後にあるSELECTコマンドを再構築します。 (これは逆コンパイルによる再構築で、元のコマンドのテキストではありません。) この関数形式では整形するオプションは常に有効で、列数よりも短く保つように長い行は折り返されます。

pg_get_viewdef ( view text [, pretty boolean ] ) → text

Reconstructs the underlying <command>SELECT</command> command for a view or materialized view, working from a textual name for the view rather than its OID. (This is deprecated; use the OID variant instead.) ビューあるいはマテリアライズドビューの背後にあるSELECTコマンドを再構築します。ビューのOIDではなく、テキスト形式の名前を使います。 (これは廃止予定です。OIDのバージョンを使ってください。)

pg_index_column_has_property ( index regclass, column integer, property text ) → boolean

Tests whether an index column has the named property. Common index column properties are listed in <xref linkend="functions-info-index-column-props"/>. (Note that extension access methods can define additional property names for their indexes.) <literal>NULL</literal> is returned if the property name is not known or does not apply to the particular object, or if the OID or column number does not identify a valid object. インデックス列が名前付きのプロパティを持つかどうかを検査します。 共通のインデックス列プロパティは表 9.73に列挙されています。 (拡張アクセスメソッドはインデックスに対して追加のプロパティ名を持てることに注意してください。) プロパティ名が不明あるいは特定のオブジェクトに適用されない場合、OIDあるいは列番号が有効なオブジェクトを特定しない場合はNULLが返ります。

pg_index_has_property ( index regclass, property text ) → boolean

Tests whether an index has the named property. Common index properties are listed in <xref linkend="functions-info-index-props"/>. (Note that extension access methods can define additional property names for their indexes.) <literal>NULL</literal> is returned if the property name is not known or does not apply to the particular object, or if the OID does not identify a valid object. インデックスが名前付きのプロパティを持つかどうかを検査します。 共通のインデックスプロパティは表 9.74に列挙されています。 (拡張アクセスメソッドはインデックスに対して追加のプロパティ名を持てることに注意してください。) プロパティ名が不明あるいは特定のオブジェクトに適用されない場合、OIDが有効なオブジェクトを特定しない場合はNULLが返ります。

pg_indexam_has_property ( am oid, property text ) → boolean

Tests whether an index access method has the named property. Access method properties are listed in <xref linkend="functions-info-indexam-props"/>. <literal>NULL</literal> is returned if the property name is not known or does not apply to the particular object, or if the OID does not identify a valid object. インデックスアクセスメソッドが名前付きのプロパティを持つかどうかを検査します。 アクセスメソッドプロパティは表 9.75に列挙されています。 プロパティ名が不明あるいは特定のオブジェクトに適用されない場合、OIDが有効なオブジェクトを特定しない場合はNULLが返ります。

pg_options_to_table ( options_array text[] ) → setof record ( option_name text, option_value text )

Returns the set of storage options represented by a value from <structname>pg_class</structname>.<structfield>reloptions</structfield> or <structname>pg_attribute</structname>.<structfield>attoptions</structfield>. pg_class.reloptionsあるいはpg_attribute.attoptionsの値で表現されるストレージオプションの集合を返します。

pg_settings_get_flags ( guc text ) → text[]

Returns an array of the flags associated with the given GUC, or <literal>NULL</literal> if it does not exist. The result is an empty array if the GUC exists but there are no flags to show. Only the most useful flags listed in <xref linkend="functions-pg-settings-flags"/> are exposed. 指定されたGUCに関連付けられたフラグの配列を返します。 存在しない場合はNULLを返します。 GUCが存在しても表示するフラグがない場合、結果は空の配列になります。 表 9.76にリストされている最も有用なフラグのみが公開されます。

pg_tablespace_databases ( tablespace oid ) → setof oid

Returns the set of OIDs of databases that have objects stored in the specified tablespace. If this function returns any rows, the tablespace is not empty and cannot be dropped. To identify the specific objects populating the tablespace, you will need to connect to the database(s) identified by <function>pg_tablespace_databases</function> and query their <structname>pg_class</structname> catalogs. 指定したテーブル空間に格納されるオブジェクトを持つデータベースのOIDの集合を返します。 この関数が何らかの行を返すならば、そのテーブル空間は空ではなく、削除できません。 特定のオブジェクトがそのテーブル空間にあるかどうかを確認するには、pg_tablespace_databasesで識別されるデータベースに接続してpg_classカタログを検索する必要があります。

pg_tablespace_location ( tablespace oid ) → text

Returns the file system path that this tablespace is located in. テーブル空間が配置されているファイルシステムのパスを返します。

pg_typeof ( "any" ) → regtype

Returns the OID of the data type of the value that is passed to it. This can be helpful for troubleshooting or dynamically constructing SQL queries. The function is declared as returning <type>regtype</type>, which is an OID alias type (see <xref linkend="datatype-oid"/>); this means that it is the same as an OID for comparison purposes but displays as a type name. 渡された値のデータ型のOIDを返します。 これはトラブル解決作業、または動的にSQL問い合わせを生成するのに便利です。 この関数は、OIDの別名型であるregtypeを返すものとして宣言されます(8.19を参照)。つまり、比較目的のOIDと同一ですが、型名として表示されます。

For example: 以下に例をあげます。

SELECT pg_typeof(33);
 pg_typeof
-----------
 integer

SELECT typlen FROM pg_type WHERE oid = pg_typeof(33);
 typlen
--------
      4

COLLATION FOR ( "any" ) → text

Returns the name of the collation of the value that is passed to it. The value is quoted and schema-qualified if necessary. If no collation was derived for the argument expression, then <literal>NULL</literal> is returned. If the argument is not of a collatable data type, then an error is raised. 渡された値の照合順序の名前を返します。 値は必要ならば引用符付きでスキーマ修飾されます。 引数式から照合順序が生じなければ、NULLが返ります。 引数が照合可能なデータ型でなければ、エラーが生じます。

For example: 例を挙げます。

SELECT collation for (description) FROM pg_description LIMIT 1;
 pg_collation_for
------------------
 "default"

SELECT collation for ('foo' COLLATE "de_DE");
 pg_collation_for
------------------
 "de_DE"

to_regclass ( text ) → regclass

Translates a textual relation name to its OID. A similar result is obtained by casting the string to type <type>regclass</type> (see <xref linkend="datatype-oid"/>); however, this function will return <literal>NULL</literal> rather than throwing an error if the name is not found. テキスト形式のリレーション名をOIDに変換します。 同様の結果はその文字列をregclass型にキャストすることによっても得られます。(8.19参照。) しかしこの関数は名前が見つからない場合にエラーを起こすのではなく、NULLを返します。

to_regcollation ( text ) → regcollation

Translates a textual collation name to its OID. A similar result is obtained by casting the string to type <type>regcollation</type> (see <xref linkend="datatype-oid"/>); however, this function will return <literal>NULL</literal> rather than throwing an error if the name is not found. テキスト形式の照合順名をOIDに変換します。 同様の結果はその文字列をregcollation型にキャストすることによっても得られます。(8.19参照。) しかしこの関数は名前が見つからない場合にエラーを起こすのではなく、NULLを返します。

to_regnamespace ( text ) → regnamespace

Translates a textual schema name to its OID. A similar result is obtained by casting the string to type <type>regnamespace</type> (see <xref linkend="datatype-oid"/>); however, this function will return <literal>NULL</literal> rather than throwing an error if the name is not found. テキスト形式のスキーマ名をOIDに変換します。 同様の結果はその文字列をregnamespace型にキャストすることによっても得られます。(8.19参照。) しかしこの関数は名前が見つからない場合にエラーを起こすのではなく、NULLを返します。

to_regoper ( text ) → regoper

Translates a textual operator name to its OID. A similar result is obtained by casting the string to type <type>regoper</type> (see <xref linkend="datatype-oid"/>); however, this function will return <literal>NULL</literal> rather than throwing an error if the name is not found or is ambiguous. テキスト形式の演算子名をOIDに変換します。 同様の結果はその文字列をregoper型にキャストすることによっても得られます。(8.19参照。) しかしこの関数は名前が見つからない、あるいは曖昧な場合にエラーを起こすのではなく、NULLを返します。

to_regoperator ( text ) → regoperator

Translates a textual operator name (with parameter types) to its OID. A similar result is obtained by casting the string to type <type>regoperator</type> (see <xref linkend="datatype-oid"/>); however, this function will return <literal>NULL</literal> rather than throwing an error if the name is not found. テキスト形式の演算子名(パラメータ型付き)をOIDに変換します。 同様の結果はその文字列をregoperator型にキャストすることによっても得られます。(8.19参照。) しかしこの関数は名前が見つからない場合にエラーを起こすのではなく、NULLを返します。

to_regproc ( text ) → regproc

Translates a textual function or procedure name to its OID. A similar result is obtained by casting the string to type <type>regproc</type> (see <xref linkend="datatype-oid"/>); however, this function will return <literal>NULL</literal> rather than throwing an error if the name is not found or is ambiguous. テキスト形式の関数名またはプロシージャ名をOIDに変換します。 同様の結果はその文字列をregproc型にキャストすることによっても得られます。(8.19参照。) しかしこの関数は名前が見つからない、あるいは曖昧な場合にエラーを起こすのではなく、NULLを返します。

to_regprocedure ( text ) → regprocedure

Translates a textual function or procedure name (with argument types) to its OID. A similar result is obtained by casting the string to type <type>regprocedure</type> (see <xref linkend="datatype-oid"/>); however, this function will return <literal>NULL</literal> rather than throwing an error if the name is not found. テキスト形式の関数名またはプロシージャ名(引数型付き)をOIDに変換します。 同様の結果はその文字列をregprocedure型にキャストすることによっても得られます。(8.19参照。) しかしこの関数は名前が見つからない場合にエラーを起こすのではなく、NULLを返します。

to_regrole ( text ) → regrole

Translates a textual role name to its OID. A similar result is obtained by casting the string to type <type>regrole</type> (see <xref linkend="datatype-oid"/>); however, this function will return <literal>NULL</literal> rather than throwing an error if the name is not found. テキスト形式のロール名をOIDに変換します。 同様の結果はその文字列をregrole型にキャストすることによっても得られます。(8.19参照。) しかしこの関数は名前が見つからない場合にエラーを起こすのではなく、NULLを返します。

to_regtype ( text ) → regtype

Translates a textual type name to its OID. A similar result is obtained by casting the string to type <type>regtype</type> (see <xref linkend="datatype-oid"/>); however, this function will return <literal>NULL</literal> rather than throwing an error if the name is not found. テキスト形式の型名をOIDに変換します。 同様の結果はその文字列をregtype型にキャストすることによっても得られます。(8.19参照。) しかしこの関数は名前が見つからない場合にエラーを起こすのではなく、NULLを返します。


Most of the functions that reconstruct (decompile) database objects have an optional <parameter>pretty</parameter> flag, which if <literal>true</literal> causes the result to be <quote>pretty-printed</quote>. Pretty-printing suppresses unnecessary parentheses and adds whitespace for legibility. The pretty-printed format is more readable, but the default format is more likely to be interpreted the same way by future versions of <productname>PostgreSQL</productname>; so avoid using pretty-printed output for dump purposes. Passing <literal>false</literal> for the <parameter>pretty</parameter> parameter yields the same result as omitting the parameter. データベースオブジェクトを再構築(逆コンパイル)する関数の多くにオプションのprettyフラグがあり、trueなら結果が整形されるようになっています。 整形によって不必要な括弧が抑止され、見やすさのために空白は追加されます。 整形形式は見やすいですが、デフォルト形式は将来のバージョンのPostgreSQLでも同じように解釈される可能性が高いです。 ですから、整形された出力をダンプ目的で使わないでください。 pretty引数にfalseを渡すとパラメータを省略したとの同じ結果が得られます。

表9.73 インデックス列の属性

<title>Index Column Properties</title>
名前説明
asc前方スキャンで列は昇順にソートされるか
desc前方スキャンで列は降順にソートされるか
nulls_first前方スキャンで列はNULLを先頭にしてソートするか
nulls_last前方スキャンで列はNULLを最後にしてソートするか
orderable列は定義済みのソート順を所有しているか
distance_orderable列は距離の演算子の順序に従ってスキャンできるか、例えばORDER BY col <-> 定数など
returnable列の値をインデックスオンリースキャンで返すことができるか
search_array列はcol = ANY(array)の検索をネイティブにサポートしているか
search_nulls列はIS NULLおよびIS NOT NULLの検索をサポートしているか

表9.74 インデックスの属性

<title>Index Properties</title>
名前説明
clusterableインデックスをCLUSTERコマンドで使うことができるか
index_scanインデックスは通常の(ビットマップでない)スキャンをサポートしているか
bitmap_scanインデックスはビットマップスキャンをサポートしているか
backward_scanスキャンの途中でスキャン方向を変更できるか(マテリアライゼーションを必要とせずにカーソルの FETCH BACKWARDをサポートするため)

表9.75 インデックスアクセスメソッドの属性

<title>Index Access Method Properties</title>
名前説明
can_orderアクセスメソッドはCREATE INDEXにおいてASCDESCおよび関連するキーワードをサポートしているか
can_uniqueアクセスメソッドは一意インデックスをサポートしているか
can_multi_colアクセスメソッドは複数列にまたがるインデックスをサポートしているか
can_excludeアクセスメソッドは排他制約をサポートしているか
can_includeアクセスメソッドがCREATE INDEXINCLUDE句をサポートしているか

表9.76 GUC Flags

フラグ説明
EXPLAINこのフラグを持つパラメータはEXPLAIN (SETTINGS)コマンドに含まれます。
NO_SHOW_ALLこのフラグを持つパラメータはSHOW ALLコマンドから除外されます。
NO_RESETこのフラグを持つパラメータはRESETコマンドをサポートしません。
NO_RESET_ALLこのフラグを持つパラメータはRESET ALLコマンドから除外されます。
NOT_IN_SAMPLEこのフラグを持つパラメータはデフォルトではpostgresql.confに含まれません。
RUNTIME_COMPUTEDこのフラグを持つパラメータは実行時に計算されます。

9.26.5. オブジェクトの情報とアドレス付関数 #

<title>Object Information and Addressing Functions</title>

<xref linkend="functions-info-object-table"/> lists functions related to database object identification and addressing. 表 9.77にデータベースオブジェクトの識別とアドレスに関連する関数を示します。

表9.77 オブジェクト情報とアドレスの関数

<title>Object Information and Addressing Functions</title>

Function 関数

Description 説明

pg_describe_object ( classid oid, objid oid, objsubid integer ) → text

Returns a textual description of a database object identified by catalog OID, object OID, and sub-object ID (such as a column number within a table; the sub-object ID is zero when referring to a whole object). This description is intended to be human-readable, and might be translated, depending on server configuration. This is especially useful to determine the identity of an object referenced in the <structname>pg_depend</structname> catalog. This function returns <literal>NULL</literal> values for undefined objects. カタログOID、オブジェクトOID、もしくはサブオブジェクトOID(たとえばテーブル中の列番号。オブジェクト全体を参照している場合は0)で指定されたデータベースオブジェクトのテキストによる説明を返します。 この説明はサーバの設定に依存しますが、人が読んでわかる、そして翻訳も可能になることを目的としたのもです。 これはpg_dependカタログに格納されたオブジェクトの識別判断の際に有用です。 この関数は、未定義オブジェクトに対してNULL値を返します。

pg_identify_object ( classid oid, objid oid, objsubid integer ) → record ( type text, schema text, name text, identity text )

Returns a row containing enough information to uniquely identify the database object specified by catalog OID, object OID and sub-object ID. This information is intended to be machine-readable, and is never translated. <parameter>type</parameter> identifies the type of database object; <parameter>schema</parameter> is the schema name that the object belongs in, or <literal>NULL</literal> for object types that do not belong to schemas; <parameter>name</parameter> is the name of the object, quoted if necessary, if the name (along with schema name, if pertinent) is sufficient to uniquely identify the object, otherwise <literal>NULL</literal>; <parameter>identity</parameter> is the complete object identity, with the precise format depending on object type, and each name within the format being schema-qualified and quoted as necessary. Undefined objects are identified with <literal>NULL</literal> values. カタログOID、オブジェクトOID、そしてサブオブジェクトIDにより指定されるデータベースオブジェクトを一意に特定するために十分な情報を含む行を返します。 この情報は機械による読み取りを目的としており、決して翻訳されません。 typeはデータベースオブジェクトの型を識別するものです。 schemaはオブジェクトが所属するスキーマの名前ですが、スキーマに所属しないオブジェクト型の場合はNULLになります。 nameは(必要なら引用符で括った)オブジェクトの名前ですが、(適切ならスキーマ名と合わせて)オブジェクトの一意識別子として使用できる場合にのみ指定し、それ以外の場合はNULLにします。 identityは完全なオブジェクトの識別で、オブジェクトの型に依存した正確なフォーマットを持っています。 フォーマット内の各部分はスキーマ修飾されており、必要に応じて引用符で括られます。 未定義オブジェクトはNULL値で識別されます。

pg_identify_object_as_address ( classid oid, objid oid, objsubid integer ) → record ( type text, object_names text[], object_args text[] )

Returns a row containing enough information to uniquely identify the database object specified by catalog OID, object OID and sub-object ID. The returned information is independent of the current server, that is, it could be used to identify an identically named object in another server. <parameter>type</parameter> identifies the type of database object; <parameter>object_names</parameter> and <parameter>object_args</parameter> are text arrays that together form a reference to the object. These three values can be passed to <function>pg_get_object_address</function> to obtain the internal address of the object. カタログOID、オブジェクトOID、そしてサブオブジェクトIDにより指定されるデータベースオブジェクトを一意に特定するために充分な情報を含む行を返します。 返される情報は現在のサーバに依存しません。 つまり、他のサーバで全く同じ名前を付けられたオブジェクトを識別するために使うことができます。 typeはデータベースオブジェクトの型を識別するものです。 object_namesobject_argsは文字列の配列で、それらが組み合わされてオブジェクトへの参照を構成します。 これらの3つの値は、オブジェクトの内部アドレスを取得するためにpg_get_object_addressに渡すことができます。

pg_get_object_address ( type text, object_names text[], object_args text[] ) → record ( classid oid, objid oid, objsubid integer )

Returns a row containing enough information to uniquely identify the database object specified by a type code and object name and argument arrays. The returned values are the ones that would be used in system catalogs such as <structname>pg_depend</structname>; they can be passed to other system functions such as <function>pg_describe_object</function> or <function>pg_identify_object</function>. <parameter>classid</parameter> is the OID of the system catalog containing the object; <parameter>objid</parameter> is the OID of the object itself, and <parameter>objsubid</parameter> is the sub-object ID, or zero if none. This function is the inverse of <function>pg_identify_object_as_address</function>. Undefined objects are identified with <literal>NULL</literal> values. 型、オブジェクト名および引数の配列で指定されたデータベースオブジェクトを一意に特定するために十分な情報を含む行を返します。 返される値は、pg_dependなどのシステムカタログで使用されるもので、pg_identify_objectpg_describe_objectなど他のシステム関数に渡すことができます。 classidはオブジェクトを含むシステムカタログのOIDです。 objidはオブジェクト自体のOIDです。 objsubidはオブジェクトのサブID、なければ0です。 この関数はpg_identify_object_as_addressの逆関数です。 未定義オブジェクトはNULL値で識別されます。


9.26.6. コメント情報関数 #

<title>Comment Information Functions</title>

The functions shown in <xref linkend="functions-info-comment-table"/> extract comments previously stored with the <xref linkend="sql-comment"/> command. A null value is returned if no comment could be found for the specified parameters. 表 9.78に示される関数は、COMMENTコマンドによって以前に保存されたコメントを抽出します。 指定されたパラメータに対するコメントが存在しない場合、NULL値が返されます。

表9.78 コメント情報関数

<title>Comment Information Functions</title>

Function 関数

Description 説明

col_description ( table oid, column integer ) → text

Returns the comment for a table column, which is specified by the OID of its table and its column number. (<function>obj_description</function> cannot be used for table columns, since columns do not have OIDs of their own.) テーブルのOIDと列番号で指定されたテーブル列のコメントを返します。 (obj_descriptionはテーブル列には使えません。列は自身のOIDを持たないからです。)

obj_description ( object oid, catalog name ) → text

Returns the comment for a database object specified by its OID and the name of the containing system catalog. For example, <literal>obj_description(123456, 'pg_class')</literal> would retrieve the comment for the table with OID 123456. OIDとそれを含むシステム型で指定されるデータベースオブジェクトのコメントを返します。 たとえばobj_description(123456, 'pg_class')はOID 123456のテーブルのコメントを返します。

obj_description ( object oid ) → text

Returns the comment for a database object specified by its OID alone. This is <emphasis>deprecated</emphasis> since there is no guarantee that OIDs are unique across different system catalogs; therefore, the wrong comment might be returned. OIDだけで指定されるデータベースオブジェクトのコメントを返します。 これは廃止予定です。異なるシステムカタログに渡ってOIDが一意であるという保証はないからです。ですから、間違ったコメントが返されるかも知れません。

shobj_description ( object oid, catalog name ) → text

Returns the comment for a shared database object specified by its OID and the name of the containing system catalog. This is just like <function>obj_description</function> except that it is used for retrieving comments on shared objects (that is, databases, roles, and tablespaces). Some system catalogs are global to all databases within each cluster, and the descriptions for objects in them are stored globally as well. OIDとそれを含むシステム型で指定されるデータベース共有オブジェクトのコメントを返します。 これは共有オブジェクト(すなわちデータベース、ロール、テーブル空間)のコメントを取り出すために使うのを除くとobj_descriptionと同じです。 システムカタログによってはクラスタ内ですべてのデータベースに対して広域的で、その中のオブジェクトの説明も広域的に格納されています。


9.26.7. データ有効性検証関数 #

<title>Data Validity Checking Functions</title>

The functions shown in <xref linkend="functions-info-validity-table"/> can be helpful for checking validity of proposed input data. 表 9.79で示した関数は、与えられた入力データの有効性をチェックするのに役立ちます。

表9.79 データ有効性検証関数

<title>Data Validity Checking Functions</title>

Function 関数

Description 説明

Example(s)

pg_input_is_valid ( string text, type text ) → boolean

Tests whether the given <parameter>string</parameter> is valid input for the specified data type, returning true or false. 指定された文字列が指定されたデータ型に対して有効な入力かどうかをテストし、真または偽を返します。

This function will only work as desired if the data type's input function has been updated to report invalid input as a <quote>soft</quote> error. Otherwise, invalid input will abort the transaction, just as if the string had been cast to the type directly. この関数は、データ型の入力関数が無効な入力をソフトエラーとして報告するように更新されている場合にのみ、機能します。 そうでない場合、無効な入力は、文字列が直接その型にキャストされたかのように、トランザクションを中断します。

pg_input_is_valid('42', 'integer')t

pg_input_is_valid('42000000000', 'integer')f

pg_input_is_valid('1234.567', 'numeric(7,4)')f

pg_input_error_info ( string text, type text ) → record ( message text, detail text, hint text, sql_error_code text )

Tests whether the given <parameter>string</parameter> is valid input for the specified data type; if not, return the details of the error that would have been thrown. If the input is valid, the results are NULL. The inputs are the same as for <function>pg_input_is_valid</function>. 指定された文字列が指定されたデータタイプに対して有効な入力かどうかをテストします。 有効でない場合は、スローされたであろうエラーの詳細を結果します。 入力が有効な場合、結果はNULLになります。 入力はpg_input_is_validと同じです。

This function will only work as desired if the data type's input function has been updated to report invalid input as a <quote>soft</quote> error. Otherwise, invalid input will abort the transaction, just as if the string had been cast to the type directly. この関数は、データ型の入力関数が無効な入力をソフトエラーとして報告するように更新されている場合にのみ、機能します。 そうでない場合、無効な入力は、文字列が直接その型にキャストされたかのように、トランザクションを中断します。

select * from pg_input_error_info('42000000000', 'integer')

                       message                        | detail | hint | sql_error_code
------------------------------------------------------+--------+------+----------------
 value "42000000000" is out of range for type integer |        |      | 22003

select message, detail from pg_input_error_info('1234.567', 'numeric(7,4)')

        message         |                                      detail
------------------------+----------------------------------​-------------------------------------------------
 numeric field overflow | A field with precision 7, scale 4 must round to an absolute value less than 10^3.


9.26.8. トランザクションIDとスナップショット情報関数 #

<title>Transaction ID and Snapshot Information Functions</title>

The functions shown in <xref linkend="functions-pg-snapshot"/> provide server transaction information in an exportable form. The main use of these functions is to determine which transactions were committed between two snapshots. 表 9.80で示される関数はサーバトランザクション情報をエクスポートできる形式で提供します。 これら関数の主な使用目的は2つのスナップショット間でどのトランザクションがコミットされたのかを特定するためです。

表9.80 トランザクションIDとスナップショット情報関数

<title>Transaction ID and Snapshot Information Functions</title>

Function 関数

Description 説明

pg_current_xact_id () → xid8

Returns the current transaction's ID. It will assign a new one if the current transaction does not have one already (because it has not performed any database updates); see <xref linkend="transaction-id"/> for details. If executed in a subtransaction, this will return the top-level transaction ID; see <xref linkend="subxacts"/> for details. 現在のトランザクションのIDを返します。 現在トランザクションにIDがない場合(データベースの更新を実行していないため)、新しいIDが割り当てられます。 詳細は74.1を参照してください。 サブトランザクションで実行された場合、トップ-レベルトランザクションIDが返却されます。 詳細は74.3を参照してください。

pg_current_xact_id_if_assigned () → xid8

Returns the current transaction's ID, or <literal>NULL</literal> if no ID is assigned yet. (It's best to use this variant if the transaction might otherwise be read-only, to avoid unnecessary consumption of an XID.) If executed in a subtransaction, this will return the top-level transaction ID. 現在のトランザクションIDを返します。もしまだ割り当てられていなければNULLを返します。 (トランザクションが読み取り専用なら、無駄なXIDの消費を避けるためにこの関数を使うのが最良です。) サブトランザクションで実行された場合、トップ-レベルトランザクションIDが返却されます。

pg_xact_status ( xid8 ) → text

Reports the commit status of a recent transaction. The result is one of <literal>in progress</literal>, <literal>committed</literal>, or <literal>aborted</literal>, provided that the transaction is recent enough that the system retains the commit status of that transaction. If it is old enough that no references to the transaction survive in the system and the commit status information has been discarded, the result is <literal>NULL</literal>. Applications might use this function, for example, to determine whether their transaction committed or aborted after the application and database server become disconnected while a <literal>COMMIT</literal> is in progress. Note that prepared transactions are reported as <literal>in progress</literal>; applications must check <link linkend="view-pg-prepared-xacts"><structname>pg_prepared_xacts</structname></link> if they need to determine whether a transaction ID belongs to a prepared transaction. 最近のトランザクションのコミット状態について報告します。 トランザクションが最近のもので、システムがそのトランザクションのコミット状態を保持している場合は、トランザクションの状態はin progresscommittedあるいはabortedとして報告されます。 トランザクションが古く、その参照がシステムに残っておらず、コミット状態の情報が破棄されている場合は、この関数はNULLを返します。 COMMITの進行中にアプリケーションとデータベースが切断されたときに、アプリケーションはトランザクションがコミットされたか中断されたかを知るためにこれを使うことができます。 プリペアドのトランザクションはin progressとして報告されること、そして指定のIDがプリペアドのトランザクションかどうかを確認する必要がある場合は、アプリケーションはpg_prepared_xactsを調べなければならないことに注意してください。

pg_current_snapshot () → pg_snapshot

Returns a current <firstterm>snapshot</firstterm>, a data structure showing which transaction IDs are now in-progress. Only top-level transaction IDs are included in the snapshot; subtransaction IDs are not shown; see <xref linkend="subxacts"/> for details. どのトランザクションIDがin-progressなのかを表示するデータ構造である現在のsnapshotを返します。 スナップショットにはトップレベルのトランザクションIDだけが含まれます。 サブトランザクションIDは表示されません。詳細は74.3をご覧ください。

pg_snapshot_xip ( pg_snapshot ) → setof xid8

Returns the set of in-progress transaction IDs contained in a snapshot. スナップショットに含まれるin-progressのトランザクションIDの集合を返します。

pg_snapshot_xmax ( pg_snapshot ) → xid8

Returns the <structfield>xmax</structfield> of a snapshot. スナップショットのxmaxを返します。

pg_snapshot_xmin ( pg_snapshot ) → xid8

Returns the <structfield>xmin</structfield> of a snapshot. スナップショットのxminを返します。

pg_visible_in_snapshot ( xid8, pg_snapshot ) → boolean

Is the given transaction ID <firstterm>visible</firstterm> according to this snapshot (that is, was it completed before the snapshot was taken)? Note that this function will not give the correct answer for a subtransaction ID (subxid); see <xref linkend="subxacts"/> for details. このスナップショットによると与えられたトランザクションIDが可視か(すなわちスナップショットが取得される前に完了していたか)? この関数は副トランザクションID(subxid)に対しては正しい答えを返さないことに注意してください。 詳細は74.3を参照してください。


The internal transaction ID type <type>xid</type> is 32 bits wide and wraps around every 4 billion transactions. However, the functions shown in <xref linkend="functions-pg-snapshot"/> use a 64-bit type <type>xid8</type> that does not wrap around during the life of an installation and can be converted to <type>xid</type> by casting if required; see <xref linkend="transaction-id"/> for details. The data type <type>pg_snapshot</type> stores information about transaction ID visibility at a particular moment in time. Its components are described in <xref linkend="functions-pg-snapshot-parts"/>. <type>pg_snapshot</type>'s textual representation is <literal><replaceable>xmin</replaceable>:<replaceable>xmax</replaceable>:<replaceable>xip_list</replaceable></literal>. For example <literal>10:20:10,14,15</literal> means <literal>xmin=10, xmax=20, xip_list=10, 14, 15</literal>. 内部トランザクションID型(xid)は32ビット幅なので40億トランザクション毎にラップします。 とは言っても、表 9.80に示される関数はインストレーションの生涯にわたってラップしないxid8型の64ビット形式を使用しており、必要に応じてxidにキャストして変換できます。 詳細は74.1を参照してください。 これらの関数で使用されるデータ型、pg_snapshotはある特定の時間におけるトランザクションIDの可視性に関する情報を格納します。 構成要素は表 9.81に記載されています。 pg_snapshotのテキスト表現はxmin:xmax:xip_listです。 たとえば10:20:10,14,15xmin=10, xmax=20, xip_list=10, 14, 15であることを意味します。

表9.81 スナップショット構成要素

<title>Snapshot Components</title>
名前説明
xmin Lowest transaction ID that was still active. All transaction IDs less than <structfield>xmin</structfield> are either committed and visible, or rolled back and dead. 現在実行中で最も小さいトランザクションID。 xminより小さい全てのトランザクションはコミットされて可視となっているか、またはロールバックされて消滅しています。
xmax One past the highest completed transaction ID. All transaction IDs greater than or equal to <structfield>xmax</structfield> had not yet completed as of the time of the snapshot, and thus are invisible. 完了した最も大きなトランザクションIDの一つ大きなID。 xmaxと等しいかより大きい全てのトランザクションIDはスナップショットの時点で未完了であり、従って不可視です。
xip_list Transactions in progress at the time of the snapshot. A transaction ID that is <literal>xmin &lt;= <replaceable>X</replaceable> &lt; xmax</literal> and not in this list was already completed at the time of the snapshot, and thus is either visible or dead according to its commit status. This list does not include the transaction IDs of subtransactions (subxids). スナップショット時の実行中のトランザクションです。 xmin <= X <xmaxで、このリストにないトランザクションIDはスナップショット時点ですでに完了しており、コミット状態によって可視あるいはデッドのどちらかです。 リストには副トランザクションのトランザクションID(subxids)は含まれません。

In releases of <productname>PostgreSQL</productname> before 13 there was no <type>xid8</type> type, so variants of these functions were provided that used <type>bigint</type> to represent a 64-bit XID, with a correspondingly distinct snapshot data type <type>txid_snapshot</type>. These older functions have <literal>txid</literal> in their names. They are still supported for backward compatibility, but may be removed from a future release. See <xref linkend="functions-txid-snapshot"/>. PostgreSQLリリースの13より前ではxid8型がなく、これらの関数の変種は、64ビットのXIDを表現するためにbigintを、スナップショットデータ型に対応する別のtxid_snapshot型を使っていました。 これらの古い関数ではtxidが名前に含まれています。 過去互換性のためにこれらはまだサポートされていますが、将来のリリースでは削除されるかも知れません。 表 9.82を参照してください。

表9.82 廃止予定のトランザクションIDとスナップショット情報関数

<title>Deprecated Transaction ID and Snapshot Information Functions</title>

Function 関数

Description 説明

txid_current () → bigint

See <function>pg_current_xact_id()</function>. pg_current_xact_id()参照。

txid_current_if_assigned () → bigint

See <function>pg_current_xact_id_if_assigned()</function>. pg_current_xact_id_if_assigned()参照。

txid_current_snapshot () → txid_snapshot

See <function>pg_current_snapshot()</function>. pg_current_snapshot()参照。

txid_snapshot_xip ( txid_snapshot ) → setof bigint

See <function>pg_snapshot_xip()</function>. pg_snapshot_xip()参照。

txid_snapshot_xmax ( txid_snapshot ) → bigint

See <function>pg_snapshot_xmax()</function>. pg_snapshot_xmax()参照。

txid_snapshot_xmin ( txid_snapshot ) → bigint

See <function>pg_snapshot_xmin()</function>. pg_snapshot_xmin()参照。

txid_visible_in_snapshot ( bigint, txid_snapshot ) → boolean

See <function>pg_visible_in_snapshot()</function>. pg_visible_in_snapshot()参照。

txid_status ( bigint ) → text

See <function>pg_xact_status()</function>. pg_xact_status()参照。


9.26.9. コミット済みトランザクション情報関数 #

<title>Committed Transaction Information Functions</title>

The functions shown in <xref linkend="functions-commit-timestamp"/> provide information about when past transactions were committed. They only provide useful data when the <xref linkend="guc-track-commit-timestamp"/> configuration option is enabled, and only for transactions that were committed after it was enabled. 表 9.83に示す関数はいつ過去のトランザクションがコミットされたかの情報を提供します。 track_commit_timestamp設定オプションが有効のときにだけ、かつそれが有効になった後にコミットされたトランザクションについてのみ意味のある情報を提供します。

表9.83 コミットされたトランザクションに関する情報関数

<title>Committed Transaction Information Functions</title>

Function 関数

Description 説明

pg_xact_commit_timestamp ( xid ) → timestamp with time zone

Returns the commit timestamp of a transaction. トランザクションのコミットタイムスタンプを返します。

pg_xact_commit_timestamp_origin ( xid ) → record ( timestamp timestamp with time zone, roident oid)

Returns the commit timestamp and replication origin of a transaction. トランザクションのコミットタイムスタンプとレプリケーション原点を返します。

pg_last_committed_xact () → record ( xid xid, timestamp timestamp with time zone, roident oid )

Returns the transaction ID, commit timestamp and replication origin of the latest committed transaction. 直近にコミットしたトランザクションのトランザクションID、コミットタイムスタンプ、レプリケーション原点を返します。


9.26.10. コントロールデータ関数 #

<title>Control Data Functions</title>

The functions shown in <xref linkend="functions-controldata"/> print information initialized during <command>initdb</command>, such as the catalog version. They also show information about write-ahead logging and checkpoint processing. This information is cluster-wide, not specific to any one database. These functions provide most of the same information, from the same source, as the <xref linkend="app-pgcontroldata"/> application. 表 9.84に示す関数は、カタログのバージョンなどといったinitdbの実行時に初期化される情報を表示します。 それらはまた、先行書き込みログとチェックポイント処理についての情報も示します。 この情報はクラスタ全体に渡るもので、どれか1つのデータベースに特有のものではありません。 これらの関数はpg_controldataアプリケーションと同じ情報源から、ほぼ同じ情報を提供します。

表9.84 制御データ関数

<title>Control Data Functions</title>

Function 関数

Description 説明

pg_control_checkpoint () → record

Returns information about current checkpoint state, as shown in <xref linkend="functions-pg-control-checkpoint"/>. 表 9.85に示すように現在のチェックポイントの状態に関する情報を返します。

pg_control_system () → record

Returns information about current control file state, as shown in <xref linkend="functions-pg-control-system"/>. 表 9.86に示すように現在の制御ファイルの状態に関する情報を返します。

pg_control_init () → record

Returns information about cluster initialization state, as shown in <xref linkend="functions-pg-control-init"/>. 表 9.87に示すようにクラスタの初期化状態に関する情報を返します。

pg_control_recovery () → record

Returns information about recovery state, as shown in <xref linkend="functions-pg-control-recovery"/>. 表 9.88に示すようにリカバリ状態に関する情報を返します。


表9.85 pg_control_checkpointの出力列

<title><function>pg_control_checkpoint</function> Output Columns</title>
列名データ型
checkpoint_lsnpg_lsn
redo_lsnpg_lsn
redo_wal_filetext
timeline_idinteger
prev_timeline_idinteger
full_page_writesboolean
next_xidtext
next_oidoid
next_multixact_idxid
next_multi_offsetxid
oldest_xidxid
oldest_xid_dbidoid
oldest_active_xidxid
oldest_multi_xidxid
oldest_multi_dbidoid
oldest_commit_ts_xidxid
newest_commit_ts_xidxid
checkpoint_timetimestamp with time zone

表9.86 pg_control_systemの出力列

<title><function>pg_control_system</function> Output Columns</title>
列名データ型
pg_control_versioninteger
catalog_version_nointeger
system_identifierbigint
pg_control_last_modifiedtimestamp with time zone

表9.87 pg_control_init Output Columns

列名データ型
max_data_alignmentinteger
database_block_sizeinteger
blocks_per_segmentinteger
wal_block_sizeinteger
bytes_per_wal_segmentinteger
max_identifier_lengthinteger
max_index_columnsinteger
max_toast_chunk_sizeinteger
large_object_chunk_sizeinteger
float8_pass_by_valueboolean
data_page_checksum_versioninteger

表9.88 pg_control_recoveryの出力列

<title><function>pg_control_recovery</function> Output Columns</title>
列名データ型
min_recovery_end_lsnpg_lsn
min_recovery_end_timelineinteger
backup_start_lsnpg_lsn
backup_end_lsnpg_lsn
end_of_backup_record_requiredboolean