in reply to Help with DBD::CSV

Hi, In DBD::CSV you should *either* specify the column names in your csv_tables hash like this:

'col_names' => "id,value"

*or* in your data file like this:

id;value
1;foo
2;bar
BUT DON'T SPECIFY BOTH! And, IIRC, both "key" and "value" are SQL reserved words so for portability, avoid them as column names.

SELECT * FROM table WHERE value = (SELECT * ...
That is called a subselect and it is available in some but by no means all databases. It is not yet available in DBD::CSV. See SQL::Parser for a list of the SQL syntax supported by DBD::CSV.

If those tips don't solve your problem, let me know (I'm the maintainer of DBD:CSV and SQL::Statement).

Replies are listed 'Best First'.
Re: Re: Help with DBD::CSV
by jey (Pilgrim) on Apr 30, 2004 at 22:33 UTC

    Thanks to both sacked and jZed for Answering the post.

    jZed, you were right! When the field's names are not specified in both the file and the csv_table hash, Perl does not complain anymore. In fact, I choose to specify them in the file(s), but is there a reason for prefering one method to the other?

    For the SQL command, I also take note that this is not supported yet and I will find a different way of doing this subselect. (key and value were field name I only used in the example for illustrating my problem.

    --
    jey
      In fact, I choose to specify them in the file(s), but is there a reason for prefering one method to the other?
      No, either is fine. I tend to prefer keeping the columns in a file because *) other programs like Lotus or MS-Access that read CSV files can use the field names *) if you forget what the names in the file are, you can either use SQL to query for them or just do a 'head' on the file.