Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rxVre-009Ki1-Q6 for pgsql-general@arkaria.postgresql.org; Thu, 18 Apr 2024 17:48:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rxVrd-007gXm-BW for pgsql-general@arkaria.postgresql.org; Thu, 18 Apr 2024 17:48:01 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rxVrc-007gXd-UJ for pgsql-general@lists.postgresql.org; Thu, 18 Apr 2024 17:48:01 +0000 Received: from mail-ed1-x52e.google.com ([2a00:1450:4864:20::52e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rxVra-001fAn-GK for pgsql-general@lists.postgresql.org; Thu, 18 Apr 2024 17:48:00 +0000 Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-563cb3ba9daso1072695a12.3 for ; Thu, 18 Apr 2024 10:47:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nielsen.com; s=dkim-gsuite-connect; t=1713462476; x=1714067276; darn=lists.postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=0YCingnjmN5H9xvuGwcSIMTMTozZay4v6mHBXtLATk4=; b=an+Uj+iK47YgWXOgwPorZFcqloDargQi2TILq3+Z2yfXW8/g6E3swWRduf5viVptwu 0vjZAlmMbXDvL5UAljkyrfa5wH/qGixwuRUg4Px8qdzw/7WYdB4D9AkCH93qsxO6wYvX tkUdfYlB15iOJZ/qm36pRMB9GQ4dmYXWupH9U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713462476; x=1714067276; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=0YCingnjmN5H9xvuGwcSIMTMTozZay4v6mHBXtLATk4=; b=keHxUIAcRkOhyaE9q95l/dzv3TB99I2J/NO6yOJu9oANpWYb4hoOsT2L1rimvVSyZs QvkYI3yjR62oLMNCwWF0u+KM5uV6uKPF5W6lOxye+IGuegxiNq7D6l41NncElmTpfPQj 64BXBGvHuxi8R3G00pVlvjWZVWmwndvP3/TeEatwsg5Y1TiOB2I0aFnWIpHkjO4Zhlrf VxfxHnG2C6qm9QgCmx2tTo4NyLsEDWdjJBF/egNaBYtd0P8Y/LtQ6Es2O3QOVTsPFUwa WLJm3Xwj6QgNV+/aKg0CcTQnlZcsY6yTkq8Feb9f+hXMTQRL8GCIZvEE9NQFFWxOO+wr 8lKA== X-Gm-Message-State: AOJu0YwE4LbCFtQ2Bn/Vr2pamyhGgCQYkbSVS4QCoqvIjqHTVvKcobEC glgGcbtwRjJk69QcqV4OvwOWeQFGH2sJtz3/jJ4ftPBObsDQSaAbKushbK2PKBiY3pouiMelhXz vPHJGWhpRBeUibnWXODBWXZzA88pHQYSYKvuNaWDYRn+ntihfUSE= X-Google-Smtp-Source: AGHT+IGjihxRZYmDvLIcWlhyGXI7Zv6Dua324x4Z9sxligH6+ozrJHYieLZiEff/+R2QXE8nQbjgBl240e+kcZlIU/w= X-Received: by 2002:a50:c00a:0:b0:570:2418:3607 with SMTP id r10-20020a50c00a000000b0057024183607mr2652687edb.36.1713462476111; Thu, 18 Apr 2024 10:47:56 -0700 (PDT) MIME-Version: 1.0 From: Michael Corey Date: Thu, 18 Apr 2024 13:47:19 -0400 Message-ID: Subject: Foreign Key error between two partitioned tables To: pgsql-general@lists.postgresql.org Content-Type: multipart/alternative; boundary="00000000000039dfd306166292ec" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000039dfd306166292ec Content-Type: text/plain; charset="UTF-8" Hello, I receive the following error when creating a foreign key between two partitioned tables. ERROR: there is no unique constraint matching given keys for referenced table "par_log_file" Here is my setup: CREATE TABLE par_log_file ( par_file_id character varying(20) NOT NULL, par_id character varying(64) NOT NULL ) PARTITION BY RANGE (par_file_id) ; ALTER TABLE ONLY par_log_file ADD CONSTRAINT plf_pk PRIMARY KEY (par_file_id); -- CREATE TABLE par_log_definition ( par_file_id character varying(20) NOT NULL, tif_seq_nmbr bigint NOT NULL, name_25 character varying(255) ) PARTITION BY RANGE (par_file_id) ; ALTER TABLE ONLY par_log_definition ADD CONSTRAINT pld_pk PRIMARY KEY (par_file_id, tif_seq_nmbr); CREATE INDEX pld_idx ON par_log_definition USING btree (par_file_id); ALTER TABLE par_log_definition ADD CONSTRAINT pld_fk FOREIGN KEY (par_file_id) REFERENCES par_log_file(par_file_id); Version Postgres 13.13 Any help would be appreciated/ -- Michael Corey --00000000000039dfd306166292ec Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello,

I receive the following error when creating a = foreign key between two partitioned tables. =C2=A0
ERROR: =C2=A0there is no unique constraint matching gi= ven keys for referenced table "par_log_file"

Here is my setup:

CREATE TABLE par_log_file (
=C2=A0 =C2=A0 par_file_id charact= er varying(20) NOT NULL,
=C2=A0 =C2=A0 par_id character varying(64) NOT = NULL
) PARTITION BY RANGE (par_file_id) =C2=A0;

ALTER TABLE ONLY = par_log_file
=C2=A0 =C2=A0 ADD CONSTRAINT plf_pk PRIMARY KEY (par_file_i= d);

--

CREATE TABLE par_log_definition (
=C2=A0 =C2=A0 par= _file_id character varying(20) NOT NULL,
=C2=A0 =C2=A0 tif_seq_nmbr bigi= nt NOT NULL,
=C2=A0 =C2=A0 name_25 character varying(255)
) PARTITION= BY RANGE (par_file_id) =C2=A0;


ALTER TABLE ONLY par_log_definit= ion
=C2=A0 =C2=A0 ADD CONSTRAINT pld_pk PRIMARY KEY (par_file_id, tif_se= q_nmbr);

CREATE INDEX pld_idx ON par_log_definition USING btree (par= _file_id);

ALTER TABLE par_log_definition
=C2=A0 =C2=A0 ADD CONST= RAINT pld_fk FOREIGN KEY (par_file_id) REFERENCES par_log_file(par_file_id)= ;


Version Postgres 13.13

Any help would be appreciated= /


--
Michael C= orey
--00000000000039dfd306166292ec--