Reputation: 3344
I'm using PostgreSQL 9.x, I want to rename a table. This SQL code:
CREATE TABLE new (id int);
ALTER TABLE new RENAME TO old;
DROP TABLE old;
renames the table correctly. But this SQL code:
CREATE SCHEMA domain;
CREATE TABLE domain.old (id int);
ALTER TABLE domain.old RENAME TO domain.new;
fails, with error:
ERROR: syntax error at or near "."
The "." underlined is the one between 'domain' and 'new'
Upvotes: 107
Views: 81185
Reputation: 435
SET search_path TO domain;
ALTER TABLE IF EXISTS old_table_name RENAME TO new_table_name;
Upvotes: 0
Reputation: 3395
machine$\c my_database
my_databse=# alter table old_name rename to new_name;
Upvotes: -2
Reputation: 34776
One way to do this:
ALTER TABLE domain.old RENAME TO new
Other way:
SET search_path TO domain;
ALTER TABLE old RENAME TO new;
Documentation for search_path
.
Upvotes: 181