R
R
Rinat Bakiev2016-12-20 10:14:52
PostgreSQL
Rinat Bakiev, 2016-12-20 10:14:52

Is it possible to do an UPDATE (SQL) with the output which rows were not found?

Hello!
I have a list in table surname and name in excel. Using the concatenate formula, I form the following query:
UPDATE table_name SET surname='surname' WHERE name='name'
There are 6000 rows in the table, 5000 in the base. Is it possible to get a list of which name could not be updated? Well, or just how to make a comparison, but with the output of what is not in the list?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
terrier, 2016-12-20
@terrier

Well, actually load the full list of names into the table (let's say from_excel ) and go

with updated as
( update table_name surname='surname' WHERE name='name'  returning name )
select name from from_excel where name not in ( select name from updated );

F
Falseclock, 2017-02-19
@Falseclock

You make a temporary table, unload unique identifiers into it, then do an update with the return of UPDATE from bla bla bla RETURNING, which you join with the unloaded data into the temporary.
You can do without a temporary table, but the query will have a lot of nesting.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question