PostgreSQL で時間の差を取って返す

2007-4-21 00:55
このエントリーをはてなブックマークに追加

PostgreSQL は時間が柔軟に扱えるので SQL だけでロジックを済ませられることも多く便利な点の一つです。

たとえば timestamp with time zone 型の last_access_time に最終アクセス日が格納されているとして、現在より1時間以内にアクセスしたデータを取り出すときは

  SELECT * FROM tablename WHERE now() - last_access_time < '01:00';

とすれば OK です。5分であれば、

  SELECT * FROM tablename WHERE now() - last_access_time < '5 minutes';

のような指定もできます。1週間であれば、

  SELECT * FROM tablename WHERE now() - last_access_time < '1 week';

のようにも指定できますし、 7 days にしても OK です。

  • ブックマーク :
    Warning: Use of undefined constant SBM_count_get - assumed 'SBM_count_get' (this will throw an Error in a future version of PHP) in /var/www/futuremix.org/wp-content/themes/futuremix/index.php on line 40

    Warning: Use of undefined constant show_post_count - assumed 'show_post_count' (this will throw an Error in a future version of PHP) in /var/www/futuremix.org/wp-content/themes/futuremix/index.php on line 40
    アクセス: 16,666回
  • カテゴリー : データベース
  • キーワード :

コメントはまだありません

No comments yet.

Sorry, the comment form is closed at this time.

69 queries. HTML convert time: 1.098 sec. Powered by WordPress. Valid XHTML
Copyright © 2003-2017 @ futuremix.org ログイン