Saturday, February 19, 2011

SQL and the Third Manifesto

I've been poking around with relational algebra a bit lately, and came across the supposedly infamous "Third Manifesto", a paper from 1995 which argues "unequivocally" for the elimination of SQL. Authors Hugh Darwen and C.J. Date say that SQL is a barrier to achieving the "true" Relational Model, put forth by E.F. Codd in 1969. They give several reasons, not least of which are SQL's tolerance for NULL values, duplicate rows, and the need for a user to manage the order of columns (for example, when doing an insert). They propose a language "Tutorial D", along with a set of prescriptions for authentically representing a relational model.

Dave Voorhi developed an implementation of Darwen and Date's "Tutorial D", called "Rel". I decided to download it and play around to see how it works. Coming from the SQL world, I thought I'd give some brief comparisons.

To demonstrate the differences, I will create a "zoo" database in MySQL and Tutorial D. The database consists of animals, which are members of a zoo. Each animal must also belong to a species.

Creating Relations


Tutorial D

Inserting Tuplets


Tutorial D

Also, inserting NULLs in Tutorial D is forbidden. So while this works in SQL

Tutorial D complains.

Selecting data


Tutorial D



Tutorial D

Running a similar query in SQL will return multiple rows, rendering the result meaningless.

I gotta say, SQL is indeed quite clunky. How can I get in on this manifesto! But Google searches to dig further return nothing but expired pages. Even finding the "Third Manifesto" was tricky. Why isn't there more interest in this subject?

Fortunately, there are a couple of useful links to better grasp Tutorial D's syntax.

Hugh Darwen's book, "An Introduction to Relational Database Theory" (free to download)

Ahmed Yusuf Almull's dissertation on translating between SQL and Tutorial D

Rel's download page

Saturday, January 15, 2011

Workaround for a broken down key on a MacBook Pro

Recently, I had the shocking revelation that my MacBook Pro's down key stopped working. It's a lot like they say about losing your pinky finger, you don't realize how much you need it until its gone. Man, I loved that down key. With the possible exception of the space bar, I probably use the down key more than any key on my keyboard (which may be why it wimped out on me).

The "guru" at the Apple Store told me that fixing it would require an entire replacement of my keyboard, at a cost of ¥30,000. Ouch.

That's just the excuse I needed to buy a new MacBook Air, but the frugal side of me insisted that I explore other options. Like a person losing a pinky finger accomplishing pinky tasks with a ring finger, I could go on if I found a suitable substitute key.

After doing a bit of Googling, it turns out many Mac adapters miss using their "home" and "end" keys. There were quite a few sites explaining how to customize the Mac keyboard to do all sorts of crazy things, including mapping "home" and "end" keys.

This is done by creating the "~/Library/KeyBindings/DefaultKeyBinding.dict" file, which allows Cocoa-based applications (like textmate) to recognize customized key allocations. Here's a good example.

So I followed the same process for the "down" key.

First, open up "Terminal" and type the following.

And add this bit of text.

In case you're not familiar with "vi", this is done by first typing "a", then copying/pasting the code above, then hitting "escape", then typing ":wq".

This was all done, mind you, without the use of a "down" key. Tricky business.

If you're curious, the commands ("moveDown:", etc) are all listed on Apple's developer center - here's the link

Now, "ctrl+(up arrow)" mimics the use of the down key. Similarly, adding the "command" key or "shift" key on top of this also allows you to go to the end of a document, and highlight.

Mind you, this only works for Cocoa-based applications. For now, this will have to do.

Saturday, January 8, 2011

Kyoto Cabinet/Kyoto Tycoon for Python and Mac Snow Leapord

Just playing around with Kyoto Cabinet/Tycoon, the successor to Tokyo Cabinet/Tokyo Tyrant, with apparently better support for concurrency.

Getting it up and running was a breeze in Python/Mac Snow Leapord. I just followed these steps:

Following this tutorial from Kelvin Wong, the steps are the same for Kyoto Cabinet/Kyoto Tyrant as they are for their counterparts in Tokyo.
  1. Get MacPorts
  2. Open a terminal window and enter the following:
  3. Start the Kyoto Cabinet server, by entering the following:
  4. For now, leave the server running. Download and unzip KAMEDAkyosuke's Python implementation of Tycoon.
  5. Save the "" file in a folder called "PyTycoon".
  6. Open a new terminal window, and cd to "/path/to/PyTycoon/..". Run the following code:
If you look at the server instance, you should see a response like the following, indicating that the key was successfully retrieved from the database.

Wallah! Python is now talking to Kyoto Tycoon.