LoginSignup
2
1

More than 5 years have passed since last update.

redshiftでCREATE TEMP TABLE LIKEして作成したテーブルに、default 0が付かない?

Last updated at Posted at 2016-10-14

現象を確認したが、謎。
CREATE TABLE LIKEでも同様。

create temp table hoge_test(
app_id int,
hoge int DEFAULT 0
);

\d hoge_test
   列   |   型    |  修飾語
--------+---------+-----------
 app_id | integer |
 hoge   | integer | default 0


CREATE TEMP TABLE moge_test(like hoge_test);
\d moge_test
   列   |   型    | 修飾語
--------+---------+--------
 app_id | integer |
 hoge   | integer |

と思ったら、postgresqlのリファレンスに書いてありました。
INCLUDING DEFAULTSをつけないとデフォルト式はスルーされるみたい。
https://www.postgresql.jp/document/8.0/html/sql-createtable.html

CREATE TEMP TABLE hogehoge_test(like hoge_test INCLUDING DEFAULTS);

\d hogehoge_test
   列   |   型    |  修飾語
--------+---------+-----------
 app_id | integer |
 hoge   | integer | default 0

今度はうまく行ったみたい。
この辺、知ってないと危険が大きい。

2
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
2
1