7 ms·
Woah that is some wild postgresql
- jkire 11y agoThe SQLite documentation has a wonderfully titled section "Outlandish Recursive Query Examples" [1], which includes computation of a Mandelbrot Set. [1] https://www.sqlite.org/lang_with.html https://www.sqlite.org/lang_with.html
- acqq 11y agoAnd the code from the OP picture is on the PostgreSQL Wiki since 2009: https://wiki.postgresql.org/wiki/Mandelbrot_set https://wiki.postgresql.org/wiki/Mandelbrot_set "This SQL query (requires PostgreSQL 8.4) produces an ASCII-art image of the Mandelbrot set. It is written entirely in SQL:2008-conformant SQL."
- tribaal 11y agoI like the one solving a sudoku puzzle, too. Impressive!
- stdclass 11y agoCopy-and-paste version here: https://gist.github.com/rupey/3be62b4f511b4d4de8fc https://gist.github.com/rupey/3be62b4f511b4d4de8fc
- UserRights 11y agovery nice, indeed. it would be very impressive, if postgresql could generate it's own CRUD interface (select option: angular / react) so much tedious frame-work could be just dropped.
- chrisdevereux 11y agoYou might be interested in this: https://github.com/begriffs/postgrest https://github.com/begriffs/postgrest "PostgREST serves a fully RESTful API from any existing PostgreSQL database. It provides a cleaner, more standards-compliant, faster API than you are likely to write from scratch." Sidenote: Anyone had any experience using postgrest? Any good?
- snuxoll 11y agoIt's pretty nice to work with for internal CRUD applications and prototyping, once support for stored functions [0] is completed it'll be tremendously more useful. 0: https://github.com/begriffs/postgrest/issues/114 https://github.com/begriffs/postgrest/issues/114
- fredsted 11y agoI don't think this is the database's job. However, lots of frameworks do code generation. With Yii you can supply a database and it'll generate the necessary controllers, models and views.
- iLoch 11y agoThis makes me want to cry.. When do you ever not have ANY logic in CRUD?
- zo1 11y agoConfiguration data? Manual input of test data?
- outworlder 11y agoWell, I did a terminal-like, request/response user interface for PostgreSQL when I got carried away with a homework assignment. It had a menu system several layers deep. I assume one could do the same by having it generate html and javascript. Note that could != should.
- juliangregorian 11y agohttp://rny.io/nginx/postgresql/2013/07/26/simple-api-with-nginx-and-postgresql.html http://rny.io/nginx/postgresql/2013/07/26/simple-api-with-ng... Probably don't use it in production.
- merb 11y agoWhy not? Currently the extension API could be used to create a server that directly serves web pages and is as secure as every other application.
- juliangregorian 11y agoGood luck with that.
- thorin 11y agoVery possible with oracle apex and oracle rest data services, even with the free version of Oracle
- growse 11y agoI thought about collecting some of these in the past. Fun thing to do, put this in a `.ps` file and send it to a printer. Should think for a bit and then print a mandelbrot: %!PS-Adobe-2.0 51 .5 551 { /x exch def 111 .5 721 { /y exch def y 521 sub 201 div x 301 sub 201 div 1 index 1 index 31 -1 1 { /n exch def 1 index dup mul 1 index dup mul 1 index 1 index add /d exch def sub 4 index add 3 1 roll 2 mul mul 2 index add d 4 gt {exit} if } for pop pop pop pop n 31 div setgray x y moveto .5 0 rlineto 0 .5 rlineto -.5 0 rlineto fill } for } for showpage I had a TSQL one as well, not mine though: https://www.growse.com/2009/05/01/odd-ways-of-making-a-mandelbrot/ https://www.growse.com/2009/05/01/odd-ways-of-making-a-mande...
- poizan42 11y agoOhh I attempted to make one in PDF (it doesn't have any control flow so loops must be manually unrolled), but it turns out that most PDF readers doesn't actually follow the spec when displaying a PDF on a monitor (no you can't just throw the precision away internally just because the end result is going to be displayed with limited precision) - this includes Adobe Reader btw. I have been wanting to write a blog post about it for some time, but have never gotten around to get it done.
- growse 11y agoI'm sure I saw a way of doing it in Latex - I'm guessing that when you call pdftex (or whatever) then that's the point it calculates the output image, rather than letting the PDF reader do it?
- leni536 11y agoPGF (LaTeX) indeed has a "Mandelbrot set" shading parameter[1]. Note: this is calculated by the PDF renderer. PDF has function shading and I think one can abuse it enough to render the Mandelbrot set. It certainly looks different in different viewers. [1] http://mirror.switch.ch/ftp/mirror/tex/graphics/pgf/base/doc/pgfmanual.pdf http://mirror.switch.ch/ftp/mirror/tex/graphics/pgf/base/doc... Page 696
- mhd 11y agoAny sufficiently Turing-complete system will be used to draw the Mandelbrot set. After that, we move on to Zawinskie's law.
- terhechte 11y agoI always thought that the next step after Mandelbrot is usually running Doom.
- mhd 11y agoI think it's mandelbrot -> read email -> lisp -> web server -> Doom -> operating system
- vezzy-fnord 11y agoOperating system would come before Doom, and web server probably the second thing after Mandelbrot set these days.
- retroencabulato 11y agoWhat does sufficiently Turing-complete mean? I thought a system is, or isn't?
- mhd 11y agoI'm just weaseling out because I don't want to claim that every system that can draw Mandelbrots is Turing complete (not considering pathetic cases like "draw_mandelbrot" keywords/functions/parameters). I'll leave the proof to interested readers.
- thyrsus 11y agoGenuinely Turing-complete machines have infinite memory ("tape") and an arbitrarily large number of steps within which to complete an algorithm. I suppose "sufficiently Turing-complete" to mean that you can express an algorithm to the machine such that the algorithm can complete within the resources (RAM and time) that you have to give it.
- aidos 11y agoI still haven't taken the time to grok Recursive CTEs. I think it's mostly my internal set theorist putting up the fight :)
- vander_elst 11y agothat's nasty!!
- timtadh 11y agoAnother cool thing you can do is solve the 8-Queens problem. There is a great write up at : http://www.andreas-dewes.de/en/2015/queens-of-the-data-age-abusing-common-table-expressions-to-solve-the-eight-queens-problem-in-sql/ http://www.andreas-dewes.de/en/2015/queens-of-the-data-age-a...
- ThePhysicist 11y agoRecursive common table expressions are indeed very powerful! You can even solve the eight queens problem in them: http://www.andreas-dewes.de/en/2015/queens-of-the-data-age-abusing-common-table-expressions-to-solve-the-eight-queens-problem-in-sql/ http://www.andreas-dewes.de/en/2015/queens-of-the-data-age-a... As others have pointed out there is a really nice section on CTEs in the SQLite documenation as well: https://www.sqlite.org/lang_with.html https://www.sqlite.org/lang_with.html
- mjn 11y agoWith these features that have been added to SQL over the past decades, you could probably at this point implement Datalog in it, or a Datalog-to-SQL translator. Might be an interesting experiment.
- coob 11y agoHere's the slides of the source for this, including loads of other cool things that can be done with PG: https://wiki.postgresql.org/images/0/0b/PGforSmarties.pdf https://wiki.postgresql.org/images/0/0b/PGforSmarties.pdf
- Xophmeister 11y agoWhenever the PostgreSQL Mandlebrot comes up, I always show off my Oracle version. It was written independently (i.e., I didn't port the PostgreSQL version; I didn't know about it at the time) and I documented the process: http://xoph.co/20130917/mandelbrot-sql/ http://xoph.co/20130917/mandelbrot-sql/ Of course, it comes with a hefty dose of proprietary functionality. I think the newer versions of Oracle support recursive CTEs -- but fortunately, I don't have to deal with Oracle any more, so it's dead to me ;)
- trentnelson 11y ago> but fortunately, I don't have to deal with Oracle any more, so it's dead to me I recently did a project where I got to use Oracle 12c. Bit of a hump getting back into it (last time I used Oracle was 8 in the early 2000s), but, man, it is amazing what you can do with it when you leverage all of its power. I really hope they adjust their pricing model in the future to be friendly to non-billion-dollar corporations -- I'd love to use Oracle as the foundation for a startup, because the technology is decades ahead of where open source is, but, man, $48k/core... that's rough.
- chucky_z 11y agoCheck out the pie chart... https://wiki.postgresql.org/wiki/Category:Fun_Snippets https://wiki.postgresql.org/wiki/Category:Fun_Snippets The Mandelbrot is awesome, but the pie chart is some next level stuff. You can even make it colored.
- alexggordon 11y agoI always loved Snowflakes[0] in postgresql. That said though, almost anything could be visualized in postgresql because of the awesome geometric[1] functions that are natively supported. Someday when I'm bored, I might try doing something like the Mona Lisa in postgres. [0] http://explainextended.com/2013/12/31/happy-new-year-5/ http://explainextended.com/2013/12/31/happy-new-year-5/ [1] http://www.postgresql.org/docs/9.0/static/functions-geometry.html http://www.postgresql.org/docs/9.0/static/functions-geometry...
- piratebroadcast 11y agoCan someone ELI5 this? And what is the image on the right? Thanks!
- ekimekim 11y agoThe Mandelbrot set (the image on the right) is a famous example of a fractal, a mathematical shape that gets more detailed the more you zoom in. The code on the left is SQL, normally used to query databases, but in this case is being used to create the image on the right. This is impressive because SQL isn't generally thought of as a language for arbitrary computation.