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 1mWxC1-0001yp-VV for pgsql-general@arkaria.postgresql.org; Sun, 03 Oct 2021 08:49:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mWxBz-00079t-Ra for pgsql-general@arkaria.postgresql.org; Sun, 03 Oct 2021 08:49:55 +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 1mWxBz-00079l-IQ for pgsql-general@lists.postgresql.org; Sun, 03 Oct 2021 08:49:55 +0000 Received: from mout.gmx.net ([212.227.15.19]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mWxBx-0000qe-DR for pgsql-general@lists.postgresql.org; Sun, 03 Oct 2021 08:49:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1633250990; bh=2IyKq5UqoPYymV9hfuBPKGJclXkltURzMZ10+WzsGsA=; h=X-UI-Sender-Class:Subject:To:References:From:Date:In-Reply-To; b=gIKWCb2ATJBcD0pzt2azbGq5HIFc8YL2YeYExDQjwJnUnJ6rqDehZFOZkwhyx2zy1 XZunMrzXXITDcrIUTCy7W5VkGCf/1PHsUSsSZv80JFrS6aK57zD4lR7RoaIpHmjNcN C9qUk4mzjkaTlYfGaYQTIK1fH0CeiWCByFA18FaA= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.178.20] ([83.171.162.122]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1M7sHo-1mT7RU2RNa-0051X2 for ; Sun, 03 Oct 2021 10:49:50 +0200 Subject: Re: PostgreSQL - Ordering Table based of Foreign Key To: pgsql-general@lists.postgresql.org References: From: Thomas Kellerer Message-ID: <553c3b6b-93f0-591e-2a48-0c8ab5344d13@gmx.net> Date: Sun, 3 Oct 2021 10:49:49 +0200 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.21) Gecko/20090302 Thunderbird/2.0.0.21 Mnenhy/0.7.5.666 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: de-DE Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:ayFbnWE/43tGydLLKqrC931IDeGwwetQsuJxw0VGdqWVVxbdx/i YE6bA6Q8rFvi5W/kXkKafGyQ1upfbBbvrx91LUtmr/Hx/dLpjzmclCN/moxAMWDkUm+Cr/2 SSHbkOBP8BcNTZhterB08pXYoYpCMzmURbFJ1PmWjj2eBILnCJ/7jN3o2MU2/iJ9M88t+yR ejpmxJ3dvUf4XDNhO4eNw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:VOF6GDNBHGk=:OcuNHQC3dfOZiEKTgDqUIQ oAUZcE4RToR4688Gc5tVbmEhGaNdSak1GHnjNH7H15viXRlUkHG62YB+95KS6h9xv0hVUzO0V l4n6Nxn8fSmeyBKO6Ium9lu92QnnfC5tDQxwAoTKY3wEE6Z5hb4Yy/2X9sbBFVyqs9f3yY3eV eeYN1nHRylTCea/z7JNUh5AbYryh3hsyR3gmGUlCdQhjqFUFfVUMIgbbLwW4vZ37eGu7Si738 OrEgZpbywwfxse4YxqXmFs6q4NM6BtZjVMKK4Y4ggD/OJcjk+kov+pVCgKSYw1Tn/YSrLFfjL S6H8iCp0Gq4cpJN5N1HJa/8PlqaRB7SYXINW4pfwvhtfhMA2O8Fj9h5wfOaFJSHoD8U4HjZjR r07mxvpznc4iRpjx32bhGU7G+ztZXYp+vrZg4dTmiQTmnpMnSG4lTp86MFtv03ix/+KCuwpAV T8UPSTTpnsv71Gdmcjkf9lRczn1xSvIrS1Rw7AVbiOknibNQ4zZebxoBwlJ3cYm0QzS6tu+Uy n2s00ZMGWLgVND1MzMpS0nRwnO9N3ntN77VLJWOTVKufZ37aRn7R7QnXir9znl2MBWFnLvBPX OPsNyFYWCZ0TqFEU8BpchgFIXGrkAEnq0Z3lvICEeN143oWTE7iiRYK2X3HCql3+dB8N7j/0h gMqzw7J4LiiTZsxw9af5Un9FAJafSMxUo+vjZs6O5p36B9hRwgqMCe3OZGTWQGr0Tn/LOgExS Ys08ZXZ18F/f9oF6CfdrV0TDB/aUjdlLCZA3U/8mDE9ARD6ks85ivnqelwseiZ2TQH+EdJV3f 64X2mwZoFbb/W+87ahdUmvM0X+XCK5PcGjBu671wqbGLo2X74Bp1Yny5TROnVzocXdW/oXUa4 404gWMKt+jecwUNZfRE1jeAUMSLcqS1lywCAvWgO3lyEUJW8/bg334p3ojsv3ciHlaoGCQ3X/ z5P29EBtUqw3HqEcmYIrME8xxACz6FDjDR8xRYd4Dc4JrMG8TP07xkEwz5k8U6zq75A/gixXm XfdtoezVeYf1R4pbedSNIJtUseefw5PgJVyRFQvXLHSzBRrH7hjqfsOV/BgHgTmXWLQd8PbHs xXszaoc1fAE4+o= List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk FOUTE K. Jaur=C3=A8s schrieb am 03.10.2021 um 09:48: > I want to order tables based on the foreign key so that I can delete > tables one by one without facing "ERROR: update or delete on table > "table" violates foreign key constraint. DETAIL: Key is still > referenced from table" You can create the foreign key constraints with the "ON DELETE CASCADE" op= tion. Then Postgres will handle dependencies automatically for you. But that means that *all* DELETEs will be cascaded. Unfortunately, there is no DELETE FROM ... CASCADE option (similar to DROP= ) Thomas