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 1tfZfn-003QIg-Sh for pgsql-admin@arkaria.postgresql.org; Wed, 05 Feb 2025 07:18:12 +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 1tfZfk-00CP7B-QR for pgsql-admin@arkaria.postgresql.org; Wed, 05 Feb 2025 07:18:08 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tfZfk-00CP72-Dv for pgsql-admin@lists.postgresql.org; Wed, 05 Feb 2025 07:18:08 +0000 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tfZfh-003GqZ-2G for pgsql-admin@lists.postgresql.org; Wed, 05 Feb 2025 07:18:07 +0000 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-43622267b2eso63789055e9.0 for ; Tue, 04 Feb 2025 23:18:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1738739883; x=1739344683; darn=lists.postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=DfyniZV7ZJTzaKrn8BnlpIOGHVd2O9Ta++4cj0gkjkQ=; b=ltOnAYCXcztB8f+MyoFTru7Vn4ckrXLMLDNoFzQ60da9JXad3rLvJ0oyLkLPs22gP4 U865OMpYTT2F2kWNiNK4AcNGdnRQifUgEMnKpA3pSsWN5dN24yspYXcKPlSL8O86CxI7 G/xV7W7PZSpC4PP4kQ3AkJaBbiQnIXCcQ/PsOxmYN/qKJST2F7prYfC3I6Rw/wFrF0uu 6l4VMEfEMs2wyn82k7roRONmE0m0NEDBUnncYOE7W5nSfCAXnIhi/Axjgr6JxttH1wIl XUSiZ4n2/EoAw0qm6VargciQ/VCktu6LeUIX6slGVVlGAu0+JM4Gq/ylaQ3wh6nC+Zch QHNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738739883; x=1739344683; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=DfyniZV7ZJTzaKrn8BnlpIOGHVd2O9Ta++4cj0gkjkQ=; b=ohdJitP6faGJm7l2k110WyqM+FW5f0PpU5Zzyd8iiQrUvpXLFKVU/tovWdrU0b7/Jr TFd8EdLK/G/7sMpYwCYYhexbHZmU6OiN/VNOZcql/PVm4Yg4ioMh9Bk1LPgk0JOvGTGw DhiGLkj6Rcs0NOr+/AJTgwhAKVNfB7CgSsiczVqsZqiVEWlJCuYWcLP6zcaXbp6PG/Pj DbAu1QOo+ELWLf1R5r9Jux/ObzG+B7WE5fbPupaEe3i6V+YCd1XGFRnjPaMwVRYiDiuu 9SyuBwu60+jbds9UhxWAS9UqYeI34acKsXqTH4GvSThy9Soy0J5kRrVis3SF+7aRJ4oa PhYw== X-Forwarded-Encrypted: i=1; AJvYcCXwG/7yjzEcZ/cpf3gL85vmY60b47rF44qvvxq+dTsVWQsDdF1i3QYfdYCfEe9akNRYVFFaUP1LJoNiXg==@lists.postgresql.org X-Gm-Message-State: AOJu0YyxN964Zkb0wVba+RLaonX4/AglQ+zkLG0J7xvsN0kmNqbLk85y c4qjFPrQnJg3rBCVJnxOZkOkGdBNiO9r+39KKkKOxDN7J9cquPvVbKvdyxpDr89NXTlL3QZv+Gb b X-Gm-Gg: ASbGncteze/G8tfmbzLEmSV48Oub4Vdu3qUier9Yutk1zvjtL5JJiGPTuA0aNJiMz1r xw2m2M9f+zp2E/fo4wN5/RNmbwf0GNwWqismdaOaxZZe1sf58Bt10znZO+3XPfX8delS7BNQzeX rx1Qf2sjEu0puP7L12tbNrwltvU5+ZMMjq8KJB9q9mnOqAtgGQ6bXAhrOvDTAyQqBgDntB2365z pOyB7L21RMHrD4sknVzvV1+1lcTVXqq3z9nWVvuw/Iatz8ShTY4PKSmdcp+x6Wk98HLLeai40Xk L+ok20xlCpVB/L1hzHJ2L7QvXG6jKr8= X-Google-Smtp-Source: AGHT+IHIC0anlfHSeWzAlgwsFKSO8kd0se9FRZ3T6x01SfO9fCF2X+0Mjtyu+QRIgGqf4zHS8cmewA== X-Received: by 2002:a05:6000:178a:b0:38d:b2a1:244e with SMTP id ffacd0b85a97d-38db492a008mr987800f8f.41.1738739883614; Tue, 04 Feb 2025 23:18:03 -0800 (PST) Received: from localhost.localdomain ([41.66.98.90]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38db6d7fb3dsm521828f8f.72.2025.02.04.23.18.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2025 23:18:03 -0800 (PST) Message-ID: Subject: Re: Partition table with a foreign key self-reference From: Laurenz Albe To: Oliver Urones , pgsql-admin@lists.postgresql.org Date: Wed, 05 Feb 2025 08:18:02 +0100 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.54.3 (3.54.3-1.fc41) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, 2025-02-04 at 16:57 +0100, Oliver Urones wrote: > I need help with the process of partitioning tables. >=20 > How can I partition a table that has a foreign key that references itself= ? >=20 > Something like this example: >=20 > CREATE TABLE employees ( > =C2=A0 =C2=A0 employee_id SERIAL PRIMARY KEY, > =C2=A0 =C2=A0 name VARCHAR(50), > =C2=A0 =C2=A0 boss_id INTEGER, > =C2=A0 =C2=A0 CONSTRAINT fk_boss FOREIGN KEY (boss_id) REFERENCES employe= es(employee_id) > ); >=20 > I'm using Postgresql 14. The question makes no sense as such. You'd have to tell us the purpose you want to achieve with partitioning. Depending on that, you'd choose the partitioning strategy and the partitioning key. At any rate, you'll probably have to drop the foreign key constraint unless your partitioning key is "id". Yours, Laurenz Albe