Reputation: 393
I have two tables
Table 1 :
CREATE TABLE public.my_line
(
id bigint NOT NULL,
geom geometry,
name character varying(254) COLLATE pg_catalog."default",
CONSTRAINT my_line_pkey PRIMARY KEY (id)
)
Table 2 :
CREATE TABLE public.ligne
(
id integer NOT NULL DEFAULT nextval('ligne_id_seq'::regclass),
name text COLLATE pg_catalog."default",
geom geometry,
CONSTRAINT ligne_pkey PRIMARY KEY (id)
)
I update the second by the first, like this :
update ligne set
name = my_line.name
from my_line
where ligne.id = my_line.id
It works good, but what I want to do is being able to update just the rows that make difference between the two tables. If you have an idea in-light me. Cordially.
Upvotes: 0
Views: 24
Reputation: 7656
You need to check whether they are different in your WHERE
clause. Try it like this:
UPDATE ligne
SET name = my_line.name
FROM my_line
WHERE ligne.id = my_line.id
AND ligne.name <> my_line.name
-- and whatever else you want to check for
Upvotes: 1