0
0

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.

Redshiftチートシート

Last updated at Posted at 2022-03-19

背景・目的

忘れぽいため、RedshiftのコマンドやSQL等をまとめておく。

内容

psqlで接続する。

psql -h {エンドポイント名} -p {ポート番号} -U {ユーザ名} -d {データベース名}

psqlを終了する。

# \q

データベース作成

CREATE DATABASE {DB名} WITH OWNER = {ユーザ名}

COPY

copy users from 's3://{バケット名}/tickit/allusers_pipe.txt' 
iam_role 'arn:aws:iam::{アカウントID}:role/{ロール名}';
delimiter '|' region 'ap-northeast-1';

UNLOAD

unload ('select * from venue')
to 's3://{バケット名}/unload/venue/' 
iam_role 'arn:aws:iam::{アカウントID}:role/{ロール名}';

Viewを参照しているテーブルを確認する

SELECT *
(
select distinct c_p.oid as tbloid,
n_p.nspname as schemaname, c_p.relname as name,
n_c.nspname as refbyschemaname, c_c.relname as refbyname,
c_c.oid as viewoid
from pg_catalog.pg_class c_p
join pg_catalog.pg_depend d_p
on c_p.relfilenode = d_p.refobjid
join pg_catalog.pg_depend d_c
on d_p.objid = d_c.objid
join pg_catalog.pg_class c_c
on d_c.refobjid = c_c.relfilenode
left outer join pg_namespace n_p
on c_p.relnamespace = n_p.oid
left outer join pg_namespace n_c
on c_c.relnamespace = n_c.oid
where d_c.deptype = 'i'::"char"
and c_c.relkind = 'v'::"char";
) WHERE refbyschemaname ={テーブル名}

その他

  • 随時更新する予定です。
0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?