PC/NETのetcetra/2004-10-08

Last-modified: 2005-09-17 (土) 19:51:05 (6793d)
※※このサイトは2012年頃より更新を停止しています。※※

postgreSQL

  • TIMESTAMP型の扱い
    参考:http://osb.sra.co.jp/PostgreSQL/Manual/PostgreSQL-7.1-ja/functions-datetime.html
    postgreSQLのTIMESTAMP型のデータって、読み出したり書き込んだりするときは文字列として扱わないといけないっぽいのに、読み出した後の値は数値として比較演算できるんだね?
    こんなtable "test"があるとして
     Column  |           Type           | Modifiers
    ---------+--------------------------+-----------
    uid      | character varying(40)    | not null
    q1       | smallint                 |
    q2       | smallint                 |
    created  | timestamp with time zone | not null
    modified | timestamp with time zone |
    Primary key: test_pkey
    こいつからcreatedが2004-09-25以前のデータを抜き出したい場合
    select * from test where created < '2004-09-25';
    で抽出できた。
    数値扱いできんのか(ノд`)
    ちなみに、EXTRACT関数のepochって値を利用して、MySQLで言うUNIX_TIMESTAMPっぽい出力ができるもよう。
    select extract(epoch from timestamp '2004-09-25');
    こりゃー便利だから覚えておこう。

コメントはありません。 コメント/PC/NETのetcetra/2004-10-08

トップ   差分 バックアップ リロード   一覧 単語検索 最終更新   ヘルプ   最終更新のRSS