1. 21

  2. 12

    If inconsistent syntax and some select and join define a relational database one can consider that yes otherwise it is just a catchy title. “ Relationnal operations in shell” would be more accurate title.

    1. 3

      Yeah. It’d be one thing if basic optimizations like indexing were supported (which would basically require filesystem support), but as it stands… Op either doesn’t work with real databases much, or wasn’t allowed to write his own title.

      (That said, much less flexible & efficient things than join(1) have been called relational databases with only vague efforts toward supporting SQL-like languages – such as Hive.)

    2. 8
      $ sqlite :memory: <<EOF
      .output stderr
      create table courses (id unique, title);
      create table enrollments (name, course_id);
      .separator ","
      .import courses.csv courses
      .import enrollments.csv enrollments
      .output stdout
      select *
      from enrollments
      join courses
      on enrollments.course_id = courses.id;

      The unique constraint on courses.id has the advantage of creating an index to speed up the join.

      1. 4

        I had never considered using sqlite like this before, thanks!

        1. 5

          You are quite welcome. Few people think of using it for this kind of thing, despite sqlite’s near-universal presence. I have written comments about sqlite before on lobste.rs that you might find interesting, in particular this comment on a post sharing the q cli tool.

      2. 3

        Unix offers other tools that have analogs to what SQL gives us. I’ve thought of a few:

        sum	SUM()
        $ whatis sum
        sum (1)              - checksum and count the blocks in a file


        1. 3

          This Matt Might post takes a bit more in-depth look at how to implement some db operations in bash: http://matt.might.net/articles/sql-in-the-shell/

          He uses awk to implement joins here, but the join tool makes an appearance in a footnote.

          1. 2

            This is kind of cute, but if you really want to work with CSV data on the command line, I recommend trying out https://csvkit.readthedocs.io/ .

            1. 2

              This was taken quite a bit more literally by Mark Williams Company (which made the Coherent Unix-like operating system) with their /rdb product.

              1. 1

                It tickles me that things like Coherent actually come up here from time to time :)

                Next thing you know we’ll be talking about Ultrix :)

                1. 1

                  I had a DECstation running Ultrix that I bought off eBay. I traded it to a buddy of mine for a washing machine. Good times.

                  1. 1

                    I do not mourn Buglix, but it was certainly a lot better than some of the other workstation vendors horrible mutations of UNIX around at that time :)

                    1. 2

                      When I was young, single, childless, and mortgage-less I spent my money on retrocomputing. At one point I had:

                      • Ultrix on a DECstation
                      • Tru64 UNIX on a DEC 3000 AXP
                      • Coherent on an old Intel box
                      • OpenVMS on a VAXstation
                      • Solaris on a Sparcstation
                      • NeXTSTEP on a NeXTstation
                      • AT&T UNIX on an AT&T Unix PC
                      • SCO UnixWare on an old Intel box
                      • Various Amigas

                      Now, an old man with kids and a mortgage, I have my laptop that I use for work, a burner laptop for conferences and such, and…that’s it. Emulation is fun though.

                      The only ones that I wanted that I never got were AIX and an original BeBox.

                      1. 1

                        Yup little point in collecting the hardware unless you want the actual experience of using the actual thing - emulation gets you 99.999% of the way there.

                        Tru64 UNIX? Really? :) I always hated OSF/1 despite loving the Alpha architecture :)

              2. 1

                Unix offers other tools that have analogs to what SQL gives us. I’ve thought of a few:


                sum SUM()

                Doesn’t quite look like it:

                $ sum
                08235     1