I am trying to select columns by their \"x\" position in the table.
DBI
my $example = $hookup->prepare(qq{SELECT This,That,Condition,\"I also want
Many others here have stated why you would not want to do such a thing. But let me just show you how exactly impossible this is.
This tells you the name of a column if you only have the position, for instance, if you only know it's the 3
rd position...
SELECT COLUMN_NAME
FROM information_schema.columns
WHERE TABLE_SCHEMA = 'YourSchema'
AND TABLE_NAME = 'YourTable' AND
ORDINAL_POSITION = 3;
Naturally, you think, you can simply wrap this around into a SELECT (subqueryabove) FROM YourTable
, you won't, because your result will be this constant: YourField
, and not the value in the actual rows. So, it's not even possible to do it in one query. You could use variables, sure, but then that solution is getting increasingly complicated, and you should see now why it's not a good idea to query fields based on their position.
Take a quick peak at the MySQL.com: Schema Object Names documentation:
Certain objects within MySQL, including database, table, index, column, alias, view, stored procedure, partition, tablespace, resource group and other object names are known as identifiers....
An identifier may be quoted or unquoted. If an identifier contains special characters or is a reserved word, you must quote it whenever you refer to it.
I suspect you just want something that's quoted. In that case, use the backticks. Also from the above source...
mysql> SELECT * FROM `select` WHERE `select`.id > 100;