Skip to content

Instantly share code, notes, and snippets.

@pypt
Created July 8, 2016 19:02
Show Gist options
  • Save pypt/b153b7b4895c0d336ef267833774bfa4 to your computer and use it in GitHub Desktop.
Save pypt/b153b7b4895c0d336ef267833774bfa4 to your computer and use it in GitHub Desktop.
story_sentences "UPDATE-then-INSERT" with media_id = 26
WITH new_sentences (disable_triggers, language, media_id, publish_date, sentence, sentence_number, stories_id) AS (VALUES
-- New sentences to potentially insert
(FALSE, 'sk', 26, '2013-09-19 07:00:00'::timestamp, 'GM McKenzie praises Pryor', 0, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'ALAMEDA – An eventful Raiders offseason orchestrated by general manager Reggie McKenzie included a trade for a starting quarterback with arm trouble and Al Davis'' final draft pick taking the helm behind center.', 1, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'McKenzie also drafted a quarterback in the fourth round and cut him in favor of an undrafted free agent.', 2, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'And he is fine with that.', 3, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'Talking with reporters Wednesday for the first time since training camp began in late July, McKenzie made it clear he''s willing to adjust on the fly to put the best 53 players on the roster.', 4, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'When Terrelle Pryor takes the field Monday night against the Denver Broncos, McKenzie can hardly wait to see what happens next.', 5, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, '"I think he energizes more than just the fan base," McKenzie said.', 6, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, '"He energizes his teammates and anybody that''s watching.', 7, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'Everybody likes to see big plays.', 8, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'And he''s a big-play guy."', 9, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'The Raiders'' housecleaning was so thorough it invited speculation that McKenzie was sweeping out anybody associated with the previous regime.', 10, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'A sign held by a fan at O.co Coliseum had a photo of Pryor and Davis with the message "Al was right."', 11, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'McKenzie said it''s more about being good than being right.', 12, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, '"Good players will stay here.', 13, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'Point blank," McKenzie said.', 14, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, '"It''s not about driving off players who were here and bringing in our own guys.', 15, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'It''s about trying to put together a good nucleus and core group of guys and then funnel in players that can complement them and put together the best team.', 16, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, '"Whoever plays will be whoever the coach thinks gives us the best chance to win.', 17, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'And that''s what it''s all about."', 18, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'McKenzie said Pryor has progressed "by leaps and bounds" since last season and said Matt Flynn, the projected starter at quarterback entering training camp, was slowed by a sore throwing elbow.', 19, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, '"His arm didn''t fare him well in the preseason," McKenzie said.', 20, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'Although Flynn had similar arm issues the previous preseason with Seattle, McKenzie said "it wasn''t a major concern" at the time of the trade in April, adding, "If it was, we probably would have looked into it deeper."', 21, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'As for cutting quarterback Tyler Wilson, the highest-drafted player to be waived by an NFL team, McKenzie said he was simply beaten out by undrafted rookie Matt McGloin.', 22, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'Wilson cleared waivers and is on the Raiders'' practice squad.', 23, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, '"The best man wins," McKenzie said.', 24, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, '"But we have Tyler here, and he''s here to learn and get better.', 25, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'We see him as a down-the-line player for us."', 26, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, '© Copyright The Sacramento Bee.', 27, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'All rights reserved.', 28, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, '• Read more articles by Jerry McDonald', 29, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'What You Should Know About Comments on Sacbee.com', 30, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'Sacbee.com is happy to provide a forum for reader interaction, discussion, feedback and reaction to our stories.', 31, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'However, we reserve the right to delete inappropriate comments or ban users who can''t play nice.', 32, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, '( See our full terms of service here. )', 33, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'Here are some rules of the road:', 34, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, '• Keep your comments civil.', 35, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'Don''t insult one another or the subjects of our articles.', 36, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'If you think a comment violates our guidelines click the "Report Abuse" link to notify the moderators.', 37, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'Responding to the comment will only encourage bad behavior.', 38, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, '• Don''t use profanities, vulgarities or hate speech.', 39, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'This is a general interest news site.', 40, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'Sometimes, there are children present.', 41, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'Don''t say anything in a way you wouldn''t want your own child to hear.', 42, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, '• Do not attack other users; focus your comments on issues, not individuals.', 43, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, '• Stay on topic.', 44, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'Only post comments relevant to the article at hand.', 45, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, '• Do not copy and paste outside material into the comment box.', 46, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, '• Don''t repeat the same comment over and over.', 47, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'We heard you the first time.', 48, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, '• Do not use the commenting system for advertising.', 49, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'That''s spam and it isn''t allowed.', 50, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, '• Don''t use all capital letters.', 51, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'That''s akin to yelling and not appreciated by the audience.', 52, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, '• Don''t flag other users'' comments just because you don''t agree with their point of view.', 53, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'Please only flag comments that violate these guidelines.', 54, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'You should also know that The Sacramento Bee does not screen comments before they are posted.', 55, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'You are more likely to see inappropriate comments before our staff does, so we ask that you click the "Report Abuse" link to submit those comments for moderator review.', 56, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'You also may notify us via email at feedback@sacbee.com.', 57, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'Note the headline on which the comment is made and tell us the profile name of the user who made the comment.', 58, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'Remember, comment moderation is subjective.', 59, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'You may find some material objectionable that we won''t and vice versa.', 60, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'If you submit a comment, the user name of your account will appear along with it.', 61, 156642155),
(FALSE, 'en', 26, '2013-09-19 07:00:00'::timestamp, 'Users cannot remove their own comments once they have submitted them.', 62, 156642155)
),
duplicate_sentences AS (
-- Either a list of duplicate sentences already found in the table
-- or an empty list if deduplication is disabled
UPDATE story_sentences
SET is_dup = 't',
disable_triggers = 't'
FROM new_sentences
WHERE half_md5(story_sentences.sentence) = half_md5(new_sentences.sentence)
AND week_start_date( story_sentences.publish_date::date )
= week_start_date( new_sentences.publish_date::date )
AND story_sentences.media_id = new_sentences.media_id
RETURNING story_sentences.sentence
)
INSERT INTO story_sentences (disable_triggers, language, media_id, publish_date, sentence, sentence_number, stories_id)
SELECT disable_triggers, language, media_id, publish_date, sentence, sentence_number, stories_id
FROM new_sentences
WHERE sentence NOT IN (
-- Skip the ones for which we've just set is_dup = 't'
SELECT sentence
FROM duplicate_sentences
)
RETURNING story_sentences.sentence
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment