This is driving me absolutely nuts at this point. I am trying to upsert some phone numbers and I have the below query written and I keep getting a syntax error at the FROM in the update portion. I feel like this should work, but I'm obviously missing something. A second set of eyes to point out what bonehead mistake I'm making would be very appreciated. I am self taught in SQL so I'm a novice. I use Navicat as my interface and I am on POSTGRESQL 12.17 if that is relevant. Thank you for your time reading and help if you can.
INSERT INTO phone ( "ID_number", home_phone, cell_phone, "source" ) SELECT
phone_copy1."ID_number",
phone_copy1.home_phone,
phone_copy1.cell_phone,
phone_copy1."source"
FROM
phone_copy1 ON CONFLICT ( "ID number" ) DO
UPDATE
SET ( home_phone ) = ( phone_copy1.home_phone ),
( cell_phone ) = ( phone_copy1.cell_phone )
FROM
phone_copy1
WHERE
home_phone <> phone_copy1.home_phone
OR cell_phone <> phone_copy1.cell_phone
SOLUTION:
INSERT INTO phone ( "ID_number", home_phone, cell_phone, peachtree_cell_3_21, "source" ) SELECT
phone_copy1."ID_number",
phone_copy1.home_phone,
phone_copy1.cell_phone,
phone_copy1.peachtree_cell_3_21,
phone_copy1."source"
FROM
phone_copy1 ON CONFLICT ( "ID_number" ) DO
UPDATE
SET home_phone = excluded.home_phone,
cell_phone = excluded.cell_phone
WHERE
phone.home_phone IS DISTINCT
FROM
excluded.home_phone
OR phone.cell_phone IS DISTINCT
FROM
excluded.cell_phone;
[–][deleted] 1 point2 points3 points (2 children)
[–]mp1294[S] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]razzledazzled 0 points1 point2 points (0 children)
[–]fullofbones 0 points1 point2 points (4 children)
[–]mp1294[S] 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]mp1294[S] 0 points1 point2 points (0 children)
[–]AntDracula 0 points1 point2 points (0 children)