Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3452402
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:15:15+00:00 2026-05-18T09:15:15+00:00

I have a table, foo . For the purposes of a quick upgrade/deploy of

  • 0

I have a table, foo. For the purposes of a quick upgrade/deploy of my site, I made a new table, tmp_foo, to contain some new data, by doing:

create table tmp_foo (like foo including constraints including defaults including indexes);

Now each table has a PK id column that looks like:

   Column    |         Type          |                                Modifiers                                 
-------------+-----------------------+--------------------------------------------------------------------------
 id          | integer               | not null default nextval('foo_id_seq'::regclass)

The important point is that both tables rely on the exact same sequence, foo_id_seq. There is no tmp_foo_id_seq. This seems OK for my purposes.

After this, I loaded tmp_foo with new data and renamed the tables so that tmp_foo took over as the real foo, and the original foo became foo_old. Now I try to drop foo_old:

db=> drop table foo_old ;
ERROR:  cannot drop table foo_old because other objects depend on it
DETAIL:  default for table foo_old column id depends on sequence foo_id_seq

Fair enough, the id column default still depends on the sequence.

db=> alter table foo_old alter column id drop default;

Here’s the kicker.

db=> drop table foo_old ;
ERROR:  cannot drop table foo_old because other objects depend on it
DETAIL:  default for table foo column id depends on sequence foo_id_seq

So foo_old no longer has any visible dependency on the sequence, yet it still tries to drop the sequence along with the table (and obviously won’t because the new table depends upon it).

So the question is two-part:

  1. Why is the sequence still linked
    with the old table?
  2. Is there any
    way around this that doesn’t involve
    making the new table depend on a
    new or different sequence (if that
    would even help)?

(On PostgreSQL 8.4)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T09:15:15+00:00Added an answer on May 18, 2026 at 9:15 am

    Try this:

    ALTER SEQUENCE foo_id_seq OWNED BY NONE
    

    then you should be able to drop the table.

    To retrieve the “owner” of a sequence use the following query

    SELECT s.relname as sequence_name,  
           n.nspname as sequence_schema,  
           t.relname as related_table, 
           a.attname as related_column 
      FROM pg_class s, pg_depend d, pg_class t, pg_attribute a, pg_namespace n 
      WHERE s.relkind     = 'S' 
        AND n.oid         = s.relnamespace 
        AND d.objid       = s.oid 
        AND d.refobjid    = t.oid 
        AND (d.refobjid, d.refobjsubid) = (a.attrelid, a.attnum)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table foo with a varchar field text where some rows are
I have following table and data: create table Foo ( id int not null,
I have a table FOO with the following definition: id INTEGER, type INTEGER, data
Let's say I have a table Foo . This table has the columns ID
I have the following test-code: CREATE TABLE #Foo (Foo int) INSERT INTO #Foo SELECT
I have my own type: CREATE TYPE MyType AS TABLE ( foo INT )
I have a table A with 2 columns Foo and Bar. I have a
In my Ruby on Rails app, I have a User table and a Foo
Suppose I have a database table with two fields, foo and bar. Neither of
Let's say I have a mysql table, called foo with a foreign key option_id

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.