[英]“Can't find table names in FROM clause” error with DBD::CSV
I'm trying to use a UNION
statement in DBI
to combine two CSV files: 我正在尝试在
DBI
使用UNION
语句来组合两个CSV文件:
#!/usr/bin/perl -w
use strict;
use DBI;
my $dbh = DBI->connect ("dbi:CSV:")
or die "Cannot connect to the CSV file: $DBI::errstr()";
$dbh->{RaiseError} = 1;
$dbh->{TraceLevel} = 0;
my $query = "select * from file.csv UNION select * from output.csv";
my $sth = $dbh->prepare ($query);
$sth->execute ();
$sth->dump_results();
$sth->finish();
$dbh->disconnect();
However, I get the following errors: 但是,我收到以下错误:
Can't find table names in FROM clause!
在FROM子句中找不到表名! at C:/Perl64/site/lib/SQL/Statement.pm line 88.
在C:/Perl64/site/lib/SQL/Statement.pm第88行。
DBD::CSV::db prepare failed: Can't find table names in FROM clause!DBD :: CSV :: db准备失败:在FROM子句中找不到表名! at C:/Perl64 /site/lib/SQL/Statement.pm line 88.
在C:/ Perl64 /site/lib/SQL/Statement.pm第88行。
[for Statement "select * from file.csv UNION select * from output.csv"] at CSV.[用于CSV的语句“select * from file.csv UNION select * from output.csv”]。 pl line 15.
第15行。
DBD::CSV::db prepare failed: Can't find table names in FROM clause!DBD :: CSV :: db准备失败:在FROM子句中找不到表名! at C:/Perl64 /site/lib/SQL/Statement.pm line 88.
在C:/ Perl64 /site/lib/SQL/Statement.pm第88行。
[for Statement "select * from file.csv UNION select * from output.csv"] at CSV.[用于CSV的语句“select * from file.csv UNION select * from output.csv”]。 pl line 15.
第15行。
I updated SQL::Statement
and SQL::Parse
as suggested elsewhere but that didn't fix the issue. 我按照其他地方的建议更新了
SQL::Statement
和SQL::Parse
,但没有解决问题。 I'm running on Windows 8.1. 我在Windows 8.1上运行。 What is causing the errors?
导致错误的原因是什么?
Drop .csv
extensions from query and make sure your files are in current dir: 从查询中删除
.csv
扩展名,并确保您的文件位于当前目录中:
my $query = "select * from file UNION select * from output";
You can also explicitly set folder with csv files, 您还可以使用csv文件显式设置文件夹,
my $dbh = DBI->connect ("dbi:CSV:", "", "", {
f_dir => 'C:\path_to_csv',
});
DBD::CSV uses SQL::Statement as its SQL engine. DBD :: CSV使用SQL :: Statement作为其SQL引擎。 SQL::Statement only supports a subset of SQL commands , which does not include
UNION
. SQL :: Statement 仅支持SQL命令的子集,不包括
UNION
。
As an alternative, why not simply concatenate the two files? 作为替代方案,为什么不简单地连接两个文件?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.