Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hGtNB-0000cT-14 for pgsql-general@arkaria.postgresql.org; Wed, 17 Apr 2019 22:49:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hGtN9-0005vD-El for pgsql-general@arkaria.postgresql.org; Wed, 17 Apr 2019 22:49:43 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hGtN8-0005v6-WE for pgsql-general@lists.postgresql.org; Wed, 17 Apr 2019 22:49:43 +0000 Received: from mail-qt1-x841.google.com ([2607:f8b0:4864:20::841]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hGtN6-0006wq-AK for pgsql-general@lists.postgresql.org; Wed, 17 Apr 2019 22:49:41 +0000 Received: by mail-qt1-x841.google.com with SMTP id w5so163592qtb.11 for ; Wed, 17 Apr 2019 15:49:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=+Z9WgQWEl0KoGv2hMIKWxhb6aPonbZUnNg6jU5/6M3Y=; b=P4mC5b/xqSeyYWmDV7ZMoiTl4vGHlDpsi3E9aE2Ws/tyV+28HRVV0pIyATv1aNRnWB TaPlUCtLzoeFbB/B66YpVdsjCcfag3nddMnVmaGoZf4e9m807YeOdCSIfWvpEk9cr9Xv t++hF3xI7CiDtA2XIr+F1T4q7AqHUJddFyhoWh5u+NY8up+sxLHTn+jaWMClOENvYGun 8TKXKjHFUHBg05J/wSXN6R1L0ZMNF6+/SVj+ffvEOXHpHjTEKp6Z/y+f6mr0TZC6Q0km HiLpFduwyhH9eO1/qBb0Z/Iyv43+6FEk31CNKSmRp7DUrviM0opuFUWi6jKXSglvq3ov ssLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=+Z9WgQWEl0KoGv2hMIKWxhb6aPonbZUnNg6jU5/6M3Y=; b=imCq3xXL1UU/yKp2Q1HOybc3UJxOmnx/uh0++6KegfHOEZ3HJvhC/mq5RMU+mG6LmJ dfURi8nZzU1d5xTgGn5SnzonnQbPwtdpGFGzEYvuzdxp9Fhs5Can3r6FZzvi5XU5uGxe DAhouPugQQencuCyMCMw0ahgG3xm4Uj8QXl8CmHGGSYuviSTOnTsvdERCKfRuNyzgfZl FeViIu3kXKFKcUlumW1q4kqivoYFfKdZbHJgFOVgIJMEIfEv0iSZKd8X+Hse1h/5ZKS3 R+l9V7NOSdfh5Jv1MjZ0KjbLuNGlwB7a9vmj0YpqtNng2YqFglbAtWv0z5NnhFg7ozyW GBXQ== X-Gm-Message-State: APjAAAV0krr12rF4zWr2/PY/0O1W/mcdkMrVDtqy8NjXdAQgVviH5uEj 0Cge79lOx6iHfQO6r9PKMavyWE3U6eObCDGYsLRzKQ== X-Google-Smtp-Source: APXvYqyXInULGhx/sIHHCH/Wxv7Y5pzJ/jiXghPdFSK/3+h0R8vpoX53VPNi/daQthv7sWVFssty0ZTdC4cZ4Umdzgk= X-Received: by 2002:ac8:2f96:: with SMTP id l22mr74806480qta.258.1555541379183; Wed, 17 Apr 2019 15:49:39 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: pabloa98 Date: Wed, 17 Apr 2019 15:49:27 -0700 Message-ID: Subject: Re: is it possible to create partitioned tables using tables from different schemas To: Adrian Klaver Cc: pgsql-general@lists.postgresql.org Content-Type: multipart/alternative; boundary="00000000000056f9eb0586c1b3c1" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --00000000000056f9eb0586c1b3c1 Content-Type: text/plain; charset="UTF-8" Thank you! This is exactly was I was looking for. The range thing is good enough for me. Pablo On Wed, Apr 17, 2019 at 3:19 PM Adrian Klaver wrote: > On 4/17/19 2:21 PM, pabloa98 wrote: > > I have a schema with a generated table with information coming from > > batch processes. > > > > I would like to store in that table manually generated information. > > Since those rows are inserted by hand, they will be lost when the table > > will be reimported. > > > > So I was thinking of creating a partitioned table with a column "origin" > > to select if the data is batch inserted or inserted by hand. Current > > generated by batch sub-table will live in its schema. > > > > I want the other sub-table containing manually inserted information > > living in another schema. > > > > Is this possible? Do I have to do something else (create some trigger, > > or something)? > > > > Something like: > > > > CREATE TABLE*automatic.*measurement ( > > city_id int not null, > > logdate date not null, > > peaktemp int, > > unitsales int > > origin int > > ) PARTITION BY RANGE (origin); > > > > > > CREATE TABLE*automatic.*measurement_automatic PARTITION > OF*automatic.*measurement > > FOR VALUES FROM (1) TO (1) > > PARTITION BY RANGE (origin); > > > > CREATE TABLE*manual.*measurement_manual PARTITION > OF*automatic.*measurement > > FOR VALUES FROM (2) TO (2) > > PARTITION BY RANGE (origin); > > > > > > It would seem so(with a caveat): > > CREATE TABLE automatic.measurement ( > city_id int not null, > > > > logdate date not null, > > > > peaktemp int, > unitsales int, > origin int > ) PARTITION BY RANGE (origin); > CREATE TABLE > > CREATE TABLE automatic.measurement_automatic PARTITION OF > automatic.measurement > test-# FOR VALUES FROM (1) TO (1) > test-# PARTITION BY RANGE (origin); > ERROR: empty range bound specified for partition "measurement_automatic" > DETAIL: Specified lower bound (1) is greater than or equal to upper > bound (1). > > OOPS, so lets cheat: > > Removed PARTITION BY RANGE (origin) as it is redundant and causes > problems later. > > CREATE TABLE automatic.measurement_automatic PARTITION OF > automatic.measurement > FOR VALUES FROM (1) TO (2) > CREATE TABLE > > CREATE TABLE manual.measurement_manual PARTITION OF automatic.measurement > FOR VALUES FROM (3) TO (4) > CREATE TABLE > > The above assumes that manual origin will be in (1,2) and automatic in > (3,4) > > insert into automatic.measurement values(1, '04/16/19', 25, 100, 1); > INSERT 0 1 > > insert into automatic.measurement values(1, '04/16/19', 25, 100, 3); > INSERT 0 1 > > select * from automatic.measurement_automatic ; > city_id | logdate | peaktemp | unitsales | origin > ---------+------------+----------+-----------+-------- > 1 | 2019-04-16 | 25 | 100 | 1 > (1 row) > > select * from manual.measurement_manual; > city_id | logdate | peaktemp | unitsales | origin > ---------+------------+----------+-----------+-------- > 1 | 2019-04-16 | 25 | 100 | 3 > (1 row) > > -- > Adrian Klaver > adrian.klaver@aklaver.com > --00000000000056f9eb0586c1b3c1 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thank you! This is exactly was I was looking for.

The range thing is good enough for me.

Pablo

On Wed, Apr 17, 2019 at 3:19 PM Adrian Klave= r <adrian.klaver@aklaver.co= m> wrote:
On 4/17/19 2:21 PM, pabloa98 wrote:
> I have a schema with a generated table with information coming from > batch processes.
>
> I would like to store in that table manually generated information. > Since those rows are inserted by hand, they will be lost when the tabl= e
> will be reimported.
>
> So I was thinking of creating a partitioned table with a column "= origin"
> to select if the data is batch inserted or inserted by hand. Current <= br> > generated by batch sub-table will live in its schema.
>
> I want the other sub-table containing manually inserted information > living in another schema.
>
> Is this possible? Do I have to do something else (create some trigger,=
> or something)?
>
> Something like:
>
> CREATE TABLE*automatic.*measurement (
>=C2=A0 =C2=A0 =C2=A0 city_id=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0int not n= ull,
>=C2=A0 =C2=A0 =C2=A0 logdate=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0date not = null,
>=C2=A0 =C2=A0 =C2=A0 peaktemp=C2=A0 =C2=A0 =C2=A0 =C2=A0 int,
>=C2=A0 =C2=A0 =C2=A0 unitsales=C2=A0 =C2=A0 =C2=A0 =C2=A0int
>=C2=A0 =C2=A0 =C2=A0 origin=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 int
> ) PARTITION BY RANGE (origin);
>
>
> CREATE TABLE*automatic.*measurement_automatic PARTITION OF*automatic.*= measurement
>=C2=A0 =C2=A0 =C2=A0 FOR VALUES FROM (1) TO (1)
>=C2=A0 =C2=A0 =C2=A0 PARTITION BY RANGE (origin);
>
> CREATE TABLE*manual.*measurement_manual PARTITION OF*automatic.*measur= ement
>=C2=A0 =C2=A0 =C2=A0 FOR VALUES FROM (2) TO (2)
>=C2=A0 =C2=A0 =C2=A0 PARTITION BY RANGE (origin);
>
>

It would seem so(with a caveat):

CREATE TABLE automatic.measurement (
=C2=A0 =C2=A0 =C2=A0city_id=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0int not null, =



=C2=A0 =C2=A0 =C2=A0logdate=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0date not null,=



=C2=A0 =C2=A0 =C2=A0peaktemp=C2=A0 =C2=A0 =C2=A0 =C2=A0 int,
=C2=A0 =C2=A0 =C2=A0unitsales=C2=A0 =C2=A0 =C2=A0 =C2=A0int,
=C2=A0 =C2=A0 =C2=A0origin=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 int
) PARTITION BY RANGE (origin);
CREATE TABLE

CREATE TABLE automatic.measurement_automatic PARTITION OF
automatic.measurement
test-#=C2=A0 =C2=A0 =C2=A0FOR VALUES FROM (1) TO (1)
test-#=C2=A0 =C2=A0 =C2=A0PARTITION BY RANGE (origin);
ERROR:=C2=A0 empty range bound specified for partition "measurement_au= tomatic"
DETAIL:=C2=A0 Specified lower bound (1) is greater than or equal to upper <= br> bound (1).

OOPS, so lets cheat:

<NOTE> Removed PARTITION BY RANGE (origin) as it is redundant and cau= ses
problems later.

CREATE TABLE automatic.measurement_automatic PARTITION OF
automatic.measurement
=C2=A0 =C2=A0 =C2=A0FOR VALUES FROM (1) TO (2)
CREATE TABLE

CREATE TABLE manual.measurement_manual PARTITION OF automatic.measurement =C2=A0 =C2=A0 =C2=A0FOR VALUES FROM (3) TO (4)
CREATE TABLE

The above assumes that manual origin will be in (1,2) and automatic in (3,4= )

insert into automatic.measurement values(1, '04/16/19', 25, 100, 1)= ;
INSERT 0 1

insert into automatic.measurement values(1, '04/16/19', 25, 100, 3)= ;
INSERT 0 1

=C2=A0 select * from automatic.measurement_automatic ;
=C2=A0 city_id |=C2=A0 logdate=C2=A0 =C2=A0| peaktemp | unitsales | origin<= br> ---------+------------+----------+-----------+--------
=C2=A0 =C2=A0 =C2=A0 =C2=A0 1 | 2019-04-16 |=C2=A0 =C2=A0 =C2=A0 =C2=A025 |= =C2=A0 =C2=A0 =C2=A0 =C2=A0100 |=C2=A0 =C2=A0 =C2=A0 1
(1 row)

select * from manual.measurement_manual;
=C2=A0 city_id |=C2=A0 logdate=C2=A0 =C2=A0| peaktemp | unitsales | origin<= br> ---------+------------+----------+-----------+--------
=C2=A0 =C2=A0 =C2=A0 =C2=A0 1 | 2019-04-16 |=C2=A0 =C2=A0 =C2=A0 =C2=A025 |= =C2=A0 =C2=A0 =C2=A0 =C2=A0100 |=C2=A0 =C2=A0 =C2=A0 3
(1 row)

--
Adrian Klaver
adrian.klave= r@aklaver.com
--00000000000056f9eb0586c1b3c1--