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 1hcBJg-0003wW-M0 for pgsql-bugs@arkaria.postgresql.org; Sat, 15 Jun 2019 16:14:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hcBJf-00052I-Gt for pgsql-bugs@arkaria.postgresql.org; Sat, 15 Jun 2019 16:14:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hcBJf-0004rm-6B for pgsql-bugs@lists.postgresql.org; Sat, 15 Jun 2019 16:14:07 +0000 Received: from mail-qk1-x744.google.com ([2607:f8b0:4864:20::744]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hcBJd-0004bn-5n for pgsql-bugs@lists.postgresql.org; Sat, 15 Jun 2019 16:14:06 +0000 Received: by mail-qk1-x744.google.com with SMTP id x18so3664747qkn.13 for ; Sat, 15 Jun 2019 09:14:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=RzBStJ4dN7Syu3JM63jlFxF+nhAPVioYEjObdtf1/6o=; b=YmmTvTFQcQ2aHe/T41RhT02yf6Gcps4adFjKY9Bt2dwN9m5JrvtYL7tMGwyMqP6JNq K0OZCQgJanY/FP09HDMz9euHOZCAgF2W9dmqpSziQC/3mpjCqof9c0vab0uRs2SBdoYm 9J+YI37YCIlfPdNPwQzDIK7I6CYC4DuN6mxrai3vdC3bByD8P4WfmTHng4llL/F0J92i m1aNGA8HvYO5Gisq02NpJoJFi6cgiCe1xYs6QbAhGTqpibb0yDrTevA/jqZG0KwQJPmb mF7oYzuTRWUVb4ECm7O9NXgZwIX9quAv6cDoqGLAMx4I3/bJDDPdNEFJL6do1S8a+AB7 dltQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=RzBStJ4dN7Syu3JM63jlFxF+nhAPVioYEjObdtf1/6o=; b=R8IxL0HCc1AsplVG01Nk/F6qK31BUrdlhno7ivYS74cEau/h5xhrG1U+WSMw8tOG92 OuSCNxMr5CVfdT3LuYOU9q6Ym9UsB6FwmP2Frw/BVLXKBw9Dv4fBIR7LDRRtmax+1sOe fG4aHH9bqsbbBTr+G7yJI8JgB1YAVpNtcKhhK8C1lgTqSjYDsTOR5u/+c6a/5U6VJu2b 3C4tM1RqmgHHgZYIu6sVO064zNuHIN4QXxc/PijjJVZ9K16QS6Q3CE+gQheYbzXakNO7 iqxsIBfYbdcntMvkJGARCiK7pIOlZcxXjlcfPZqtTX4k2SDyqYit6uBQTJ8/vWnqnHkR 10ug== X-Gm-Message-State: APjAAAV7kKr62KyzTwL97sbHRUq37o/uzBe69EWCyv72nguq1IvYPu0E OJyQAgfFhXt1A4H0btEDo/LDiA== X-Google-Smtp-Source: APXvYqyxsJI6N5g4psI8dwDJThc0R6KGsBAW0EYyzk8sDmS0vsuz/107Jjq6pjCXFcG3meFu5wUvuA== X-Received: by 2002:a37:5c8:: with SMTP id 191mr68860681qkf.188.1560615242182; Sat, 15 Jun 2019 09:14:02 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([177.154.139.203]) by smtp.gmail.com with ESMTPSA id d26sm3425946qkl.97.2019.06.15.09.14.01 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 15 Jun 2019 09:14:01 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id C7CAD12084B; Sat, 15 Jun 2019 12:13:58 -0400 (-04) Date: Sat, 15 Jun 2019 12:13:58 -0400 From: Alvaro Herrera To: wondertx@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15853: DROP TABLE CASCADE drops sequence that other tables depend on Message-ID: <20190615161358.GA31948@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <15853-b83a5170b0267679@postgresql.org> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2019-Jun-15, PG Bug reporting form wrote: > The following SQL executed will drop the sequence `t_id_seq`: > CREATE TABLE t(id SERIAL, value INT NOT NULL); > CREATE TABLE t_bak LIKE t INCLUDING DEFAULTS INCLUDING INDEXES INCLUDING > COMMENTS INCLUDING CONSTRAINTS); > DROP TABLE t CASCADE; > This will drop default value of column `value` in t_bak. Yes. The reason the sequence is dropped is that it is owned by the t.id column, so when the column goes away, so does the sequence. And this cascades to that default value. > However, the following SQL will not drop the sequence: > CREATE TABLE t(id SERIAL, value INT NOT NULL); > DROP SEQUENCE t_id_seq; > CREATE SEQUENCE t_id_seq; > ALTER TABLE T ALTER COLUMN ID SET DEFAULT NEXTVAL('t_id_seq'::regclass); > CREATE TABLE t_bak LIKE t INCLUDING DEFAULTS INCLUDING INDEXES INCLUDING > COMMENTS INCLUDING CONSTRAINTS); > DROP TABLE t CASCADE; In this case, by dropping and recreating the sequence, you made it an independent sequence. Setting as the default for the column doesn't make it owned by it. If you throw ALTER SEQUENCE t_id_set OWNED BY t.id; in the mix, then it should work just like in the first case. Conversely, you can make the first case behave like the second by doing this ALTER SEQUENCE t_id_set OWNED BY NONE; In short, not a bug. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services