Kouhei Sutou
kou****@clear*****
2012年 5月 24日 (木) 10:53:37 JST
須藤です。 In <20120****@fizs*****> "[groonga-dev,00898] Re: テーブル結合について" on Wed, 23 May 2012 16:55:09 +0900, 田中 理恵 <rie_t****@fizs*****> wrote: > 条件については、簡単なものでいうと、 > delete from tableB where id > in (select id from tableA where end_date < 現在日付 ); > のような感じです。 それであれば、以下のように delete tableB --filter 'tableA_key.end_date < now()' というように実現できます。 以下、groongaコマンドの実行例です。 「#」から始まっていない行がgroongaのコマンドで、「#」から始 まっている行が実行結果です。 table_create tableA TABLE_HASH_KEY ShortText # [[0,0.0,0.0],true] column_create tableA end_date COLUMN_SCALAR Time # [[0,0.0,0.0],true] table_create tableB TABLE_HASH_KEY ShortText # [[0,0.0,0.0],true] column_create tableB tableA_key COLUMN_SCALAR tableA # [[0,0.0,0.0],true] load --table tableA [ {"_key": "1", end_date: "2012-05-24 10:47:00"}, {"_key": "2", end_date: "2012-05-24 10:48:00"}, {"_key": "3", end_date: "2013-05-24 10:49:00"} ] # [[0,0.0,0.0],3] load --table tableB [ {"_key": "10", tableA_key: "1"}, {"_key": "20", tableA_key: "2"}, {"_key": "30", tableA_key: "3"} ] # [[0,0.0,0.0],3] select tableB # [ # [ # 0, # 0.0, # 0.0 # ], # [ # [ # [ # 3 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "_key", # "ShortText" # ], # [ # "tableA_key", # "tableA" # ] # ], # [ # 1, # "10", # "1" # ], # [ # 2, # "20", # "2" # ], # [ # 3, # "30", # "3" # ] # ] # ] # ] delete tableB --filter 'tableA_key.end_date < now()' # [[0,0.0,0.0],true] select tableB # [ # [ # 0, # 0.0, # 0.0 # ], # [ # [ # [ # 1 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "_key", # "ShortText" # ], # [ # "tableA_key", # "tableA" # ] # ], # [ # 3, # "30", # "3" # ] # ] # ] # ] > その他、条件を動的に作成していたりします。 他のものも同じくらいシンプルなものであれば、同様に実現できる のではないかと思います。 -- 須藤 功平 <kou****@clear*****> 株式会社クリアコード <http://www.clear-code.com/> (03-6231-7270) groongaサポート: http://groonga.org/ja/support/ プログラミングが好きなソフトウェア開発者を募集中: http://www.clear-code.com/recruitment/