PostgreSQL
について
| timestamp [ (p) ] without time zone | |
| timestamp [ (p) ] [ with time zone ] |
| timestamp 型の Field の作成 | |
beniya=# create table timstp( tmsp timestamp);
CREATE
beniya-# select \d timstp;
Table "timstp"
Column | Type | Modifiers
--------+--------------------------+-----------
tmsp | timestamp with time zone |
|
なにもつけないで timestamp 型 で項目を作成すると
timestamp with time zone となっている。
7.4. 系では反対に with out time Zone になるらしい。
|
beniya-# create table timstp0( tmsp timestamp[0]);
CREATE
beniya=# select \d timstp0;
Table "timstp0"
Column | Type | Modifiers
--------+----------------------------+-----------
tmsp | timestamp with time zone[] |
|
これは全然違う!! 配列になっている。 配列について調べると |
beniya-# create table timstp1( tmsp timestamp[1]);
ERROR: parser: parse error at or near "table"
beniya=# create table timstp1( tmsp timestamp[1]);
CREATE
beniya=# select \d timstp1;
Table "timstp1"
Column | Type | Modifiers
--------+----------------------------+-----------
tmsp | timestamp with time zone[] |
|
| beniya=# select tmsp from timstp; tmsp ------------------------------- 2004-12-26 14:43:50.714774+09 2004-12-26 15:01:06.12685+09 2004-12-26 15:56:44.8268+09 2004-12-26 00:00:15.9201+09 2004-12-26 00:01:34.2544+09 2004-12-26 19:02:15.378+09 (6 rows) |
| beniya=# select to_char( now(),'HH12:MI:SS'); to_char ---------- 06:01:03 (1 row) beniya=# select to_char( now(),'HH24:MI:SS'); to_char ---------- 18:01:10 (1 row) beniya=# select to_char( tmsp,'HH24:MI:SS') from timstp; to_char ---------- 14:43:50 15:01:06 15:56:44 00:00:15 00:01:34 19:02:15 (6 rows) beniya=# select to_char( tmsp,'YYYY HH24:MI:SS') from timstp; to_char --------------- 2004 14:43:50 2004 15:01:06 2004 15:56:44 2004 00:00:15 2004 00:01:34 2004 19:02:15 (6 rows) beniya=# select to_char( tmsp,'YYYY/MM HH24:MI:SS') from timstp; to_char ------------------ 2004/12 14:43:50 2004/12 15:01:06 2004/12 15:56:44 2004/12 00:00:15 2004/12 00:01:34 2004/12 19:02:15 (6 rows) beniya=# select to_char( tmsp,'YYYY/MM/dd HH24:MI:SS') from timstp; to_char --------------------- 2004/12/26 14:43:50 2004/12/26 15:01:06 2004/12/26 15:56:44 2004/12/26 00:00:15 2004/12/26 00:01:34 2004/12/26 19:02:15 (6 rows) beniya=# select to_char( tmsp,'YYYY/MM/dd- HH24:MI:SS') from timstp; to_char ---------------------- 2004/12/26- 14:43:50 2004/12/26- 15:01:06 2004/12/26- 15:56:44 2004/12/26- 00:00:15 2004/12/26- 00:01:34 2004/12/26- 19:02:15 (6 rows) beniya=# select * from timstp; tmsp ------------------------------- 2004-12-26 14:43:50.714774+09 2004-12-26 15:01:06.12685+09 2004-12-26 15:56:44.8268+09 2004-12-26 00:00:15.9201+09 2004-12-26 00:01:34.2544+09 2004-12-26 19:02:15.378+09 (6 rows )beniya=# select to_char( tmsp,'YYYY/MM/dd- HH24:MI:SS:MS') from timstp; to_char -------------------------- 2004/12/26- 14:43:50:715 2004/12/26- 15:01:06:127 2004/12/26- 15:56:44:827 2004/12/26- 00:00:15:920 2004/12/26- 00:01:34:254 2004/12/26- 19:02:15:378 (6 rows) beniya=# select to_char( tmsp,'YYYY/MM/dd- HH24:MI:SS:MS TZ') from timstp; to_char ------------------------------- 2004/12/26- 14:43:50:715 JST 2004/12/26- 15:01:06:127 JST 2004/12/26- 15:56:44:827 JST 2004/12/26- 00:00:15:920 JST 2004/12/26- 00:01:34:254 JST 2004/12/26- 19:02:15:378 JST (6 rows) |
まず現在時間を HH12:MI:SS だけで表示する。 24時間表示 HH24 としてみる。 そしてこれがテーブルの内容をフォーマットして出力出来るか? のテスト これでいけるようです。 YYYY を入れて年を表示 月 0-12 で表示 年月日と時間 オリジナルのデーターを表示 MS(ミリセコンドの表示)も付けて見る。 最後尾は 四捨五入されているようです。 ほほう 時間帯も 表示出来るようです。 |
Last Update 2004/12/27 18:13 JST