コマンドを使用してmysqlデータベースにロードしているcsvファイルがありますload local infile
。
csvには、5つの値の列挙から収集された一連のフィールドがあり、これらに基づいてクエリを実行する必要があります。クエリを高速化するために(おそらく最大600万行)、参照テーブルで文字列値ではなくIDを挿入するように選択しようとしています。
load data local infile 'test_file.csv'
into table matching
fields terminated by ','
enclosed by '"'
(... @match, ...)
set
...
match = select id from matchRefData where name = @match,
...;
http://dev.mysql.com/doc/refman/5.1/en/load-data.htmlによると、サブクエリは集合演算の右側で使用できますが、次の場合は毎回失敗するようです。
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check
the manual that corresponds to your MySQL server version for the right
syntax to use near 'select id from matchRefData where name = @match,...'
バージョン情報:
サーバーバージョン:5.5.25ソース配布
+-------------------------+---------------------+
| Variable_name | Value |
+-------------------------+---------------------+
| innodb_version | 1.1.8 |
| protocol_version | 10 |
| slave_type_conversions | |
| version | 5.5.25 |
| version_comment | Source distribution |
| version_compile_machine | i386 |
| version_compile_os | osx10.7 |
+-------------------------+---------------------+