问题
Ho do I rewrite the following UPDATE statement into a Common Table Expressions (CTE's) format?
DB::statement('UPDATE taggables, threads SET taggables.created_at = threads.created_at, taggables.updated_at = threads.updated_at WHERE taggables.thread_id = threads.id');
回答1:
I don't really see the point for using a CTE here. Since it seems like your purpose is to update taggables
from threads
, I would suggest simply using Postgres' update/join syntax, which goes like:
update taggables ta
set created_at = th.created_at, updated_at = th.updated_at
from threads th
where ta.thread_id = th.id
来源:https://stackoverflow.com/questions/60416996/how-to-write-an-update-query-for-multiple-tables-in-common-table-expressions-ct