本文介绍了SELECT DISTINCT是否可以与Perl的DBD :: CSV一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网上找到了一个SELECT示例.当我在脚本中尝试时,出现以下错误消息:

I found a SELECT-example on the web.When I try it in my script I get this error-message:

Specifying DISTINCT when using aggregate functions isn't reasonable - ignored. at /usr/lib/perl5/site_perl/5.10.0/SQL/Parser.pm line 496.

#!/usr/bin/perl
use warnings;
use strict;
use DBI;

my $dbh = DBI->connect( "DBI:CSV:", undef, undef, { RaiseError => 1, AutoCommit => 1 } );
my $table = 'artikel';

my $array_ref = [   [ 'a_nr', 'a_name', 'a_preis' ],  
            [ 12, 'Oberhemd', 39.80, ],
            [ 22, 'Mantel', 360.00, ],
            [ 11, 'Oberhemd', 44.20, ],
            [ 13, 'Hose', 119.50, ],
        ];
$dbh->do( "CREATE TEMP TABLE $table AS IMPORT(?)", {}, $array_ref );

my $sth = $dbh->prepare( "SELECT DISTINCT a_name FROM $table" );
$sth->execute();
$sth->dump_results();
$dbh->disconnect();

SELECT DISTINCT是否不能与DBD :: CSV一起使用,或者我的脚本有问题吗?

Does SELECT DISTINCT not work with DBD::CSV or is something wrong with my script?

输出是

'Oberhemd''Mantel''Oberhemd''Hose'4 rows

'Oberhemd''Mantel''Oberhemd''Hose'4 rows

我认为应该是

'Oberhemd''Mantel''Hose'3 rows

'Oberhemd''Mantel''Hose'3 rows

已安装的版本:

Perl : 5.010000 (x86_64-linux-thread-multi) OS : linux (2.6.31) DBI : 1.609 DBD::Sponge : 12.010002 DBD::SQLite : 1.25 DBD::Proxy : 0.2004 DBD::Gofer : 0.011565 DBD::File : 0.37 DBD::ExampleP : 12.010007 DBD::DBM : 0.03 DBD::CSV : 0.26

Perl : 5.010000 (x86_64-linux-thread-multi) OS : linux (2.6.31) DBI : 1.609 DBD::Sponge : 12.010002 DBD::SQLite : 1.25 DBD::Proxy : 0.2004 DBD::Gofer : 0.011565 DBD::File : 0.37 DBD::ExampleP : 12.010007 DBD::DBM : 0.03 DBD::CSV : 0.26

推荐答案

这是一个易于复制的错误. SELECT data_display_mask FROM test.csv返回200多行. SELECT DISTINCT data_display_mask FROM test.csv返回警告消息和相同的200行.

Hi This is an easily reproducable bug. SELECT data_display_mask FROM test.csv returns 200 plus rows. SELECT DISTINCT data_display_mask FROM test.csv returns the warning message and same 200 rows.

如果我执行awk,将-u排序为唯一(行的值),我得到36个值,这是我期望的值.

If i do an awk, sort -u for unique ( values of the row ) I get 36 values, which is what I would expect.

肯定是代码中的错误.

-Kanwar

perl -V我的perl5(修订版5版本10子版本0)的配置摘要: 平台: osname = linux,osvers = 2.2.24-6.2.3,archname = i686-linux-thread-multi

perl -VSummary of my perl5 (revision 5 version 10 subversion 0) configuration: Platform: osname=linux, osvers=2.2.24-6.2.3, archname=i686-linux-thread-multi

DBD :: CSV 0.26SQL ::解析器1.23DBI 1.609

DBD::CSV 0.26SQL::Parser 1.23DBI 1.609

示例:

在使用聚合函数时指定DISTINCT是不合理的-会被忽略.在/opt/perl2exe/perl5/lib/site_perl/5.10.0/SQL/Parser.pm行496中.87060870608706087060

Specifying DISTINCT when using aggregate functions isn't reasonable - ignored. at /opt/perl2exe/perl5/lib/site_perl/5.10.0/SQL/Parser.pm line 496.87060870608706087060

使用的SQL是来自test.csv的SELECT DISTINCT entry_id

SQL used is SELECT DISTINCT entry_id FROM test.csv

这篇关于SELECT DISTINCT是否可以与Perl的DBD :: CSV一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 09:41