Skip to content

Instantly share code, notes, and snippets.

@judell
Created September 10, 2024 20:30
Show Gist options
  • Save judell/9b5d60bee6b780aafd145556d552a926 to your computer and use it in GitHub Desktop.
Save judell/9b5d60bee6b780aafd145556d552a926 to your computer and use it in GitHub Desktop.
hn_mentions
query "mentions" {
sql = <<EOQ
with names as (
select
unnest( $1::text[] ) as name
),
counts as (
select
name,
(
select
count(*)
from
hn
where
title ~* name
and (extract(epoch from now() - time::timestamptz) / 60)::int between symmetric $2 and $3
) as mentions
from
names
)
select
replace(name, '\', '') as name,
mentions
from
counts
where
mentions > 0
order by
mentions desc
EOQ
param "names" {}
param "min_minutes_ago" {}
param "max_minutes_ago" {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment