Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: Query Hacker News via ChatGPT (ossinsight.io)
17 points by Hooopo on May 16, 2023 | hide | past | favorite | 4 comments



Very interesting, but not what I expected when I heard the word “ChatGPT”. In fact I don’t even see evidence of an LLM at work here, just AI-generated SQL queries.


I've got this:

Q:How many repeating articles were posted in 2023?

I'm a robot running Auto-GPT on TiDB Cloud Serverless

Our goals:

Answer: How many repeating articles were posted in 2023? Shutdown upon achieving goals Thoughts: Let's list all tables and check if 'items' table is in the database

Reasoning: We have to find out if the 'items' table exists because it contains the information we need to answer the question 'How many repeating articles were posted in 2023?'

Plan:

Use the command 'tidb_query_executor' to list all tables in the database Check if 'items' table is in the result Criticism: None

Next action:

Command = tidb_query_executor

Query =

SHOW TABLES; I'm waiting for your feedback...

Command tidb_query_executor returned:

Tables_in_hackernews items users Thoughts: We've confirmed that the 'items' table exists in the database, so let's examine its schema to determine which columns we should use.

Reasoning: By examining the schema for the 'items' table, we'll be able to see which columns are relevant for answering the question 'How many repeating articles were posted in 2023?'

Plan:

Use the command 'tidb_query_executor' to list the schema for the 'items' table Identify the columns needed to answer the question Criticism: None

Next action:

Command = tidb_query_executor

Query =

SHOW CREATE TABLE `items`; I'm waiting for your feedback...

Command tidb_query_executor returned:

Table Create Table items CREATE TABLE items ( id bigint(20) NOT NULL COMMENT 'The item''s unique id.', title varchar(198) DEFAULT NULL COMMENT 'The title of the story, poll or job. HTML.', url varchar(6598) DEFAULT NULL COMMENT 'The URL of the story.', text text DEFAULT NULL COMMENT 'The comment, story or poll text. HTML.', type varchar(8) NOT NULL DEFAULT 'story' COMMENT 'The type of item. One of "job", "story", "comment", "poll", or "pollopt".', by varchar(15) NOT NULL DEFAULT '' COMMENT 'The username of the item''s author.', time int(11) NOT NULL COMMENT 'Creation date of the item, in Unix Time.', score int(11) NOT NULL DEFAULT '0' COMMENT 'The story''s score, or the votes for a pollopt.\n', parent bigint(20) DEFAULT NULL COMMENT 'The comment''s parent: either another comment or the relevant story.', descendants int(11) DEFAULT '0' COMMENT 'In the case of stories or polls, the total comment count.', deleted tinyint(1) NOT NULL DEFAULT '0' COMMENT 'true if the item is deleted.', dead tinyint(1) NOT NULL DEFAULT '0' COMMENT 'true if the item is dead.', last_fetch_at datetime NOT NULL DEFAULT '1970-01-01 00:00:01', kids json DEFAULT NULL COMMENT 'The ids of the item''s comments, in ranked display order.', parts json DEFAULT NULL COMMENT 'A list of related pollopts, in display order.', poll bigint(20) DEFAULT NULL COMMENT 'The pollopt''s associated poll.', PRIMARY KEY (id) /T![clustered_index] CLUSTERED /, KEY index_items_type_time_id (type,time,id), KEY index_items_time (time), KEY index_items_by (by), KEY index_items_score (score), KEY index_items_type_deleted_dead_time (type,deleted,dead,time), KEY index_items_descendants (descendants), KEY index_items_deleted_dead_time_score (deleted,dead,time,score), KEY index_items_score1 (score), KEY index_items_score2 (score) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin Thoughts: Now we know which columns we need to query to answer 'How many repeating articles were posted in 2023?', so let's generate SQL to query the 'items' table

Reasoning: By selecting the 'title', 'time', and 'url' columns from the 'items' table, we can determine which articles were posted in 2023 and if they are repeating

Plan:

Use the SELECT command to query the 'items' table Add the WHERE clause to filter the results to the articles posted in 2023 Use GROUP BY and COUNT to identify the repeating articles Criticism: None

Next action:

Command = tidb_query_executor

Query =

SELECT title, time, url, COUNT() FROM items WHERE type = 'story' AND time BETWEEN UNIX_TIMESTAMP('2023-01-01 00:00:00') AND UNIX_TIMESTAMP('2023-12-31 23:59:59') GROUP BY title, url HAVING COUNT() > 1 ORDER BY COUNT(*) DESC; I'm waiting for your feedback...

Executing command..


This contains an interesting idea:

Ask ChatGPT (or other AI) to automatically create SQL which will generate a table based on some criteria...

I'm guessing it is or will be possible to ask ChatGPT to generate an entire database schema based on various criteria in the future...

How good such schemas will turn out to be?

Well, that remains to be seen(!) -- but there's a very interesting set of ideas here...


Yes, it will save lots of tokens for large database schema.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: