Home: Perl Programming Help: DBI:
select statements containing ()



vic
New User

Mar 8, 2010, 7:54 AM


Views: 5154
select statements containing ()

Hi all,

I have a program which connects to a .csv file to read in certain columns and this all works fine apart from specific column headers. Some of the headers contain brackets i.e. myheader(moreheader) is one column name. To make my code work on these columns, I have to manually rename the headers, removing the brackets. Does anyone know how to use myheader(moreheader) in a SELECT statement without having to change the headers (and ideally without using col_names as columns are not always in the same order, but they do always have the same 'default' column names).

The correct column headers (i.e. with the brackets) are given when I run the following:

print "$sth->{NAME}[$i]\n"

But when I execute my $sth = $dbh->prepare("SELECT `myheader(moreheader)` FROM $file"); i get the following error:

DBD::CSV::db prepare failed: Unknown function '`myheader'


I have tried with and without the backquotes and have tried using underscores in place of the brackets (I read about the 'sanitizer', which reads in column headers.) All give errors and I'm really stumped!

Any help would be great,



Many thanks