PostgreSQL対応
最新のリリースバージョンを使うことでより快適に動作するが、
運用面で最新のリリースバージョンはパッケージに組み込まれていない場合がよくある。
Tugboat.GTDで使用しているPostgreSQLもそのうちのひとつ。
リリース元 | 最新バージョン |
postgresql.org | 8.3.1 |
RHEL5 | 8.1.11 |
SLES10 | 8.1.9 |
RHEL4 | 7.4.19 |
というわけで、少し前のpostgresに対応するためのSQLの注意点
PostgreSQL8.1の場合
SET standard_conforming_strings = off;
8.2以降の構文。
standard_conforming_stringsの変更が8.2からできただけで、8.1でも存在し、デフォルトはoffになっている。
そのため、削除しても問題ないはず。
DROP DATABASE IF EXISTS tugboat_gtd; DROP USER IF EXISTS tangerine;
8.2以降の構文。
IF EXISTS構文はエラーメッセージの表示を防いでくれる。しかし、新しいバージョンでエラーで動作しなくては元も子もない。
というわけで、使用しないようにしましょう。
- 例:
-
DROP DATABASE tugboat_gtd; DROP USER tangerine;
- 参考
- http://www.postgresql.org/docs/8.2/static/sql-dropdatabase.html
- http://www.postgresql.org/docs/8.1/static/sql-dropdatabase.html
- http://www.postgresql.org/docs/8.2/static/sql-dropuser.html
- http://www.postgresql.org/docs/8.1/static/sql-dropuser.html
INSERT INTO task_statuses VALUES (1,'To Do','新規'), (2,'Doing','処理中'), (3,'Done','処理済'), (4,'Pending','保留');
8.2以降の構文
複数のrowを「,」区切りでINSERTできるそうですが、ちゃんと毎行書くようにしましょう。
- 例:
-
INSERT INTO task_statuses VALUES (1,'To Do','新規'); INSERT INTO task_statuses VALUES (2,'Doing','処理中'); INSERT INTO task_statuses VALUES (3,'Done','処理済'); INSERT INTO task_statuses VALUES (4,'Pending','保留');
- 参考
- http://www.postgresql.org/docs/8.2/static/sql-insert.html
- http://www.postgresql.org/docs/8.1/static/sql-insert.html
GRANT ALL ON SEQUENCE activity_colors_id_seq TO tangerine;
8.2以降の構文
GRANTに「ON SEQUENCE」は、8.2以降で作られた。
それまではsequenceに対しても、「ON TABLE」または省略しましょう。
- 例:
-
GRANT ALL ON TABLE activity_colors_id_seq TO tangerine;