

 Amazon Redshift は、パッチ 198 以降、新しい Python UDF の作成をサポートしなくなります。既存の Python UDF は、2026 年 6 月 30 日まで引き続き機能します。詳細については、[ブログ記事](https://aws.amazon.com/blogs/big-data/amazon-redshift-python-user-defined-functions-will-reach-end-of-support-after-june-30-2026/)を参照してください。

# PG\_TABLE\_DEF
<a name="r_PG_TABLE_DEF"></a>

テーブルの列に関する情報を格納します。

PG\_TABLE\_DEF は、テーブルに関してユーザーに表示される情報のみを返します。もし PG\_TABLE\_DEF が予期した結果を返さない場合、該当のスキーマを含むように [search\_path](r_search_path.md) パラメータが正しく設定されていることを確認します。

[SVV\_TABLE\_INFO](r_SVV_TABLE_INFO.md) を使用すると、データ分散スキュー、キー分散スキュー、テーブルサイズ、統計情報など、テーブルに関するより包括的な情報を表示することができます。

## テーブルの列
<a name="r_PG_TABLE_DEF-table-columns2"></a>


| 列名  | データ型  | 説明  | 
| --- | --- | --- | 
| schemaname | name | スキーマ名。 | 
| tablename | name | テーブル名。 | 
| column | name  | 列名。 | 
| type  | text | 列のデータ型。 | 
| encoding  | character(32)  | 列のエンコード。 | 
| distkey  | boolean | この列がテーブルの分散キーである場合は True。 | 
| sortkey | integer  | ソートキーの列の順序。テーブルが複合ソートキーを使用する場合、ソートキーに含まれるすべての列は、ソートキー内の列の位置を示す正の値を持ちます。テーブルがインターリーブソートキーを使用する場合、ソートキーに含まれる各列は正または負の値を交互に持ち、この値の絶対値がソートキー内の列の位置を示します。0 の場合、列はソートキーに含まれません。 | 
| notnull | boolean  | 列が NOT NULL 制約を持つ場合は True。 | 

## 例
<a name="r_PG_TABLE_DEF-example2"></a>

次に、LINEORDER\_COMPOUND テーブルの複合ソートキーの列の例を示します。

```
select "column", type, encoding, distkey, sortkey, "notnull" 
from pg_table_def
where tablename = 'lineorder_compound' 
and sortkey <> 0;

column       | type    | encoding | distkey | sortkey | notnull
-------------+---------+----------+---------+---------+--------
lo_orderkey  | integer | delta32k | false   |       1 | true   
lo_custkey   | integer | none     | false   |       2 | true   
lo_partkey   | integer | none     | true    |       3 | true   
lo_suppkey   | integer | delta32k | false   |       4 | true   
lo_orderdate | integer | delta    | false   |       5 | true   
(5 rows)
```

 次に、LINEORDER\_INTERLEAVED テーブルのインターリーブソートキーの列の例を示します。

```
select "column", type, encoding, distkey, sortkey, "notnull" 
from pg_table_def
where tablename = 'lineorder_interleaved' 
and sortkey <> 0;

column       | type    | encoding | distkey | sortkey | notnull
-------------+---------+----------+---------+---------+--------
lo_orderkey  | integer | delta32k | false   |      -1 | true   
lo_custkey   | integer | none     | false   |       2 | true   
lo_partkey   | integer | none     | true    |      -3 | true   
lo_suppkey   | integer | delta32k | false   |       4 | true   
lo_orderdate | integer | delta    | false   |      -5 | true   
(5 rows)
```

PG\_TABLE\_DEF は、検索パスに含まれているスキーマのテーブルの情報のみを返します。詳細については、「[search\_path](r_search_path.md)」を参照してください

例えば、新しいスキーマと新しいテーブルを作成し、PG\_TABLE\_DEF にクエリを実行するとします。

```
create schema demo;
create table demo.demotable (one int);
select * from pg_table_def where tablename = 'demotable';

schemaname|tablename|column| type | encoding | distkey | sortkey | notnull 
----------+---------+------+------+----------+---------+---------+--------
```

このクエリは、新しいテーブルの列を返しません。`search_path` の設定を検証します。

```
show search_path;

  search_path
---------------
 $user, public
(1 row)
```

`demo` スキーマを検索パスに追加し、クエリを再度実行します。

```
set search_path to '$user', 'public', 'demo';

select * from pg_table_def where tablename = 'demotable';

schemaname| tablename |column|  type   | encoding |distkey|sortkey| notnull
----------+-----------+------+---------+----------+-------+-------+--------
demo      | demotable | one  | integer | none     | f     |     0 | f
(1 row)
```