简体   繁体   English

如何截断(substring)PostgreSQL数据库中表的特定列的所有值?

[英]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.

相关问题 我如何在PostgreSQL中找到包含主键或单个表的特定列的所有数据库表 - How can I find all the tables of db that contains primary key or particular column of a single table in Postgresql 如何在所有表中查找特定列并在PostgreSQL中修改该列的值 - How to find a particular column in all tables and modify the values of that column in PostgreSQL PostgreSQL-如果所有列值均为'A'或NULL,如何返回ID - PostgreSQL - How can I return ids if all column values are 'A' or NULL 如何获取存储在 PostgreSQL 中特定模式的数据库中的所有函数的列表? - How can I get a list of all functions stored in the database of a particular schema in PostgreSQL? 如何更改PostgreSQL中任何列中所有出现的特定值? - How can I change all occurrences of a particular value in any column in PostgreSQL? 如何将 substring 值插入 PostgreSQL 中的 json 列? - How to insert with substring values into json column in PostgreSQL? 如何转置 postgresql 中的表值? - How can I transpose table values in postgresql? 如何使用条件截断 postgreSQL 表 - How to Truncate a postgreSQL table with conditions 在PostgreSQL数据库的所有模式中的表中添加一列 - Add a column to a table in all schemas of a PostgreSQL database 如何将数据从一个 PostgreSQL 数据库迁移到另一个(表/列名略有不同)? - How can I migrate data from one PostgreSQL database to another (with slightly different table/column names)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM