At some time in the future it likely would be beneficial to centralize all SQL queries and/or move to stored procedures. What I mean by centralizing is:

```python
from qiitapet.sql import fetch_analysis, fetch_study, ...

def foo(*args):
    try:
        # get open psql connection
        pgcursor.execute(fetch_analysis(*args)
        res = pgcursor.fetchall()
    except PostgresError, e:
        # do something
    except QueryCompilationError, e:
        # do something
```

Once the queries are centralized, it becomes very easy to wrap them all in a common function to sanity check:

```python
from functools import partial

def scrub_sql(name, query, *args):
    for item in args:
        # do sanity check on item

    try:
        to_execute = query % args
    except TypeError, e:
        raise QueryCompilationError("Failed to compile %s with %s" % (name, repr(args))
    
    return to_execute

_fetch_analysis_sql = """SELECT foo FROM bar"""
fetch_analysis = partial("fetch_analysis",  _fetch_analysis_sql)
```

BUT, it does ease development having the sql right in your face, so if this approach makes sense to everyone, then it may be better to shift it to a refactor in the future.