Skip to content

Instantly share code, notes, and snippets.

@workmaster2n
Created November 4, 2013 22:28
Show Gist options
  • Select an option

  • Save workmaster2n/7310317 to your computer and use it in GitHub Desktop.

Select an option

Save workmaster2n/7310317 to your computer and use it in GitHub Desktop.
integer issues
SELECT * FROM tracked_points
INNER JOIN tags ON tags.frequency = tracked_points.frequency
INNER JOIN worker_tags ON worker_tags.tag_id = tags.id
ORDER BY recorded_at DESC LIMIT 100
CREATE TABLE public.tags
(
id integer NOT NULL DEFAULT nextval('tags_id_seq'::regclass),
frequency integer,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
CONSTRAINT tags_pkey PRIMARY KEY (id)
)
CREATE TABLE public.tracked_points
(
id integer NOT NULL DEFAULT nextval('tracked_points_id_seq'::regclass),
recorded_at timestamp without time zone,
worker_id integer,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
location_id integer NOT NULL,
session_id integer,
frequency integer,
worker_id_checked_at timestamp without time zone,
zone_checked_at timestamp without time zone,
CONSTRAINT tracked_points_pkey PRIMARY KEY (id)
)
UPDATE tracked_points SET worker_id = worker_tags.worker_id
FROM tags LEFT JOIN worker_tags ON tags.id = worker_tags.tag_id
WHERE (tags.frequency = tracked_points.frequency OR worker_tags.id IS NULL)
AND tracked_points.worker_id_checked_at IS NULL
CREATE TABLE public.worker_tags
(
id integer NOT NULL DEFAULT nextval('worker_tags_id_seq'::regclass),
worker_id integer,
tag_id integer,
start_at timestamp without time zone,
end_at timestamp without time zone,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
CONSTRAINT worker_tags_pkey PRIMARY KEY (id)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment