Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m47o7-0005Wk-IW for pgsql-admin@arkaria.postgresql.org; Thu, 15 Jul 2021 20:18:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m47o6-0005uR-Ej for pgsql-admin@arkaria.postgresql.org; Thu, 15 Jul 2021 20:18:06 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m47o6-0005uJ-5U for pgsql-admin@lists.postgresql.org; Thu, 15 Jul 2021 20:18:06 +0000 Received: from jakobs.com ([85.214.83.89] helo=rs.plausibolo.de) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m47o2-00035L-Er for pgsql-admin@lists.postgresql.org; Thu, 15 Jul 2021 20:18:05 +0000 Received: from localhost (localhost [127.0.0.1]) by rs.plausibolo.de (Postfix) with ESMTP id 3E7AF3804D5; Thu, 15 Jul 2021 22:18:00 +0200 (CEST) Received: from rs.plausibolo.de ([127.0.0.1]) by localhost (h2367442.stratoserver.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id UWdGtuiF4lFK; Thu, 15 Jul 2021 22:18:00 +0200 (CEST) Received: from [10.243.178.13] (dynamic-002-247-242-013.2.247.pool.telefonica.de [2.247.242.13]) by rs.plausibolo.de (Postfix) with ESMTPSA id D7695380398; Thu, 15 Jul 2021 22:17:59 +0200 (CEST) Date: Thu, 15 Jul 2021 22:17:56 +0200 User-Agent: K-9 Mail for Android In-Reply-To: References: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----F31K14VBZY27HDMKWUTVRFPFSPQMX8" Content-Transfer-Encoding: 7bit Subject: Re: Partitioning on the date part of a timestamp & PK issues To: pgsql-admin@lists.postgresql.org From: Holger Jakobs Message-ID: <4C13EFB8-F25D-4361-817B-DA997FB15912@jakobs.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ------F31K14VBZY27HDMKWUTVRFPFSPQMX8 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Am 15=2E Juli 2021 22:10:01 MESZ schrieb Wells Oliver : >I have a table like so: > >CREATE TABLE t ( > guid uuid not null, > seq smallint not null, > tid smallint not null, > ts timestamp without time zone not null, > x real, > y real, > z real, > primary key (guid, tid, seq) >) partition by range (extract(date from ts)); > >Which results in the error: > >ERROR: unsupported PRIMARY KEY constraint with partition key >definition >DETAIL: PRIMARY KEY constraints cannot be used when partition keys >include >expressions=2E > >Is there a suitable way to get around this? I can make an additional >date >col in the table to use for the partition range, but given the amount >of >data we will have, I am trying to be cognizant of storage concerns=2E > >The PK is the PK, so I'm not sure what options I have there=2E > >Thanks=2E > >--=20 >Wells Oliver >wells=2Eoliver@gmail=2Ecom --=20 Maybe you could sister separate date and time and use date as partition ke= y=2E The timestamp column could be generated in a view as datecol + timecol= =2E If new data is entered, it could be separated into the two columns via tri= gger=2E Haven't tried it, bit seems feasible=2E Regards, Holger -- Holger Jakobs, Bergisch Gladbach +49 178 9759012 - sent from mobile, therefore short - ------F31K14VBZY27HDMKWUTVRFPFSPQMX8 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable

Am 15=2E Juli 2= 021 22:10:01 MESZ schrieb Wells Oliver <wells=2Eoliver@gmail=2Ecom>:<= blockquote class=3D"gmail_quote" style=3D"margin: 0pt 0pt 0pt 0=2E8ex; bord= er-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
I have a table like so:

CREATE TABLE t= (
    guid uuid not null,
    seq smallint not n= ull,
    tid smallint not null,
    ts timestamp = without time zone not null,
    x real,
    y rea= l,
    z real,
    primary key (guid, tid, seq)) partition by range (extract(date from ts));

Wh= ich results in the error:

ERROR:  unsupported= PRIMARY KEY constraint with partition key definition
DETAIL:  PRIM= ARY KEY constraints cannot be used when partition keys include expressions= =2E

Is there a suitable way to get around this?= I can make an additional date col in the table to use for the partition ra= nge, but given the amount of data we will have, I am trying to be cognizant= of storage concerns=2E

The PK is the PK, so I'm n= ot sure what options I have there=2E

Thanks=2E

--

--
Maybe you could sister separate date and tim= e and use date as partition key=2E The timestamp column could be generated = in a view as datecol + timecol=2E

If new data is entered, it could b= e separated into the two columns via trigger=2E

Haven't tried it, bi= t seems feasible=2E

Regards,
Holger

--
Holger Jakobs, B= ergisch Gladbach
+49 178 9759012
- sent from mobile, therefore short = -
------F31K14VBZY27HDMKWUTVRFPFSPQMX8--