2021年1月10日日曜日

Postgress(copyクエリ利用)

 以下、クエリになる。

---------------------------------------------------------------------

#!/bin/bash


DBNAME="dvdrental" # 接続するデータベース名

HOST="database-pg1.cksctvztkm5v.ap-northeast-1.rds.amazonaws.com"

tables=("actor")

day=$(date "+%m%d%Y%H%M")


# postgresqlでcopy出力

psql -U postgres -h $HOST -d $DBNAME -c "\COPY (select * from $tables where last_update::date = date 'now') TO '/tmp/$day"_""$tables".csv' WITH CSV DELIMITER ','"

----------------------------------------------------------------------



参照先:

https://docs.aws.amazon.com/ja_jp/AmazonRDS/latest/AuroraUserGuide/postgresql-s3-export.html


0 件のコメント:

コメントを投稿

AIツール断捨離の果てに

  導入 ハード環境 : Mac Studio M4 Maxの導入。 背景 : 以前から使い倒してきたITエンジニアとして、話題のAIツール(Cursor, Zed, Void, Continue, Roo Codeなど)を片っ端から実戦投入してみたこと。 目的 : ツールをいじ...