PostgreSQL怎么更改列类型
我们来看一下pg中的语法:
推荐:postgresql教程
highgo=# \h auto where action is one of: ADD [ COLUMN ] [ IF NOT EXISTS ] column_name data_type [ COLLATE collation ] [ column_constraint [ ... ] ] DROP [ COLUMN ] [ IF EXISTS ] column_name [ RESTRICT | CASCADE ] ALTER [ COLUMN ] column_name [ SET DATA ] TYPE data_type [ COLLATE collation ] [ USING expression ] ALTER [ COLUMN ] column_name SET DEFAULT expression
更改列类型demo:
highgo=# alter table p1 alter COLUMN pswd type text ; ALTER TABLE highgo=# \d p1 Table "public.p1" Column | Type | Collation | Nullable | Default --------+-----------------------------+-----------+----------+--------- id | integer | | | pswd | text | | | time | timestamp without time zone | | |
请注意,假如是不同类型转换的话可能不成功。
推荐学习《Python教程》。
神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试