はじめに
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;