Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joebartels/06658384afbf2f182b30cc89f0e3fea8 to your computer and use it in GitHub Desktop.
Save joebartels/06658384afbf2f182b30cc89f0e3fea8 to your computer and use it in GitHub Desktop.
updating table entries with subquery
with date_fields as (
select id,
extract(dow from date) as day_of_week,
extract(hour from date) as hour_of_day,
extract(minute from date) as minute_of_hour
from cycling_entry
)
update cycling_entry
set day_of_week=subquery.day_of_week,
hour_of_day=subquery.hour_of_day,
minute_of_hour=subquery.minute_of_hour
from (
select * from date_fields
) as subquery
where cycling_entry.id = subquery.id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment