PG重命名表字段及表名

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)

你可能感兴趣的:(Highgo,DB,PostgreSQL)