public inbox for [email protected]  
help / color / mirror / Atom feed
From: Bruce Momjian <[email protected]>
To: Robins <[email protected]>
Cc: [email protected]
Subject: Re: Clarify 'dependent objects' for DROP COLUMN
Date: Wed, 13 Mar 2013 17:19:41 -0400
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAEP4nAxFw=2pB-oJyWZkwo7hccggoDzooEBmv+umd1R-neyZXg@mail.gmail.com>
References: <CAEP4nAxFw=2pB-oJyWZkwo7hccggoDzooEBmv+umd1R-neyZXg@mail.gmail.com>
List-Unsubscribe: <mailto:[email protected]?body=unsub%20pgsql-docs>

On Tue, Mar 12, 2013 at 09:51:44AM +0530, Robins wrote:
> Hi,
> 
> ALTER TABLE in postgresql.org/docs/devel/ says:
> 
> RESTRICT: Refuse to drop the column or constraint if there are any dependent
> objects. This is the default behavior.
> 
> Could someone confirm whether 'dependent objects' also includes SEQUENCES? i.e.
> if I create a sequence OWNED BY tbl.col1 and then try to drop the column with
> RESTRICT, should it allow this DROP? Currently it does, but by reading that
> line it seemed it shouldn't.

I had to dig a little bit on this.  The "dependent" object would be the
removal of the constraint depending on the sequence.  Here is an
example:

	test=> create table test (x serial);
	CREATE TABLE
	test=> \d test
	                         Table "public.test"
	 Column |  Type   |                    Modifiers
	--------+---------+--------------------------------------------------
	 x      | integer | not null default nextval('test_x_seq'::regclass)
	
	test=> \ds
	             List of relations
	 Schema |    Name    |   Type   |  Owner
	--------+------------+----------+----------
	 public | test_x_seq | sequence | postgres
	(1 row)
	
-->	test=> drop sequence test_x_seq;
	ERROR:  cannot drop sequence test_x_seq because other objects depend on it
	DETAIL:  default for table test column x depends on sequence test_x_seq
	HINT:  Use DROP ... CASCADE to drop the dependent objects too.
-->	test=> drop sequence test_x_seq cascade;
	NOTICE:  drop cascades to default for table test column x
	DROP SEQUENCE
	test=> \d test
	     Table "public.test"
	 Column |  Type   | Modifiers
	--------+---------+-----------
	 x      | integer | not null

If this does not answer your questions, please post queries showing the
problem.   Thanks.

-- 
  Bruce Momjian  <[email protected]>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + It's impossible for everything to be true. +


-- 
Sent via pgsql-docs mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-docs



view thread (5+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: Clarify 'dependent objects' for DROP COLUMN
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox