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. 1 Answer Sorted by: 35 If you are using PostgreSQL 9. This SQL code: CREATE TABLE new (id int) ALTER TABLE new RENAME TO old DROP TABLE old renames the table correctly. The postgresql documentation for the alter table method does not tell me explicitly about this particular problem: ĭo I really need to use a prefix like ' backup' instead of '_' ? Or would it be possible to rename it, my only interest is to maintain the information in the table whilst having the minimal changes to the table name. I'm using PostgreSQL 9.x, I want to rename a table. I am using pgAdmin III to access the database tables and making use of it's 'rename' operation results in the same error. The '_my_table' table is a fake name, but this error is reproduced by actually creating a '_my_table' table and running the same script above. ![]() Add workaround for ActiveRecords schema cache. NOTICE: table "_my_table" does not exist, skipping ERROR:ĮRROR: type "_my_table" already exists SQL state: 42710 Create a database view using the old table name by pointing to the new table name. The result of the query is the following: But this is not working: DROP TABLE IF EXISTS _my_table - table does not exists, this does nothing ![]() For this I thought of renaming the older tables so they have an underscore as a prefix. The batch operation on other backends will proceed using standard ALTER TABLE operations. ![]() The directive by default will only use recreate style on the SQLite backend, and only if directives are present which require this form, e.g. I have a database which relies on a PostgreSQL system and I am maintaining it so I want to change tables and overall scheme. the new table is renamed to the existing table name.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |