[英]How can I truncate (substring) all values for a particular column of a table in a PostgreSQL database?
I'm fairly new to PostgreSQL. 我对PostgreSQL很新。 I'm working with a table that has not had a max-length (character count) enforced in the "title" column. 我正在使用一个没有在“标题”列中强制执行最大长度(字符数)的表。 The application needs it to be less than 1000 characters but some fields are at 1200, 1300 etc. 应用程序需要它少于1000个字符,但有些字段是1200,1300等。
I'm quite familiar with mySql but I'm having a harder time picking up PostgreSQL. 我对mySql非常熟悉,但是我很难接受PostgreSQL。
If this was mySql I would so something like: 如果这是mySql我会这样:
UPDATE TABLE entries SET title = LEFT(title,1000)
How can I accomplish the same thing with PostgreSQL? 如何用PostgreSQL完成同样的事情?
I have phppgadmin and the commmand line at my disposal. 我有phppgadmin和命令行供我使用。
Actually, it's the same in postgresql 实际上,它在postgresql中是一样的
UPDATE TABLE entries SET title = LEFT(title,1000)
or you can do something like this 或者你可以做这样的事情
UPDATE TABLE entries SET title = substring(title from 1 for 1000)
Here's the doc about the string functions in postgresql 这是关于postgresql中字符串函数的文档
In PostgreSQL it could be: 在PostgreSQL中它可能是:
UPDATE TABLE entries SET title = substring(title from 1 for 1000)
From the pg documentation : 从pg文档 :
Function substring(string [from int] [for int])
函数 substring(string [from int] [for int])
Descript Extract substring
描述 Extract substring
Example substring('Thomas' from 2 for 3)
示例 substring('Thomas' from 2 for 3)
Result hom
结果 hom
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.