0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

PostgreSQL: スキーマにコメントをつける

Last updated at Posted at 2024-05-07

環境

ユーザー scott
データベース city

city というデータベースに、city というスキーマを作成します。

コメントの付加

set_comment.sql
comment on schema city is '都市名';

実行コマンド

psql -U scott city < set_comment.sql

コメントの確認

get_comment.sql
SELECT n.nspname AS schema_name, d.description
FROM pg_catalog.pg_namespace n
LEFT JOIN pg_catalog.pg_description d ON d.objoid = n.oid AND d.objsubid = 0;

実行コマンド

psql -U scott city < get_comment.sql

実行結果

$ psql -U scott city < get_comment.sql
    schema_name     |           description            
--------------------+----------------------------------
 pg_toast           | reserved schema for TOAST tables
 pg_catalog         | system catalog schema
 public             | standard public schema
 information_schema | 
 city               | 都市名
(5 rows)

別の確認方法

$ psql -U scott city
psql (16.2 (Ubuntu 16.2-1ubuntu4), server 14.8 (Ubuntu 14.8-0ubuntu0.22.10.1))
Type "help" for help.

city=# select  * from pg_description where objoid = (SELECT oid FROM pg_catalog.pg_namespace WHERE nspname = 'city');
 objoid | classoid | objsubid | description 
--------+----------+----------+-------------
  93405 |     2615 |        0 | 都市名
(1 row)

city=#
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?