0

I have created two PostgreSQL tables tables (the code originates from a Django app):

CREATE TABLE "app_book" (
    "id" serial NOT NULL PRIMARY KEY,
    "title" varchar(256)
);
CREATE TABLE "app_author" (
    "book_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "app_book" ("id") DEFERRABLE INITIALLY DEFERRED,
    "name" varchar(128) NOT NULL
);

I want to rename the table app_book to app_item. Is the following line sufficient, or do I also have to update the REFERENCES in app_author? If so, how can I do that?

ALTER TABLE app_book RENAME TO app_item;

Looking at this page, I guess that it does not. But the page does not explain how to update the reference.

mimo
  • 2,469
  • 2
  • 28
  • 49

1 Answers1

1

See for yourself http://sqlfiddle.com/#!15/0dd1f/5

The problem described in your link only refers to problems when using Slony.

If you can live with the fact that the sequence "behind" the id column does not reflect the name change then everything is fine. If it bothers you, you need to rename the sequence as well. Note that pg_get_serial_sequence() still works.

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228