by shigemk2

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

Oracle SIGN

Oracle SIGN

  • 1より大きかったら1
  • -1より小さかったら-1
  • それ以外ならそのままの値を返す
SQL> select SIGN(1) from dual;

   SIGN(1)
----------
     1

SQL> select SIGN(-1) from dual;

  SIGN(-1)
----------
    -1

SQL> select SIGN(0) from dual;

   SIGN(0)
----------
     0

SQL> select SIGN(999) from dual;

 SIGN(999)
----------
     1

https://docs.oracle.com/en/database/oracle/oracle-database/12.2/sqlrf/SIGN.html#GUID-08B75521-B5F5-4658-A005-4B4441C82945

memo redash graph js

memo redash graph js

Redashで使っているグラフを描画するJSライブラリにはplotlyとd3がありまして、両方を適宜使っているっぽい

client/app/visualizations の下で、グラフの種類別に実装が別れているから、チャートがおかしかったらchartを見たら良いし、コホートがおかしかったらcohortを見たらいい感じ。

Athena StartQueryExecution

Athena StartQueryExecution

Your query has exceeded the maximum query length of 262144 bytes. Please reduce the length of your query and try again. If you continue to see this issue after reducing your query length, contact customer support for further assistance.

Athenaの仕様で、クエリのバイト数が262144をオーバーすると上記のエラーになる。 クエリの文字数がそんなオーバーすることがあるのか?と思うが、ありえなくもないかもしれない。

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

Emacs indirect buffer

Emacs indirect buffer

  • 間接バッファと呼ばれる
    • indirect buffer
  • 基底バッファの「コピー」のような扱い
    • 片方を編集するともう片方も編集される
    • 間接バッファをkillしても基底バッファは消えない
    • 基底を消すと間接も消える
    • メジャーモード マーカー ローカル変数は別々で持つ
  • clone-indirect-buffer / make-indirect-buffer / C-x 4 c

https://www.gnu.org/software/emacs/manual/html_node/emacs/Indirect-Buffers.html

Emacs narrowing

Emacs narrowing

  • バッファから一部分を切り出して、別のバッファに出力する 他の部分には アクセスできないようにする
    • narrow-to-region リージョン
    • narrow-to-defun defunなぶぶん
    • narrow-to-page ページ (^L で区切られているぶぶん)
  • M-x widen でもとに戻す
  • ナローイングされたバッファの部分をbuffer's restrictionという

https://www.gnu.org/software/emacs/manual/html_node/emacs/Narrowing.html

http://flex.phys.tohoku.ac.jp/texi/emacs-jp/emacs-jp_198.html

https://www.gnu.org/software/emacs/manual/html_node/emacs/Pages.html#Pages

http://flex.phys.tohoku.ac.jp/texi/emacs-jp/emacs-jp_118.html

oracle cheatsheet

oracle cheatsheet

  • 環境
    • Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production

https://en.wikibooks.org/wiki/Oracle_Database/SQL_Cheatsheet

微妙に間違ってて、こちらは「無効な識別子」エラーになる

SQL> SELECT * FROM TABLE(get_all_objects);
SELECT * FROM TABLE(get_all_objects)
                    *
行1でエラーが発生しました。:
ORA-00904: "GET_ALL_OBJECTS": 無効な識別子です。