こんにちわ、北川です。
PostgreSQL 9.2 で追加された JSON型を触ってみましたので紹介したいと思います。
http://www.postgresql.org/docs/9.2/static/datatype-json.html
JSON型
ドキュメントを読むとJSON型は内部的には、RFC 4627 準拠するように
チェックされたテキスト型になります。
まずは、JSON 型 をカラムに持つテーブルを作成していきます。
| 
					 1 2 3 4 5 6 7 8  | 
						demo=# CREATE TABLE weather (country TEXT , weather_data JSON); demo=# \d weather      Table "public.weather"     Column    | Type | Modifiers  --------------+------+-----------  country      | text |   weather_data | json |  | 
					
次に、データを入れてみます。
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16  | 
						demo=# insert into weather values  ('日本','{"東京":"晴れ","大阪":"雨","名古屋":"曇り"}'); demo=# select * from weather;  country |                weather_data                  ---------+---------------------------------------------  日本    | {"東京":"晴れ","大阪":"雨","名古屋":"曇り"} (1 row) demo=# insert into weather values  ('日本','[{"東京":"晴れ"},{"大阪":"雨"},{"名古屋":"曇り"}]'); demo=# select * from weather;  country |                   weather_data                     ---------+---------------------------------------------------  日本    | {"東京":"晴れ","大阪":"雨","名古屋":"曇り"}  日本    | [{"東京":"晴れ"},{"大阪":"雨"},{"名古屋":"曇り"}] (2 rows)  | 
					
特に、詰まることなく利用できました。配列も登録でき、RFC 4627 に準拠していれば問題ないようです。
また、RFC 4627 に違反していると、エラーになり insert することができませんでした。
| 
					 1 2 3 4 5 6  | 
						demo=# insert into weather values  ('日本','{"東京":"晴れ"'); ERROR:  invalid input syntax for type json LINE 1: insert into weather values  ('日本','{"東京":"晴れ"');                                             ^ DETAIL:  The input string ended unexpectedly. CONTEXT:  JSON data, line 1: {"東京":"晴れ"  | 
					
JSON型のまま、絞り込み条件は指定できず、 like , order by などもエラーとなり失敗しました。
また、JSONのキーや要素での検索も出来ないようです。
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17  | 
						demo=# select * from weather where weather_data = '{"東京":"晴れ","大阪":"雨","名古屋":"曇り"}'; ERROR:  operator does not exist: json = unknown LINE 1: select * from weather where weather_data = '{"東京":"晴れ","... '                                                  ^ HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts. demo=# select * from weather where  weather_data like '%大阪%'; ERROR:  operator does not exist: json ~~ unknown LINE 1: select * from weather where  weather_data like '%大阪%';                                                   ^ HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts. demo=# select * from weather order by weather_data; ERROR:  could not identify an ordering operator for type json LINE 1: select * from weather order by weather_data;                                        ^ HINT:  Use an explicit ordering operator or modify the query.  | 
					
一度、text型にキャストすることで、絞り込み条件として利用することは出来そうです。
| 
					 1 2 3 4 5  | 
						select * from weather where weather_data::text = '{"東京":"晴れ","大阪":"雨","名古屋":"曇り"}';  country |                weather_data                  ---------+---------------------------------------------  日本    | {"東京":"晴れ","大阪":"雨","名古屋":"曇り"} (1 rows)  | 
					
関数
JSON型の追加に合わせて、array_to_json() row_to_json() の関数が追加されています。
http://www.postgresql.org/docs/9.2/static/functions-json.html
試しに、利用してみます。
array_to_json()は 値を配列形式のJSONとして取得でき、
row_to_json()は値を行形式のJSONとして取得できます。
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16  | 
						CREATE TABLE demo (col1 integer , col2 INTEGER); insert into demo values (1,100); insert into demo values (2,300); demo=# select array_to_json(array_agg(demo)) from demo;                  array_to_json                  -----------------------------------------------  [{"col1":1,"col2":100},{"col1":2,"col2":300}] (1 row) demo=# select row_to_json(demo) from demo;       row_to_json       -----------------------  {"col1":1,"col2":100}  {"col1":2,"col2":300} (2 rows)  | 
					
まとめ
要素検索ができないなど、標準機能でのデータアクセスがもう少し便利になると嬉しい部分がありますが、
データが正しいことが保証されているので、取り出してからパースエラーとなることがなくなるなど、
利用する場面はありそうです。実際の利用では、その辺りを注意しながら利用してみるのも良さそうです。

