in reply to SQL Query Error

Sorry, you appear to have found a bug which only gets activated with a WHERE clause used with a CREATE TABLE AS clause. I'll look into it. In the meantime, the workaround is to create and populate the table in separate steps, like this:
$dbh->do(" CREATE TABLE saninfo (IP TEXT, Manufacturer TEXT, Model TEXT, OS TEXT, OSSP TEXT, RAM TEXT, CPUSpeed INT, CPUCount INT, CPUType TEXT, SOFT TEXT) "); my $select = $dbh->prepare(" SELECT hostinfo.IP, Manufacturer, Model, OS, OSSP, RAM, CPUSpeed, CPUCount, CPUType, SOFT FROM hostinfo JOIN software ON hostinfo.IP = software.IP WHERE SOFT LIKE '%Secure Path%' "); my $insert = $dbh->prepare(" INSERT INTO saninfo VALUES(?.?.?.?.?.?.?.?.?.?) "); $select->execute; while (my @row = $select->fetchrow_array) { $insert->execute(@row); }
This will have the same effect as the CREATE TABLE AS SELECT , but does it in separate steps.

Replies are listed 'Best First'.
Re^2: SQL Query Error
by thor (Priest) on Sep 09, 2005 at 18:54 UTC
    Does this database support "INSERT INTO table1 SELECT x, y, z FROM table2"? If so, you could save yourself bringing all of the data from the db into perl and back to the db and keep it all on the server. Definately much faster...

    thor

    Feel the white light, the light within
    Be your own disciple, fan the sparks of will
    For all of us waiting, your kingdom will come

      No, it doesn't yet support subselects with INSERT. And even when it does, it will not be any faster. Since these are CSV tables (there is no "server"), the same work is being done in my example above as would be done by INSERT with a subselect.
        Ah...didn't see that it was using a DBD::CSV. Guess I should have looked. ;)

        thor

        Feel the white light, the light within
        Be your own disciple, fan the sparks of will
        For all of us waiting, your kingdom will come