TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

A C parser for CREATE and ALTER TABLE SQLite statements

58 pointsby marcobambinialmost 2 years ago

5 comments

simonwalmost 2 years ago
Huh, weirdly enough I&#x27;ve been hoping for exactly this kind of thing - albeit easily called from Python.<p>My use-case is that with SQLite there are aspects of the table - things like generated columns - which aren&#x27;t yet available via the regular SQLite PRAGMAs for introspecting tables.<p>For those things, the only way to introspect them is to read the CREATE TABLE statement out of the &quot;sqlite_master&quot; table and parse it.<p>But you need a very robust parser!<p>I&#x27;ve been investigating tree-sitter recently for this, notes here: <a href="https:&#x2F;&#x2F;til.simonwillison.net&#x2F;python&#x2F;tree-sitter" rel="nofollow noreferrer">https:&#x2F;&#x2F;til.simonwillison.net&#x2F;python&#x2F;tree-sitter</a><p>If anyone needs an implementation of that advanced ALTER TABLE mechanism (where you create a new table with the new schema, copy the data cross from the old one and then swap the names) my sqlite-utils CLI tool and Python library implements that, as described here: <a href="https:&#x2F;&#x2F;simonwillison.net&#x2F;2020&#x2F;Sep&#x2F;23&#x2F;sqlite-advanced-alter-table&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;simonwillison.net&#x2F;2020&#x2F;Sep&#x2F;23&#x2F;sqlite-advanced-alter-...</a>
评论 #37131592 未加载
评论 #37131307 未加载
评论 #37133658 未加载
评论 #37130863 未加载
评论 #37132211 未加载
gfodyalmost 2 years ago
don&#x27;t you need a full parse even just for create and alter statements since you could always encounter an &quot;as&quot; followed by arbitrarily complex sql?
crabbonealmost 2 years ago
What was the reason for a hand-written lexer and parser vs using Flex &#x2F; Bison?
评论 #37132581 未加载
tedunangstalmost 2 years ago
The section that says sqlite doesn&#x27;t support drop column links to documentation that says it&#x27;s supported?
评论 #37129969 未加载
评论 #37130471 未加载
kyberiasalmost 2 years ago
So this is more than just on parser for those statements. Very confusing.