Skip to content

Hacker News

Hacker News front page, stories, comment threads and users

Connector software
Free and open source
Service credentials
Not needed
Use with an agent

Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.

npx skills add Query-farm/vgi-skills --skill orchard

Copy this request into your coding agent to get started.

Use https://query.farm/products/orchard/connectors/hackernews/index.md to help me query Hacker News with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.

Read today’s top stories and discussion counts

Example output Β· captured
Connector release
v0.4.0
Engine
2.0.1
VGI protocol
3.4.0
SELECT rank, title, score, descendants AS comments
FROM hackernews.main.top_stories
ORDER BY rank
LIMIT 30
Result Β· first 5 rows
rank title score comments
1 Initial Assessment of Anthropic's Findings on Lattice Cryptography 488 281
2 Best Buy will officially sell physical media in stores again 335 208
3 Cloudflare Clairic System One Extraction Models Are Now Open-Weight 60 13
4 Galactic quasi-polynomial quantum algorithms for integral and module lattices [… 225 114
5 Red heads are linked to a mutation that makes them resistant to anesthesia (202… 96 66

Quick start

Choose where to run Hacker News, then follow the steps below.

The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.

1. Install the vgi extension

Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.

setup.sql
SET allow_extension_repositories = 'allowed';

CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
    WITH PREFIX 'https://duckdb-extensions.query.farm';

INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;

2. Attach the connector

Attach with uvx

Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.

ATTACH 'hackernews' AS hackernews (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-hackernews'
);

3. Run a query

query.sql
SELECT rank, title, score, descendants AS comments
FROM hackernews.main.top_stories
ORDER BY rank
LIMIT 30
More example queries β†’
Technical details
Verified connector release
v0.4.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
Pin a version for production

When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.

Attach with uvx

Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.

ATTACH 'hackernews' AS hackernews (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-hackernews'
);

Overview

Hacker News front page, stories, comment threads and user profiles, read live from the official API

Catalog

Everything hackernews exposes once attached β€” read straight from the worker's released build.

hackernews 1 schema
main 9 tables Β· 7 functions

Live, read-only Hacker News data from the public Firebase API β€” no credentials required

Schema examples (7)
Examples (7)

The front page right now, with each story's discussion size

SELECT rank, title, score, descendants AS comments
FROM hackernews.main.top_stories
ORDER BY rank
LIMIT 30;
Result Β· first 5 rows
rank title score comments
1 Initial Assessment of Anthropic's Findings on Lattice Cryptography 488 281
2 Best Buy will officially sell physical media in stores again 335 208
3 Cloudflare Clairic System One Extraction Models Are Now Open-Weight 60 13
4 Galactic quasi-polynomial quantum algorithms for integral and module lattices [… 225 114
5 Red heads are linked to a mutation that makes them resistant to anesthesia (202… 96 66

Which sites dominate the front page

SELECT regexp_extract(url, '^https?://(?:www\.)?([^/]+)', 1) AS site,
  count(*) AS stories
FROM hackernews.main.top_stories
WHERE url IS NOT NULL
GROUP BY site
ORDER BY stories DESC, site
LIMIT 15;

Read the whole discussion of the current top story, as displayed

SELECT depth, author, hackernews.main.html_to_text(text) AS comment
FROM hackernews.main.comments((SELECT id FROM hackernews.main.top_stories WHERE rank = 1))
WHERE NOT deleted
ORDER BY path;

The karma of each front-page poster

SELECT s.rank, s.author, u.karma
FROM (SELECT rank, author FROM hackernews.main.top_stories WHERE rank <= 30) s,
     LATERAL hackernews.main.user(s.author, cache_ttl => 300) u
ORDER BY s.rank;
3 more examples

Front-page stories the change feed lists as active right now (new votes, replies or edits), with their current score and comment count

SELECT t.rank, t.title, u.score, u.descendants AS comments
FROM hackernews.main.top_stories t
JOIN hackernews.main.updated_items u USING (id)
ORDER BY t.rank;

The busiest commenters among the newest 300 items site-wide, with their karma and account age

SELECT r.author, count(*) AS comments, u.karma, u.created_at AS joined
FROM (SELECT author FROM hackernews.main.recent_items(300) WHERE type = 'comment' AND author IS NOT NULL) r,
     LATERAL hackernews.main.user(r.author, cache_ttl => 300) u
GROUP BY r.author, u.karma, u.created_at
ORDER BY comments DESC, r.author
LIMIT 10;

Who and what a user's latest comments were replying to

SELECT c.created_at, p.type AS replying_to, p.author AS to_whom,
  coalesce(p.title, hackernews.main.html_to_text(p.text)) AS what
FROM (SELECT * FROM hackernews.main.submissions('dang') LIMIT 20) c,
     LATERAL hackernews.main.item(c.parent) p
WHERE c.type = 'comment'
ORDER BY c.created_at DESC;
Tables
ask_stories 1 example16 cols

Ask HN questions currently listed, as the Ask HN page ranks them

Columns
ranknot null INTEGER
1-based position in the list when it was read; 1 is the top slot. Positions move from one read to the next, so the rank is a snapshot, not an identity.
idnot null BIGINT
Unique item id, assigned in increasing order across every kind of item; the key item() and comments() take, and the value kids, parent, poll and parts refer to.
type VARCHAR
What the item is: 'story', 'comment', 'job', 'poll' or 'pollopt' (one option of a poll). Ask HN and Show HN posts are stories.
author VARCHAR
Username of whoever posted it (the API's `by` field); the key user() takes. NULL on deleted items.
created_at TIMESTAMP WITH TIME ZONE
When the item was posted, as a UTC instant (the API's `time`, in Unix seconds).
title VARCHAR
Headline of a story, poll or job, as plain text. NULL for comments and poll options.
url VARCHAR
Address a link story points to. NULL for text posts such as Ask HN, and for comments.
text VARCHAR
Body of a comment, text post, job or poll option, as HTML: entity-escaped, with <p> paragraph breaks and <a> links. html_to_text() turns it into plain text. NULL when the item has no body.
score BIGINT
Points (net upvotes) on a story, poll or job, or the number of votes cast for a poll option. NULL for comments, whose scores Hacker News does not publish.
descendants BIGINT
Number of live comments in the whole thread under a story or poll, at every depth (deleted and dead comments are not counted). NULL for other item types.
parent BIGINT
Id of the item a comment replies to (another comment, or the story at the top of the thread). NULL for anything that is not a comment.
poll BIGINT
For a poll option, the item id of the poll (its parent). NULL otherwise.
kids BIGINT[]
Ids of the direct replies, in the ranked order Hacker News displays them. Empty when there are none.
parts BIGINT[]
For a poll, the ids of its options in display order. NULL for other item types.
deleted BOOLEAN
Whether the item was deleted. A deleted item keeps its id, type and place in its thread but loses its author and body. Never NULL.
dead BOOLEAN
Whether the item is dead: killed by moderators or flags, and hidden from readers who have not opted in to seeing it. Never NULL.
ConstraintsUNIQUE (rank) Β· PRIMARY KEY (id)
Example

The Ask HN questions drawing the most answers

SELECT title, descendants AS answers,
  hackernews.main.html_to_text(text) AS question
FROM hackernews.main.ask_stories
ORDER BY answers DESC
LIMIT 10;
Link
best_stories 1 example16 cols

Hacker News' 'best' list: the highest-voted recent stories

Columns
ranknot null INTEGER
1-based position in the list when it was read; 1 is the top slot. Positions move from one read to the next, so the rank is a snapshot, not an identity.
idnot null BIGINT
Unique item id, assigned in increasing order across every kind of item; the key item() and comments() take, and the value kids, parent, poll and parts refer to.
type VARCHAR
What the item is: 'story', 'comment', 'job', 'poll' or 'pollopt' (one option of a poll). Ask HN and Show HN posts are stories.
author VARCHAR
Username of whoever posted it (the API's `by` field); the key user() takes. NULL on deleted items.
created_at TIMESTAMP WITH TIME ZONE
When the item was posted, as a UTC instant (the API's `time`, in Unix seconds).
title VARCHAR
Headline of a story, poll or job, as plain text. NULL for comments and poll options.
url VARCHAR
Address a link story points to. NULL for text posts such as Ask HN, and for comments.
text VARCHAR
Body of a comment, text post, job or poll option, as HTML: entity-escaped, with <p> paragraph breaks and <a> links. html_to_text() turns it into plain text. NULL when the item has no body.
score BIGINT
Points (net upvotes) on a story, poll or job, or the number of votes cast for a poll option. NULL for comments, whose scores Hacker News does not publish.
descendants BIGINT
Number of live comments in the whole thread under a story or poll, at every depth (deleted and dead comments are not counted). NULL for other item types.
parent BIGINT
Id of the item a comment replies to (another comment, or the story at the top of the thread). NULL for anything that is not a comment.
poll BIGINT
For a poll option, the item id of the poll (its parent). NULL otherwise.
kids BIGINT[]
Ids of the direct replies, in the ranked order Hacker News displays them. Empty when there are none.
parts BIGINT[]
For a poll, the ids of its options in display order. NULL for other item types.
deleted BOOLEAN
Whether the item was deleted. A deleted item keeps its id, type and place in its thread but loses its author and body. Never NULL.
dead BOOLEAN
Whether the item is dead: killed by moderators or flags, and hidden from readers who have not opted in to seeing it. Never NULL.
ConstraintsUNIQUE (rank) Β· PRIMARY KEY (id)
Example

The ten highest-scoring stories of the last few days

SELECT title, score, descendants AS comments
FROM hackernews.main.best_stories
ORDER BY score DESC
LIMIT 10;
Link
job_stories 1 example16 cols

Job ads from Y Combinator companies currently on the Hacker News jobs page

Columns
ranknot null INTEGER
1-based position in the list when it was read; 1 is the top slot. Positions move from one read to the next, so the rank is a snapshot, not an identity.
idnot null BIGINT
Unique item id, assigned in increasing order across every kind of item; the key item() and comments() take, and the value kids, parent, poll and parts refer to.
type VARCHAR
What the item is: 'story', 'comment', 'job', 'poll' or 'pollopt' (one option of a poll). Ask HN and Show HN posts are stories.
author VARCHAR
Username of whoever posted it (the API's `by` field); the key user() takes. NULL on deleted items.
created_at TIMESTAMP WITH TIME ZONE
When the item was posted, as a UTC instant (the API's `time`, in Unix seconds).
title VARCHAR
Headline of a story, poll or job, as plain text. NULL for comments and poll options.
url VARCHAR
Address a link story points to. NULL for text posts such as Ask HN, and for comments.
text VARCHAR
Body of a comment, text post, job or poll option, as HTML: entity-escaped, with <p> paragraph breaks and <a> links. html_to_text() turns it into plain text. NULL when the item has no body.
score BIGINT
Points (net upvotes) on a story, poll or job, or the number of votes cast for a poll option. NULL for comments, whose scores Hacker News does not publish.
descendants BIGINT
Number of live comments in the whole thread under a story or poll, at every depth (deleted and dead comments are not counted). NULL for other item types.
parent BIGINT
Id of the item a comment replies to (another comment, or the story at the top of the thread). NULL for anything that is not a comment.
poll BIGINT
For a poll option, the item id of the poll (its parent). NULL otherwise.
kids BIGINT[]
Ids of the direct replies, in the ranked order Hacker News displays them. Empty when there are none.
parts BIGINT[]
For a poll, the ids of its options in display order. NULL for other item types.
deleted BOOLEAN
Whether the item was deleted. A deleted item keeps its id, type and place in its thread but loses its author and body. Never NULL.
dead BOOLEAN
Whether the item is dead: killed by moderators or flags, and hidden from readers who have not opted in to seeing it. Never NULL.
ConstraintsUNIQUE (rank) Β· PRIMARY KEY (id)
Example

Current job ads, newest first

SELECT title, url, created_at
FROM hackernews.main.job_stories
ORDER BY created_at DESC;
Link
max_item 2 examples1 col

The id of the newest item on Hacker News, as a single row

Columns
idnot null BIGINT
Largest item id assigned so far, so the id of the newest item on the site. Ids are handed out in sequence, which also makes it a running count of everything posted.
ConstraintsPRIMARY KEY (id)
Examples (2)

The newest item on the site, fetched in full

SELECT i.type, i.author, i.created_at
FROM hackernews.main.max_item m,
     LATERAL hackernews.main.item(m.id) i;
SELECT id AS items_posted FROM hackernews.main.max_item();
Link
new_stories 1 example16 cols

The 500 most recently submitted Hacker News stories, newest first

Columns
ranknot null INTEGER
1-based position in the list when it was read; 1 is the top slot. Positions move from one read to the next, so the rank is a snapshot, not an identity.
idnot null BIGINT
Unique item id, assigned in increasing order across every kind of item; the key item() and comments() take, and the value kids, parent, poll and parts refer to.
type VARCHAR
What the item is: 'story', 'comment', 'job', 'poll' or 'pollopt' (one option of a poll). Ask HN and Show HN posts are stories.
author VARCHAR
Username of whoever posted it (the API's `by` field); the key user() takes. NULL on deleted items.
created_at TIMESTAMP WITH TIME ZONE
When the item was posted, as a UTC instant (the API's `time`, in Unix seconds).
title VARCHAR
Headline of a story, poll or job, as plain text. NULL for comments and poll options.
url VARCHAR
Address a link story points to. NULL for text posts such as Ask HN, and for comments.
text VARCHAR
Body of a comment, text post, job or poll option, as HTML: entity-escaped, with <p> paragraph breaks and <a> links. html_to_text() turns it into plain text. NULL when the item has no body.
score BIGINT
Points (net upvotes) on a story, poll or job, or the number of votes cast for a poll option. NULL for comments, whose scores Hacker News does not publish.
descendants BIGINT
Number of live comments in the whole thread under a story or poll, at every depth (deleted and dead comments are not counted). NULL for other item types.
parent BIGINT
Id of the item a comment replies to (another comment, or the story at the top of the thread). NULL for anything that is not a comment.
poll BIGINT
For a poll option, the item id of the poll (its parent). NULL otherwise.
kids BIGINT[]
Ids of the direct replies, in the ranked order Hacker News displays them. Empty when there are none.
parts BIGINT[]
For a poll, the ids of its options in display order. NULL for other item types.
deleted BOOLEAN
Whether the item was deleted. A deleted item keeps its id, type and place in its thread but loses its author and body. Never NULL.
dead BOOLEAN
Whether the item is dead: killed by moderators or flags, and hidden from readers who have not opted in to seeing it. Never NULL.
ConstraintsUNIQUE (rank) Β· PRIMARY KEY (id)
Example

The newest submissions that are already drawing votes

SELECT title, author, score, created_at
FROM hackernews.main.new_stories
WHERE score > 1
ORDER BY created_at DESC
LIMIT 20;
Link
show_stories 1 example16 cols

Show HN posts currently listed: things members have built, as the Show HN page ranks them

Columns
ranknot null INTEGER
1-based position in the list when it was read; 1 is the top slot. Positions move from one read to the next, so the rank is a snapshot, not an identity.
idnot null BIGINT
Unique item id, assigned in increasing order across every kind of item; the key item() and comments() take, and the value kids, parent, poll and parts refer to.
type VARCHAR
What the item is: 'story', 'comment', 'job', 'poll' or 'pollopt' (one option of a poll). Ask HN and Show HN posts are stories.
author VARCHAR
Username of whoever posted it (the API's `by` field); the key user() takes. NULL on deleted items.
created_at TIMESTAMP WITH TIME ZONE
When the item was posted, as a UTC instant (the API's `time`, in Unix seconds).
title VARCHAR
Headline of a story, poll or job, as plain text. NULL for comments and poll options.
url VARCHAR
Address a link story points to. NULL for text posts such as Ask HN, and for comments.
text VARCHAR
Body of a comment, text post, job or poll option, as HTML: entity-escaped, with <p> paragraph breaks and <a> links. html_to_text() turns it into plain text. NULL when the item has no body.
score BIGINT
Points (net upvotes) on a story, poll or job, or the number of votes cast for a poll option. NULL for comments, whose scores Hacker News does not publish.
descendants BIGINT
Number of live comments in the whole thread under a story or poll, at every depth (deleted and dead comments are not counted). NULL for other item types.
parent BIGINT
Id of the item a comment replies to (another comment, or the story at the top of the thread). NULL for anything that is not a comment.
poll BIGINT
For a poll option, the item id of the poll (its parent). NULL otherwise.
kids BIGINT[]
Ids of the direct replies, in the ranked order Hacker News displays them. Empty when there are none.
parts BIGINT[]
For a poll, the ids of its options in display order. NULL for other item types.
deleted BOOLEAN
Whether the item was deleted. A deleted item keeps its id, type and place in its thread but loses its author and body. Never NULL.
dead BOOLEAN
Whether the item is dead: killed by moderators or flags, and hidden from readers who have not opted in to seeing it. Never NULL.
ConstraintsUNIQUE (rank) Β· PRIMARY KEY (id)
Example

The Show HN launches getting the strongest response

SELECT title, url, score, descendants AS comments
FROM hackernews.main.show_stories
ORDER BY score DESC
LIMIT 10;
Link
top_stories 1 example16 cols

The Hacker News front page ranking: up to 500 stories and job ads, in the order the site shows them

Columns
ranknot null INTEGER
1-based position in the list when it was read; 1 is the top slot. Positions move from one read to the next, so the rank is a snapshot, not an identity.
idnot null BIGINT
Unique item id, assigned in increasing order across every kind of item; the key item() and comments() take, and the value kids, parent, poll and parts refer to.
type VARCHAR
What the item is: 'story', 'comment', 'job', 'poll' or 'pollopt' (one option of a poll). Ask HN and Show HN posts are stories.
author VARCHAR
Username of whoever posted it (the API's `by` field); the key user() takes. NULL on deleted items.
created_at TIMESTAMP WITH TIME ZONE
When the item was posted, as a UTC instant (the API's `time`, in Unix seconds).
title VARCHAR
Headline of a story, poll or job, as plain text. NULL for comments and poll options.
url VARCHAR
Address a link story points to. NULL for text posts such as Ask HN, and for comments.
text VARCHAR
Body of a comment, text post, job or poll option, as HTML: entity-escaped, with <p> paragraph breaks and <a> links. html_to_text() turns it into plain text. NULL when the item has no body.
score BIGINT
Points (net upvotes) on a story, poll or job, or the number of votes cast for a poll option. NULL for comments, whose scores Hacker News does not publish.
descendants BIGINT
Number of live comments in the whole thread under a story or poll, at every depth (deleted and dead comments are not counted). NULL for other item types.
parent BIGINT
Id of the item a comment replies to (another comment, or the story at the top of the thread). NULL for anything that is not a comment.
poll BIGINT
For a poll option, the item id of the poll (its parent). NULL otherwise.
kids BIGINT[]
Ids of the direct replies, in the ranked order Hacker News displays them. Empty when there are none.
parts BIGINT[]
For a poll, the ids of its options in display order. NULL for other item types.
deleted BOOLEAN
Whether the item was deleted. A deleted item keeps its id, type and place in its thread but loses its author and body. Never NULL.
dead BOOLEAN
Whether the item is dead: killed by moderators or flags, and hidden from readers who have not opted in to seeing it. Never NULL.
ConstraintsUNIQUE (rank) Β· PRIMARY KEY (id)
Example

The first page of Hacker News, stories only

SELECT rank, title, score, descendants AS comments
FROM hackernews.main.top_stories
WHERE type = 'story'
ORDER BY rank
LIMIT 30;
Link
updated_items 3 examples16 cols

Items Hacker News reports as just changed β€” new replies, votes, edits β€” in their current state

Columns
ranknot null INTEGER
1-based position in the change feed as served; the feed is a rolling window of recent changes, not a ranking by importance.
idnot null BIGINT
Unique item id, assigned in increasing order across every kind of item; the key item() and comments() take, and the value kids, parent, poll and parts refer to.
type VARCHAR
What the item is: 'story', 'comment', 'job', 'poll' or 'pollopt' (one option of a poll). Ask HN and Show HN posts are stories.
author VARCHAR
Username of whoever posted it (the API's `by` field); the key user() takes. NULL on deleted items.
created_at TIMESTAMP WITH TIME ZONE
When the item was posted, as a UTC instant (the API's `time`, in Unix seconds).
title VARCHAR
Headline of a story, poll or job, as plain text. NULL for comments and poll options.
url VARCHAR
Address a link story points to. NULL for text posts such as Ask HN, and for comments.
text VARCHAR
Body of a comment, text post, job or poll option, as HTML: entity-escaped, with <p> paragraph breaks and <a> links. html_to_text() turns it into plain text. NULL when the item has no body.
score BIGINT
Points (net upvotes) on a story, poll or job, or the number of votes cast for a poll option. NULL for comments, whose scores Hacker News does not publish.
descendants BIGINT
Number of live comments in the whole thread under a story or poll, at every depth (deleted and dead comments are not counted). NULL for other item types.
parent BIGINT
Id of the item a comment replies to (another comment, or the story at the top of the thread). NULL for anything that is not a comment.
poll BIGINT
For a poll option, the item id of the poll (its parent). NULL otherwise.
kids BIGINT[]
Ids of the direct replies, in the ranked order Hacker News displays them. Empty when there are none.
parts BIGINT[]
For a poll, the ids of its options in display order. NULL for other item types.
deleted BOOLEAN
Whether the item was deleted. A deleted item keeps its id, type and place in its thread but loses its author and body. Never NULL.
dead BOOLEAN
Whether the item is dead: killed by moderators or flags, and hidden from readers who have not opted in to seeing it. Never NULL.
ConstraintsUNIQUE (rank) Β· PRIMARY KEY (id)
Examples (3)

Which stories are gaining activity right now

SELECT title, score, descendants AS comments
FROM hackernews.main.updated_items
WHERE type = 'story'
ORDER BY score DESC;

Front-page stories the change feed lists as active right now (new votes, replies or edits), with their current score and comment count

SELECT t.rank, t.title, u.score, u.descendants AS comments
FROM hackernews.main.top_stories t
JOIN hackernews.main.updated_items u USING (id)
ORDER BY t.rank;
SELECT type, count(*) AS changed
FROM hackernews.main.updated_items()
GROUP BY type
ORDER BY changed DESC;
Link
updated_users 2 examples6 cols

User profiles Hacker News reports as just changed, usually because their karma moved

Columns
ranknot null INTEGER
1-based position in the change feed as served; the feed is a rolling window of recent profile changes, not a ranking.
usernamenot null VARCHAR
Unique, case-sensitive username (the API's user `id`); what author holds on an item.
created_at TIMESTAMP WITH TIME ZONE
When the account was created, as a UTC instant.
karma BIGINT
Karma points (roughly the upvotes the user's stories and comments have received, less their downvotes).
about VARCHAR
Self-description from the profile, as HTML. NULL when blank.
submitted BIGINT[]
Ids of every story, comment, poll and job the user has posted, newest first. Can run to tens of thousands of ids; submissions() hydrates them a page at a time.
ConstraintsUNIQUE (rank) Β· PRIMARY KEY (username)
Examples (2)

Recently active users, by karma

SELECT username, karma, created_at, len(submitted) AS posts
FROM hackernews.main.updated_users
ORDER BY karma DESC;
SELECT username, karma, len(submitted) AS posts
FROM hackernews.main.updated_users()
ORDER BY karma DESC;
Link
Scalar functions
html_to_text (value VARCHAR) 2 examples

Turn Hacker News' HTML (comment bodies, text posts, profiles) into plain text

Arguments
value VARCHAR
HTML from an item's text or a user's about
ReturnsVARCHAR
Examples (2)

Decode a snippet of comment HTML

SELECT hackernews.main.html_to_text('Don&#x27;t <i>panic</i> &amp; carry on') AS plain;

Search comment text on a thread without tripping over HTML entities

SELECT id, author
FROM hackernews.main.comments(8863)
WHERE hackernews.main.html_to_text(text) ILIKE '%don''t%'
ORDER BY path;
Link
Table functions
comments (id BIGINT, max_depth := BIGINT) 3 examples

The whole discussion under a Hacker News story or comment, one row per reply

Positional arguments
id BIGINT
Id of the item whose replies to walk
Named arguments
max_depth := BIGINT
Deepest level of replies to include; 1 means direct replies only, 0 means no limit Β· default 0
Returns columns
root_id BIGINT
Id of the item whose thread this comment belongs to: the id comments() was called with.
depth INTEGER
Levels below the root item: 1 is a direct reply, 2 a reply to a reply, and so on.
path INTEGER[]
The comment's 1-based position among its siblings at each level from the root down, so sorting by path lists the thread exactly as Hacker News displays it.
id BIGINT
Unique item id, assigned in increasing order across every kind of item; the key item() and comments() take, and the value kids, parent, poll and parts refer to.
type VARCHAR
What the item is: 'story', 'comment', 'job', 'poll' or 'pollopt' (one option of a poll). Ask HN and Show HN posts are stories.
author VARCHAR
Username of whoever posted it (the API's `by` field); the key user() takes. NULL on deleted items.
created_at TIMESTAMP WITH TIME ZONE
When the item was posted, as a UTC instant (the API's `time`, in Unix seconds).
title VARCHAR
Headline of a story, poll or job, as plain text. NULL for comments and poll options.
url VARCHAR
Address a link story points to. NULL for text posts such as Ask HN, and for comments.
text VARCHAR
Body of a comment, text post, job or poll option, as HTML: entity-escaped, with <p> paragraph breaks and <a> links. html_to_text() turns it into plain text. NULL when the item has no body.
score BIGINT
Points (net upvotes) on a story, poll or job, or the number of votes cast for a poll option. NULL for comments, whose scores Hacker News does not publish.
descendants BIGINT
Number of live comments in the whole thread under a story or poll, at every depth (deleted and dead comments are not counted). NULL for other item types.
parent BIGINT
Id of the item a comment replies to (another comment, or the story at the top of the thread). NULL for anything that is not a comment.
poll BIGINT
For a poll option, the item id of the poll (its parent). NULL otherwise.
kids BIGINT[]
Ids of the direct replies, in the ranked order Hacker News displays them. Empty when there are none.
parts BIGINT[]
For a poll, the ids of its options in display order. NULL for other item types.
deleted BOOLEAN
Whether the item was deleted. A deleted item keeps its id, type and place in its thread but loses its author and body. Never NULL.
dead BOOLEAN
Whether the item is dead: killed by moderators or flags, and hidden from readers who have not opted in to seeing it. Never NULL.
Examples (3)

The Dropbox launch thread, read top to bottom

SELECT depth, author, hackernews.main.html_to_text(text) AS comment
FROM hackernews.main.comments(8863)
WHERE NOT deleted AND NOT dead
ORDER BY path;

Who talked most in the discussion of the current top story

SELECT author, count(*) AS comments
FROM hackernews.main.comments((SELECT id FROM hackernews.main.top_stories WHERE rank = 1))
WHERE author IS NOT NULL
GROUP BY author
ORDER BY comments DESC, author
LIMIT 10;

How many direct replies each of the top five stories has drawn

SELECT s.rank, s.title, count(c.id) AS replies
FROM (SELECT rank, id, title FROM hackernews.main.top_stories WHERE rank <= 5) s,
     LATERAL hackernews.main.comments(s.id, max_depth => 1) c
GROUP BY s.rank, s.title
ORDER BY s.rank;
Link
item (id BIGINT, cache_ttl := BIGINT) 3 examples

Look up any Hacker News story, comment, job or poll by its numeric id

Positional arguments
id BIGINT
Id of the item to fetch
Named arguments
cache_ttl := BIGINT
Seconds to cache each result (0 turns caching off) Β· default 0
Returns columns
id BIGINT
Unique item id, assigned in increasing order across every kind of item; the key item() and comments() take, and the value kids, parent, poll and parts refer to.
type VARCHAR
What the item is: 'story', 'comment', 'job', 'poll' or 'pollopt' (one option of a poll). Ask HN and Show HN posts are stories.
author VARCHAR
Username of whoever posted it (the API's `by` field); the key user() takes. NULL on deleted items.
created_at TIMESTAMP WITH TIME ZONE
When the item was posted, as a UTC instant (the API's `time`, in Unix seconds).
title VARCHAR
Headline of a story, poll or job, as plain text. NULL for comments and poll options.
url VARCHAR
Address a link story points to. NULL for text posts such as Ask HN, and for comments.
text VARCHAR
Body of a comment, text post, job or poll option, as HTML: entity-escaped, with <p> paragraph breaks and <a> links. html_to_text() turns it into plain text. NULL when the item has no body.
score BIGINT
Points (net upvotes) on a story, poll or job, or the number of votes cast for a poll option. NULL for comments, whose scores Hacker News does not publish.
descendants BIGINT
Number of live comments in the whole thread under a story or poll, at every depth (deleted and dead comments are not counted). NULL for other item types.
parent BIGINT
Id of the item a comment replies to (another comment, or the story at the top of the thread). NULL for anything that is not a comment.
poll BIGINT
For a poll option, the item id of the poll (its parent). NULL otherwise.
kids BIGINT[]
Ids of the direct replies, in the ranked order Hacker News displays them. Empty when there are none.
parts BIGINT[]
For a poll, the ids of its options in display order. NULL for other item types.
deleted BOOLEAN
Whether the item was deleted. A deleted item keeps its id, type and place in its thread but loses its author and body. Never NULL.
dead BOOLEAN
Whether the item is dead: killed by moderators or flags, and hidden from readers who have not opted in to seeing it. Never NULL.
Examples (3)

The Dropbox launch post, from 2007

SELECT title, author, created_at, url FROM hackernews.main.item(8863);

The top-level comments on the current number one story, in display order

SELECT k.position, c.author, hackernews.main.html_to_text(c.text) AS comment
FROM (SELECT unnest(kids) AS kid, generate_subscripts(kids, 1) AS position FROM hackernews.main.top_stories WHERE rank = 1) k,
     LATERAL hackernews.main.item(k.kid) c
ORDER BY k.position;

How a poll's votes split across its options

SELECT o.text AS option, o.score AS votes
FROM (SELECT unnest(parts) AS part FROM hackernews.main.item(126809)) p,
     LATERAL hackernews.main.item(p.part) o
ORDER BY votes DESC;
Link
recent_items (count BIGINT) 3 examples

The latest items posted anywhere on Hacker News, comments and stories alike

Arguments
count BIGINT
How many of the newest item ids to walk back through
Returns columns
id BIGINT
Unique item id, assigned in increasing order across every kind of item; the key item() and comments() take, and the value kids, parent, poll and parts refer to.
type VARCHAR
What the item is: 'story', 'comment', 'job', 'poll' or 'pollopt' (one option of a poll). Ask HN and Show HN posts are stories.
author VARCHAR
Username of whoever posted it (the API's `by` field); the key user() takes. NULL on deleted items.
created_at TIMESTAMP WITH TIME ZONE
When the item was posted, as a UTC instant (the API's `time`, in Unix seconds).
title VARCHAR
Headline of a story, poll or job, as plain text. NULL for comments and poll options.
url VARCHAR
Address a link story points to. NULL for text posts such as Ask HN, and for comments.
text VARCHAR
Body of a comment, text post, job or poll option, as HTML: entity-escaped, with <p> paragraph breaks and <a> links. html_to_text() turns it into plain text. NULL when the item has no body.
score BIGINT
Points (net upvotes) on a story, poll or job, or the number of votes cast for a poll option. NULL for comments, whose scores Hacker News does not publish.
descendants BIGINT
Number of live comments in the whole thread under a story or poll, at every depth (deleted and dead comments are not counted). NULL for other item types.
parent BIGINT
Id of the item a comment replies to (another comment, or the story at the top of the thread). NULL for anything that is not a comment.
poll BIGINT
For a poll option, the item id of the poll (its parent). NULL otherwise.
kids BIGINT[]
Ids of the direct replies, in the ranked order Hacker News displays them. Empty when there are none.
parts BIGINT[]
For a poll, the ids of its options in display order. NULL for other item types.
deleted BOOLEAN
Whether the item was deleted. A deleted item keeps its id, type and place in its thread but loses its author and body. Never NULL.
dead BOOLEAN
Whether the item is dead: killed by moderators or flags, and hidden from readers who have not opted in to seeing it. Never NULL.
Examples (3)

What has been posted in the last few hundred items, by type

SELECT type, count(*) AS items, min(created_at) AS since
FROM hackernews.main.recent_items(500)
GROUP BY type
ORDER BY items DESC;

The newest stories submitted anywhere on the site

SELECT id, title, author, created_at
FROM hackernews.main.recent_items(1000)
WHERE type = 'story'
ORDER BY id DESC;

The busiest commenters among the newest 300 items site-wide, with their karma and account age

SELECT r.author, count(*) AS comments, u.karma, u.created_at AS joined
FROM (SELECT author FROM hackernews.main.recent_items(300) WHERE type = 'comment' AND author IS NOT NULL) r,
     LATERAL hackernews.main.user(r.author, cache_ttl => 300) u
GROUP BY r.author, u.karma, u.created_at
ORDER BY comments DESC, r.author
LIMIT 10;
Link
stories (feed VARCHAR) 2 examples

The stories on one Hacker News list, chosen by name, in the order the site ranks them

Arguments
feed VARCHAR
Which list to read: top (the front page), new, best, ask (Ask HN), show (Show HN) or job
Returns columns
rank INTEGER
1-based position in the list when it was read; 1 is the top slot. Positions move from one read to the next, so the rank is a snapshot, not an identity.
id BIGINT
Unique item id, assigned in increasing order across every kind of item; the key item() and comments() take, and the value kids, parent, poll and parts refer to.
type VARCHAR
What the item is: 'story', 'comment', 'job', 'poll' or 'pollopt' (one option of a poll). Ask HN and Show HN posts are stories.
author VARCHAR
Username of whoever posted it (the API's `by` field); the key user() takes. NULL on deleted items.
created_at TIMESTAMP WITH TIME ZONE
When the item was posted, as a UTC instant (the API's `time`, in Unix seconds).
title VARCHAR
Headline of a story, poll or job, as plain text. NULL for comments and poll options.
url VARCHAR
Address a link story points to. NULL for text posts such as Ask HN, and for comments.
text VARCHAR
Body of a comment, text post, job or poll option, as HTML: entity-escaped, with <p> paragraph breaks and <a> links. html_to_text() turns it into plain text. NULL when the item has no body.
score BIGINT
Points (net upvotes) on a story, poll or job, or the number of votes cast for a poll option. NULL for comments, whose scores Hacker News does not publish.
descendants BIGINT
Number of live comments in the whole thread under a story or poll, at every depth (deleted and dead comments are not counted). NULL for other item types.
parent BIGINT
Id of the item a comment replies to (another comment, or the story at the top of the thread). NULL for anything that is not a comment.
poll BIGINT
For a poll option, the item id of the poll (its parent). NULL otherwise.
kids BIGINT[]
Ids of the direct replies, in the ranked order Hacker News displays them. Empty when there are none.
parts BIGINT[]
For a poll, the ids of its options in display order. NULL for other item types.
deleted BOOLEAN
Whether the item was deleted. A deleted item keeps its id, type and place in its thread but loses its author and body. Never NULL.
dead BOOLEAN
Whether the item is dead: killed by moderators or flags, and hidden from readers who have not opted in to seeing it. Never NULL.
Examples (2)

The first page of Hacker News as it stands right now

SELECT rank, title, score, descendants AS comments
FROM hackernews.main.stories('top')
ORDER BY rank
LIMIT 30;

Stories on both the front page and the best list

SELECT t.rank AS top_rank, b.rank AS best_rank, t.title
FROM hackernews.main.stories('top') t
JOIN hackernews.main.stories('best') b USING (id)
ORDER BY t.rank;
Link
submissions (username VARCHAR) 3 examples

Everything one Hacker News user has posted β€” stories, comments, polls β€” newest first

Arguments
username VARCHAR
Username whose posts to read; case-sensitive
Returns columns
id BIGINT
Unique item id, assigned in increasing order across every kind of item; the key item() and comments() take, and the value kids, parent, poll and parts refer to.
type VARCHAR
What the item is: 'story', 'comment', 'job', 'poll' or 'pollopt' (one option of a poll). Ask HN and Show HN posts are stories.
author VARCHAR
Username of whoever posted it (the API's `by` field); the key user() takes. NULL on deleted items.
created_at TIMESTAMP WITH TIME ZONE
When the item was posted, as a UTC instant (the API's `time`, in Unix seconds).
title VARCHAR
Headline of a story, poll or job, as plain text. NULL for comments and poll options.
url VARCHAR
Address a link story points to. NULL for text posts such as Ask HN, and for comments.
text VARCHAR
Body of a comment, text post, job or poll option, as HTML: entity-escaped, with <p> paragraph breaks and <a> links. html_to_text() turns it into plain text. NULL when the item has no body.
score BIGINT
Points (net upvotes) on a story, poll or job, or the number of votes cast for a poll option. NULL for comments, whose scores Hacker News does not publish.
descendants BIGINT
Number of live comments in the whole thread under a story or poll, at every depth (deleted and dead comments are not counted). NULL for other item types.
parent BIGINT
Id of the item a comment replies to (another comment, or the story at the top of the thread). NULL for anything that is not a comment.
poll BIGINT
For a poll option, the item id of the poll (its parent). NULL otherwise.
kids BIGINT[]
Ids of the direct replies, in the ranked order Hacker News displays them. Empty when there are none.
parts BIGINT[]
For a poll, the ids of its options in display order. NULL for other item types.
deleted BOOLEAN
Whether the item was deleted. A deleted item keeps its id, type and place in its thread but loses its author and body. Never NULL.
dead BOOLEAN
Whether the item is dead: killed by moderators or flags, and hidden from readers who have not opted in to seeing it. Never NULL.
Examples (3)

Paul Graham's highest-scoring stories among his latest 200 posts

SELECT title, score, created_at
FROM (SELECT * FROM hackernews.main.submissions('pg') LIMIT 200)
WHERE type = 'story'
ORDER BY score DESC
LIMIT 10;

What a user has been commenting on lately

SELECT created_at, parent, hackernews.main.html_to_text(text) AS comment
FROM (SELECT * FROM hackernews.main.submissions('dang') LIMIT 20)
WHERE type = 'comment'
ORDER BY created_at DESC;

Who and what a user's latest comments were replying to

SELECT c.created_at, p.type AS replying_to, p.author AS to_whom,
  coalesce(p.title, hackernews.main.html_to_text(p.text)) AS what
FROM (SELECT * FROM hackernews.main.submissions('dang') LIMIT 20) c,
     LATERAL hackernews.main.item(c.parent) p
WHERE c.type = 'comment'
ORDER BY c.created_at DESC;
Link
user (username VARCHAR, cache_ttl := BIGINT) 2 examples

Look up a Hacker News user's public profile and karma by username

Positional arguments
username VARCHAR
Username to fetch; case-sensitive
Named arguments
cache_ttl := BIGINT
Seconds to cache each result (0 turns caching off) Β· default 0
Returns columns
username VARCHAR
Unique, case-sensitive username (the API's user `id`); what author holds on an item.
created_at TIMESTAMP WITH TIME ZONE
When the account was created, as a UTC instant.
karma BIGINT
Karma points (roughly the upvotes the user's stories and comments have received, less their downvotes).
about VARCHAR
Self-description from the profile, as HTML. NULL when blank.
submitted BIGINT[]
Ids of every story, comment, poll and job the user has posted, newest first. Can run to tens of thousands of ids; submissions() hydrates them a page at a time.
Examples (2)

Paul Graham's account

SELECT username, created_at, karma, len(submitted) AS posts
FROM hackernews.main.user('pg');

Karma of the people who posted today's front page

SELECT s.rank, s.author, u.karma, u.created_at AS joined
FROM (SELECT rank, author FROM hackernews.main.top_stories WHERE rank <= 30) s,
     LATERAL hackernews.main.user(s.author, cache_ttl => 300) u
ORDER BY s.rank;
Link

Try these queries

an_old_item_is_stable β€” Item 8863 is Dropbox's 2007 launch post; its title and author never change.

SELECT title, author, type FROM hackernews.main.item(8863);

Uses item

unix_time_becomes_a_timestamp β€” created_at is a real instant: pg's account dates from 1160418092 in Unix time.

SELECT username, CAST(epoch(created_at) AS BIGINT)
FROM hackernews.main.user('pg');

Uses user

a_thread_is_rooted_and_nested β€” Every comment in a thread names its root, and the walk starts at depth 1.

SELECT bool_and(root_id = 8863), min(depth), bool_and(len(path) = depth)
FROM hackernews.main.comments(8863);

Uses comments

a_limit_stops_a_ranking_early β€” A ranking streams in pages, so a LIMIT yields its rows without reading the rest.

SELECT count(*) FROM (SELECT id FROM hackernews.main.top_stories LIMIT 30);

Uses top_stories

ranks_are_dense_from_one β€” A list's ranks run 1..n with no gaps or repeats.

SELECT min(rank) = 1 AND max(rank) = count(*) AND count(DISTINCT rank) = count(*)
FROM hackernews.main.job_stories;

Uses job_stories

html_is_decoded β€” html_to_text decodes entities and drops markup.

SELECT hackernews.main.html_to_text('Don&#x27;t <i>panic</i> &amp; carry on');

Uses html_to_text

4 more examples

an_unassigned_id_is_no_row β€” An id with no item behind it returns nothing rather than an error.

SELECT count(*) FROM hackernews.main.item(999999999999);

Uses item

a_poll_lists_its_options β€” A poll carries the ids of its options in parts.

SELECT type, len(parts) FROM hackernews.main.item(126809);

Uses item

a_depth_cap_stops_the_walk β€” max_depth => 1 returns exactly the story's direct replies.

SELECT (SELECT count(*) FROM hackernews.main.comments(8863, max_depth => 1)) = (SELECT len(kids) FROM hackernews.main.item(8863));

Uses commentsitem

the_site_has_tens_of_millions_of_items β€” max_item is the newest id, and ids are assigned in sequence.

SELECT id > 40000000 FROM hackernews.main.max_item;

Uses max_item

34 more examples in the Catalog, each listed under the table or function it uses.

Questions it can answer

Plain-English questions from the worker's agent test tasks. An AI agent with this catalog attached should answer each one with SQL.

  • What are the titles of the five stories at the top of the Hacker News front page right now, in order?
  • Which three stories were submitted to Hacker News most recently? Give their titles and authors.
  • How many stories are on the Hacker News front page and on its 'best' list at the same time?
  • Which story on Hacker News' 'best' list has the highest score at the moment?
  • Of the Ask HN questions currently listed, which one has drawn the most comments?
  • What is the highest-scoring Show HN post currently listed on Hacker News?

Hacker News is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.