Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I truncate (substring) all values for a particular column of a table in a PostgreSQL database?

I'm fairly new to 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.

I'm quite familiar with mySql but I'm having a harder time picking up PostgreSQL.

If this was mySql I would so something like:

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

How can I accomplish the same thing with PostgreSQL?

I have phppgadmin and the commmand line at my disposal.

like image 635
cwd Avatar asked Jan 15 '23 02:01

cwd


1 Answers

Actually, it's 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's the doc about the string functions in postgresql

like image 110
Marc Avatar answered Jan 29 '23 20:01

Marc