PG重命名表字段及表名

来源:互联网 发布:js常用调试工具 编辑:程序博客网 时间:2024/04/29 01:30
PG重命名表字段:


highgo=# \d test
      Table "public.test"
 Column |  Type   | Modifiers  
--------+---------+------------
 id     | integer | default 10
 no     | text    | 


highgo=# alter table test rename column no to name;
ALTER TABLE


highgo=# \d test
      Table "public.test"
 Column |  Type   | Modifiers  
--------+---------+------------
 id     | integer | default 10
 name   | text    | 
 
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
 
 PG重命名表名:
 highgo=# select * from test;
 id | name 
----+------
 15 | 1
 15 | 2
 15 | 
 15 | 1
(4 rows)


highgo=# 
highgo=# 
highgo=# 
highgo=# alter table test rename to t;
错误:  关系 "t" 已经存在
highgo=# alter table test rename to test_new;
ALTER TABLE
highgo=# select * from test;
错误:  关系 "test" 不存在
LINE 1: select * from test;
                      ^
highgo=# select * from test_new;
 id | name 
----+------
 15 | 1
 15 | 2
 15 | 
 15 | 1
(4 rows)
原创粉丝点击