Wednesday, April 06, 2022

bulk replacing descriptions

In our local database, using phpPgAdmin, got an sql prompt by choosing a Select and Edit SQL, then the following query worked:

SELECT "fileid","description","languageid" FROM "public"."file_information" WHERE "description" LIKE 'Our Descrip%' AND "languageid" = '1'

Edited SQL to

update "public"."file_information" set "description"
REPLACE(description,'Our Descrip', 'Prefix to Our Descrip') 
WHERE "description" LIKE 'Our Descrip%' AND "languageid" = '1'

(trying this with a view instead of a table did not work, 
ERROR:  cannot update a view
HINT:  You need an unconditional ON UPDATE DO INSTEAD rule.)

For the remote database, tried a similar query, but it failed. phpMyAdmin had a find/replace option, so used that, and the corresponding query, which has single back-quotes, was:
UPDATE `our_table_name` SET `description` = REPLACE(`description`, 'Our Descrip', 'Prefix to Our Descrip') WHERE `description` LIKE 'Our Descrip%' COLLATE utf8mb4_bin

No comments:

Post a Comment