by shigemk2

当面は技術的なことしか書かない

Emacs format-sql

  • Emacs 25.3
  • Python 2.7.13 (pyenv)

Emacsでこういったものを

sql = """ SELECT country, product, SUM(profit) FROM
sales   left join x on x.id=sales.k GROUP BY country,
product having f > 7 and fk=9 limit 5;    """

こうするためのものであって、

sql = """
    SELECT
        country,
        product,
        SUM(profit)
    FROM
        sales
        LEFT JOIN x ON
            x.id = sales.k
    GROUP BY
        country,
        product
    HAVING
        f > 7
        AND fk = 9
    LIMIT 5; """

ナマのSQLを整形するものではない。

select *
from PenPeriods P0
where end_year = (select max(end_year)
from PenPeriods P1
where P1.sin = P0.sin);

こんなエラーが出るので。

TypeError: expected a string or other character buffer object

Emacs上で生クエリを整形するためには、別の方法が必要。

github.com