Skip to content

Instantly share code, notes, and snippets.

Nick Andren nick-andren

Block or report user

Report or block nick-andren

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@nick-andren
nick-andren / sqrt.sql
Created Nov 26, 2018
Using CTEs in SQLite to generate a square root. sqrt() isn't a native function within SQLite, so I wanted to see if I could recreate the process within a recursive CTE instead. Unfortunately, there doesn't seem to be a way to dynamically alter the initial values in a recursive CTE (at least not in a straightforward way), so this example will onl…
View sqrt.sql
WITH RECURSIVE rsqrt AS (
SELECT 27 AS x,
1 AS step,
1 AS g
UNION ALL
SELECT x AS x,
step+1 AS step,
CASE WHEN g = ((x/g + g) /2.0) THEN x ELSE ((x/g + g) /2.0) END AS g
You can’t perform that action at this time.