Postgres:减少 varchar 大小并截断
我目前有一个 Postgres 8.4 数据库,其中包含 varchar(10000) 列。我想将其更改为 varchar(255) 并截断任何太长的数据。我该怎么做?
I currently have a Postgres 8.4 database that contains a varchar(10000) column. I'd like to change this into a varchar(255) and truncate any data that happens to be too long. How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
类似于 ALTER TABLE t ALTER COLUMN c TYPE VARCHAR(255) USING SUBSTR(c, 1, 255)
Something like
ALTER TABLE t ALTER COLUMN c TYPE VARCHAR(255) USING SUBSTR(c, 1, 255)
1) 使用子字符串方法更新列数据以截断它
2) 然后更改表列
此处的文档 http://www.postgresql.org/docs/8.4/static/sql-altertable.html
1) Update the column data using a substring method to truncate it
2) Then alter the table column
Docs here http://www.postgresql.org/docs/8.4/static/sql-altertable.html