SQL Type Safety

The cluster discusses type safety in SQL, focusing on static type checking of queries at compile time using tools like pgtyped and sqlx, and contrasts strict databases like Postgres with flexible ones like SQLite.

📉 Falling 0.4x Databases
1,710
Comments
19
Years Active
5
Top Authors
#5336
Topic ID

Activity Over Time

2008
2
2009
10
2010
4
2011
7
2012
25
2013
37
2014
33
2015
40
2016
54
2017
90
2018
42
2019
85
2020
173
2021
315
2022
168
2023
225
2024
239
2025
157
2026
4

Keywords

e.g REAL UI TABLE SQL s.a RDBMS ANSI underscore.io CHAR sql sqlite type typed queries sql queries compile time compile db strict

Sample Comments

oceanswave Dec 18, 2017 View on HN

If type safety is so great, why isn’t sql statically type checked

golergka Jun 18, 2021 View on HN

Have you tried pgtyped? I'm in love with it: it allows us check SQL queries at compile times and statically type them.

gfody Sep 29, 2020 View on HN

strong typing for arbitrary sql queries is actually really nice and this is much better than stuff like sequelize or typeorm which seem sadistic in comparison

neximo64 Feb 26, 2023 View on HN

Would be nice to add types to SQL instead of adding json objects as sql

Scarbutt Apr 22, 2020 View on HN

SQL (at least in Postgres) is already type safe.

ObscureScience Jun 28, 2023 View on HN

I can imagine what would be/is valuable is type checked embedded SQL queries.

codeptualize Nov 7, 2023 View on HN

Very much agree with this. I really like how sqlx (on rust) does it. You just write normal SQL queries, and it will check and validate the types against your db. Best of both worlds.

saosebastiao Jan 15, 2017 View on HN

You mean it's impossible to have compile time type safety of sql queries, and that the compiler can't tell the difference between an SQL string and any other string? You're wrong.http://underscore.io/blog/posts/2015/05/28/typechecking-sql....

kaba0 Jun 24, 2023 View on HN

It is quite statically typed, look at the examples. You might be thinking of the stringly-typed version, but it can generate classes from DB inspection and use columns and whatnot with its respective type throughout a query, failing to compile when a group by value is incorrect! It can’t verify everything what a SQL engine can of course, but it is quite remarkable in my opinion.

fulafel Jan 22, 2021 View on HN

I wonder what a statically typed SQL would look like.