MySQL 将列名添加到结果的开头
希望这只是快速修复,但是当我执行任何选择查询时,例如,
SELECT table_name
FROM table_info
WHERE load_order IS NOT NULL
ORDER BY load_order;
它总是将列名添加到结果中。在本例中,结果是,
table_name settings tax tax_rate sales_tax_zone sic
naics exempt_reason wh pack pcat route supply_point
point credit_status fuel_type participant site salesman
driver truck profit terms vendor product pump customer
card card_fuel_type tax_certificate prodware prodware_price
这是 bash 脚本的一个片段:
TABLES=` (
echo -n "select table_name from table_info "
echo -n "where load_order is not null "
echo "order by load_order;"
) | mysql -uuser -ppassword database`
通过以下方式解析它:
for TABLE in ${TABLES}
do
if [ $TABLE != 'table_name' ]
do_table #Start the load process
fi
done
问题是脚本相当大(~2000)行,并且有很多选择查询。是否有一个选项可以传递给 mysql 来排除列名?
找到解决方案:我在调用mysql时需要使用--skip-column-names选项。感谢您的所有回答。
Hopefully this is just quick fix, but when I execute any select query, such as,
SELECT table_name
FROM table_info
WHERE load_order IS NOT NULL
ORDER BY load_order;
it always prepends the column name to the result. In this case, the result is,
table_name settings tax tax_rate sales_tax_zone sic
naics exempt_reason wh pack pcat route supply_point
point credit_status fuel_type participant site salesman
driver truck profit terms vendor product pump customer
card card_fuel_type tax_certificate prodware prodware_price
Here is a snippet from the bash script:
TABLES=` (
echo -n "select table_name from table_info "
echo -n "where load_order is not null "
echo "order by load_order;"
) | mysql -uuser -ppassword database`
Parsing it via:
for TABLE in ${TABLES}
do
if [ $TABLE != 'table_name' ]
do_table #Start the load process
fi
done
The problem is the script is quite large (~2000) lines and there are many select queries. Is there an option I can pass to mysql that will exclude the column name?
Found the solution: I needed to use the --skip-column-names option when invoking mysql. Thanks for all the answers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是您问题的答案:
mysql CLI 手册页说有一个“--column-names”选项。尝试一下。
这是你没有问的问题的答案:
是的,你应该用另一种方式来做。使用某种实际上为您提供数据库连接的语言,而不是通过管道运行“许多选择查询”!
Here's the answer to your question:
The mysql CLI man page says that there's an option for "--column-names". Try that.
And here's the answer to the question you didn't ask:
Yes, you should be doing it another way. Drop into some language that actually gives you a database connection rather than running "many select queries" via pipes!
听起来这就是结果集中返回的列名称。
要通过 shell 脚本处理此问题,请尝试修改处理结果的代码。以某种方式跳过第一个结果,因为它是列的名称。
伪代码:
Sounds like that's the column name coming back in your result set.
To deal with this from your shell script, try modifying the code that's handling the results. Somehow skip the first result, as it's the name of the column.
Pseudocode:
将选择更改为读取
或
Change the select to read
or