How can I trim (fine-tune) all values ​​for a specific column of a table in a PostgreSQL database?

I am new to PostgreSQL. I am working with a table in which there was no maximum length (number of characters) entered in the "title" column. The application should be less than 1000 characters, but some fields are located at 1200, 1300, etc.

I am very familiar with mySql, but it is harder for me to type PostgreSQL.

If it was mySql, I would like something like:

UPDATE TABLE entries SET title = LEFT(title,1000) 

How can I do the same with PostgreSQL?

I have phppgadmin and the commmand line at my disposal.

+4
source share
2 answers

Actually, this is the same in 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 is a document on string functions in postgresql

+4
source

In PostgreSQL, it could be:

 UPDATE TABLE entries SET title = substring(title from 1 for 1000) 

From pg documentation :

substring(string [from int] [for int]) function substring(string [from int] [for int])
Description of Extract substring
Example substring('Thomas' from 2 for 3)
Result hom

+3
source

Source: https://habr.com/ru/post/1444446/


All Articles