我是 Postgres 的新手,正在metrics_reaches
使用 pgAdmin III 创建一个表 ( )。
在我的表中,我有一个带有 timezome类型列insertion_timestamp
的时间戳。
我想创建一个UNIQUE
约束,在其他字段中,只检查日期部分insertion_timestamp
而不是时间。
有没有办法做到这一点?这是我的脚本目前的样子(见最后一个CONSTRAINT
)。
-- Table: metrics_reaches
-- DROP TABLE metrics_reaches;
CREATE TABLE metrics_reaches
(
organizations_id integer NOT NULL,
applications_id integer NOT NULL,
countries_id integer NOT NULL,
platforms_id integer NOT NULL,
...
insertion_timestamp timestamp with time zone NOT NULL,
id serial NOT NULL,
CONSTRAINT metrics_reaches_pkey PRIMARY KEY (id),
CONSTRAINT metrics_reaches_applications_id_fkey FOREIGN KEY (applications_id)
REFERENCES applications (id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE,
CONSTRAINT metrics_reaches_countries_id_fkey FOREIGN KEY (countries_id)
REFERENCES countries (id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE,
CONSTRAINT metrics_reaches_organizations_id_fkey FOREIGN KEY (organizations_id)
REFERENCES organizations (id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE,
CONSTRAINT metrics_reaches_platforms_id_fkey FOREIGN KEY (platforms_id)
REFERENCES platforms (id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE,
CONSTRAINT metrics_reaches_organizations_id_key UNIQUE (organizations_id, applications_id, countries_id, platforms_id, insertion_timestamp)
)
WITH (
OIDS=FALSE
);
ALTER TABLE metrics_reaches
OWNER TO postgres;