Created
July 1, 2014 05:48
-
-
Save a-suenami/32665e688d7b16e576fe to your computer and use it in GitHub Desktop.
PostgreSQL の timestamp with time zone の等価判定について ref: http://qiita.com/a-suenami/items/dea19256f6ec672d67f1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
postgres=# CREATE TABLE orders ( product_id integer, ordered_at timestamp with time zone, CONSTRAINT pkey PRIMARY KEY (product_id, ordered_at) ) ; | |
CREATE TABLE | |
postgres=# \d orders | |
Table "public.orders" | |
Column | Type | Modifiers | |
------------+--------------------------+----------- | |
product_id | integer | not null | |
ordered_at | timestamp with time zone | not null | |
Indexes: | |
"pkey" PRIMARY KEY, btree (product_id, ordered_at) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
postgres=# INSERT INTO orders (product_id, ordered_at) VALUES (1, '2014-07-01 14:00:00') ; | |
INSERT 0 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
postgres=# SELECT product_id, ordered_at FROM orders ; | |
product_id | ordered_at | |
------------+------------------------ | |
1 | 2014-07-01 14:00:00+09 | |
(1 row) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
postgres=# INSERT INTO orders (product_id, ordered_at) VALUES (1, '2014-07-01 14:00:00 UTC') ; | |
INSERT 0 1 | |
postgres=# SELECT product_id, ordered_at FROM orders ; | |
product_id | ordered_at | |
------------+------------------------ | |
1 | 2014-07-01 14:00:00+09 | |
1 | 2014-07-01 23:00:00+09 | |
(2 rows) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
postgres=# INSERT INTO orders (product_id, ordered_at) VALUES (1, '2014-07-01 05:00:00 UTC') ; | |
ERROR: duplicate key value violates unique constraint "pkey" | |
DETAIL: Key (product_id, ordered_at)=(1, 2014-07-01 14:00:00+09) already exists. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment