LoginSignup
5
1

More than 3 years have passed since last update.

Redshiftでのビュー定義の確認方法

Posted at

はじめに

Amazon Redshift や PostgreSQLで、このビューってどんなSQLで定義されていたっけ?
と調べる際に、もはや惰性的に

select * from pg_views where viewname = 'ビュー名';

と打ち込んでいましたが、簡単に参照する方法がありました。

結論

\d+ ビュー名

これだけ、、、作業時間が少し短縮された気がします。。。

確認

--テーブル1
CREATE TABLE book (
 bookid SMALLINT
,shopid SMALLINT
,bookname VARCHAR(32)
)
;

--テーブル2
CREATE TABLE bookshop (
 shopid SMALLINT
,shopname VARCHAR(32)
)
;

--ビュー
CREATE VIEW bookview as 
select
a.bookid,a.shopid,a.bookname,b.shopname
from
book a,bookshop b where a.shopid = b.shopid
;

=> \d+ bookview
                  ビュー "public.bookview"
        |                     | 修飾語 | ストレージ | 説明
----------+-----------------------+--------+------------+------
 bookid   | smallint              |        | plain      |
 shopid   | smallint              |        | plain      |
 bookname | character varying(32) |        | extended   |
 shopname | character varying(32) |        | extended   |
ビュー定義:
 SELECT a.bookid, a.shopid, a.bookname, b.shopname
   FROM book a, bookshop b
  WHERE a.shopid = b.shopid;
5
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
5
1