-8
I need to make a query to update a column, but you should only update the column if the data to be updated does not currently exist in that column.
-8
I need to make a query to update a column, but you should only update the column if the data to be updated does not currently exist in that column.
4
The ideal is to leave the field UNIQUE
, but if for some reason you need to do it, you can use a query similar to this:
UPDATE
suatabela
SET
seucampo = 'seuvalor'
WHERE
seucampo NOT IN (SELECT
COUNT(seucampo)
FROM
suatabela
WHERE
seucampo = 'seuvalor')
Check if value exists before you update, this is what I want to do
this is not what I want
Browser other questions tagged postgresql
You are not signed in. Login or sign up in order to post.
If there is no?
– Maniero
simply does nothing, I just want to udpate if this does not exist in the table already, I am able to arrange with update if not exist Insert
– Miguel Lourenço
From what I understand what you want is a
INSERT
if the record does not exist in the table.– Guilherme Lautert
no, I want to update a field. but I don’t want repeated values.
– Miguel Lourenço
Specify. Give an example of what you want. If you don’t want repeated values in a column, then determine that it should be
UNIQUE
.– Maniero
Hello Miguel! Welcome to Stack Overflow. Please make a tour to know how to get better answers. Your question is a little confusing, you need to drill in better. Put the SQL command you tried to do, an example of how you would like the information to be after the update, etc. We need more information to help you.
– Dherik
we have a table with this data Joao Luis and Joao Sousa, I want to update to Joao Luis I want to change also to Joao Sousa but will only make this update if the table does not exist if there is nothing.
– Miguel Lourenço
@Let me get this straight, you want to update a column of a table only if the value to be updated does not currently exist in that column of the table. Would that be?
– Erlon Charles
@Erloncharles yes that’s it! Thank you
– Miguel Lourenço