I
I
Ivan Hrushka2018-09-10 17:21:02
PostgreSQL
Ivan Hrushka, 2018-09-10 17:21:02

How to build an update query in postgressql?

I sometimes have the following entries in my database: city | ('JACKSONVILLE',) - you need to remove the brackets so that the result is - city | JACKSONVILLE
how to write such an update request?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Kuznetsov, 2018-09-11
@DarkRaven

update table_name set column_name  = 'city | JACKSONVILLE'
where id in (select id from table_name where column_name = 'city | (''JACKSONVILLE'',)')

In general, if there are different combinations and there are a lot of them, just update on
where ... like '%JACKSONVILLE%', but be sure to check that there is no 'JACKSONVILLE', 'BLAH2' , etc. there.
So, to summarize, to update these records, you need to get their id and simply execute a query like
update table_name set column_name  = 'city | JACKSONVILLE'
where id in (...)
,
where ...is a list of row IDs to be updated, separated by commas, for example 1,3,8.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question