update one column based on query containing another (joined) table Consider the following select query:

SELECT s.id, s.event, s.column, e.oldcolumn
FROM section as s
INNER JOIN event as e
ON s.event = e.id
WHERE s.id = 1


Now I wish to update the section table so that the values are equal to the oldcolumn from the event table.

I tried:

UPDATE public."section"
SET public."section".column = public."event".oldcolumn
FROM public."section"
INNER JOIN public."event"
on public."section".event = public."event".id
WHERE s.id = 1


However this, on postgresql, returned the following error:

ERROR:  table name "section" specified more than once
SQL state: 42712


How would I do such a thing, using joins inside an update query?
Disclaimer, I don't use PostgreSQL but I'm pretty familiar with SQL Server.

From what I understand in the PostgreSQL documentation here, I think the error you are getting is caused by the inclusion of public."section" INNER JOIN in your FROM statement. When using UPDATE you specify the table you are updating so adding public."section" in the FROM is not necessary. Per the documentation "Do not repeat the target table as a from_item unless you intend a self-join (in which case it must appear with an alias in the from_item)."

If you change your code to what I have below, I think it would resolve your issue. Though I'm not sure about the quotation marks you have, I just copied your format. The main difference being, only have the tables you're joining to in the FROM and move the ON to the WHERE.

UPDATE public."section"
SET public."section".column = public."event".oldcolumn
FROM public."event"
WHERE public."section".event = public."event".id AND public."section".id = 1