3 ms·
If you're interested in this I would also recommend you check out Logica[0], which is a datalog-like language that is explicitly made to compile to SQL queries.
by steinuil 3y ago
If you're interested in this I would also recommend you check out Logica[0], which is a datalog-like language that is explicitly made to compile to SQL queries.
0: https://logica.dev/ https://logica.dev/
- zilti 3y agoOh nice, this is the one "SQL replacement" I'd actually look into
- breakfastduck 3y agoWhat puts you off prequel? https://prql-lang.org https://prql-lang.org really readable, nice syntax imo
- otabdeveloper4 3y ago"Unreadable syntax" is like number 1000 on the list of SQL problems.
- hashmash 3y agoPRQL has some very nice features, but the syntax also has some not so nice features that you don't see in the examples. There's special parsing rules for parenthesis and newlines, and a special word wrap character is needed at times to disable the rule that treats newlines as the pipe operator.
- ryanjshaw 3y agoI was wondering how this was possible and then found this monstrosity: https://colab.research.google.com/github/EvgSkv/logica/blob/main/examples/Logica_example_Reachability.ipynb https://colab.research.google.com/github/EvgSkv/logica/blob/... Click on the SQL tab.
- cess11 3y agoSeen longer, more obtuse queries written by hand in some applications I've worked on. Big, useful systems often give rise to them eventually.
- greenavocado 3y agoI wrote SQL queries twice that long for credit originations reports in banks which would hit several terabytes of disk read per run
- ryanjshaw 3y agoApologies, I should've been more clear. The absolute length of SQL wasn't what I was alluding to: it was the ratio of Datalog to SQL I was curious about based on this statement in the website: > Among database theoreticians Datalog and SQL are known to be equivalent. And indeed the conversion from Datalog to SQL and back is often straightforward. I was skeptical, and indeed the sample I linked to shows 8 lines of Datalog turning into 265 lines of SQL. In defense of SQL, I note WITH RECURSIVE wasn't used.
- greenavocado 3y agoCREATE TABLE edges ( source INT, target INT ); INSERT INTO edges (source, target) SELECT generate_series as source, generate_series + 1 as target FROM generate_series(0, 999); WITH RECURSIVE path_lengths AS ( -- Base case: Direct paths from edges SELECT source, target, 1 AS distance FROM edges UNION ALL -- Recursive step: Double the path length by joining on intermediate nodes SELECT p.source, e.target, p.distance + 1 AS distance FROM path_lengths AS p JOIN edges AS e ON p.target = e.source WHERE p.distance < 256 -- Control the recursion depth (2^8=256 for C8 equivalent) ) -- Final query to select paths from source 0, similar to the logic program's final goal , final_paths AS ( SELECT source, target, MIN(distance) AS distance FROM path_lengths WHERE source = 0 GROUP BY source, target ) SELECT * FROM final_paths ORDER BY source, target; You can confirm the output matches by pasting it and clicking run here: https://extendsclass.com/postgresql-online.html https://extendsclass.com/postgresql-online.html
- ryanjshaw 3y agoThat's really not bad. I'm looking at CozoDB for a hobby project of mine, but if Logica could produce output like this consistently I'd probably prefer it because I'm much more familiar with maintaining RDBMSs.