user2964140
user2964140

Reputation: 101

PostgreSQL update statement to substring a column value

Considering XPT table containing the following values:

123, 443, 213, 124

I want to update it remove the last character of each number in order to get it like this:

12, 44, 21, 12

Upvotes: 0

Views: 1696

Answers (1)

sagi
sagi

Reputation: 40481

Use SUBSTRING() function:

SELECT SUBSTRING(t.value, 1, 2)
    FROM XPT t;

Or if you want to update:

UPDATE XPT t
    SET t.value = SUBSTRING(t.value, 1, 2);

Upvotes: 1

Related Questions