# Esqueleto Select Syntax

Our instinct as Haskell programmers is to follow the types around and make sure the way we’re composing things works. Normally, this makes sense.

However, in the case of translating SQL to Esqueleto syntax, I find it’s often easier to view the Haskell code as just the end product of some indifferent translation mechanism (translate :: SQL -> Haskell), which doesn’t have very helpful types until it’s completed the translation. This definitely has drawbacks, such as making it harder to iteratively add things, but if you already have your SQL query handy, then translating it to Esqueleto becomes a purely syntactic game of shuffling terms around.

For convenience, I’ll be using the example schema from https://hackage.haskell.org/package/esqueleto-3.3.3.2/docs/Database-Esqueleto.html, but hopefully the exact schema won’t matter too much here. It looks something like this:

Person
name String
age Int Maybe
deriving Eq Show

BlogPost
title String
authorId PersonId
deriving Eq Show

I’m also using some example queries taken directly from that page. Mostly what I’ve done here is just adding a bit more description to how they get translated, and color-coding for clarity. Hopefully, this means that if I’ve made any mistakes, the Esqueleto docs can clear them up.

## Shuffling words

Let’s start with a basic, yet common, query. I’ve color-coded each of the elements so it’s easier to follow along with where they move to.

SELECT * FROM Person;