Search code examples
databasepostgresqlsql-updateinsert-update

PostgreSQL UPDATE "insert" infront of existing data


UPDATE table  
SET column = **`insert in front of original data`**  
WHERE condition

Is it possible to insert data in front or at the end?
Or it has to be rewritten all over again?


Solution

  • If I understand you correctly, column is a column containing string data, and you want to prepend text in front of the current value of the column, for each record satisfying the condition?

    In that case, just do the following:

    UPDATE table
    SET column = 'my prepended text' || column
    WHERE condition