MySQL 将列名添加到结果的开头

发布于 2024-10-31 05:10:13 字数 989 浏览 6 评论 0原文

希望这只是快速修复,但是当我执行任何选择查询时,例如,

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

后eg是否自 2024-11-07 05:10:13

这是您问题的答案:

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!

離殇 2024-11-07 05:10:13

听起来这就是结果集中返回的列名称。

要通过 shell 脚本处理此问题,请尝试修改处理结果的代码。以某种方式跳过第一个结果,因为它是列的名称。

伪代码:

for each result in myResultSet
    if result != myResultSet[0]
    begin
        //include this result.
    end
next

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:

for each result in myResultSet
    if result != myResultSet[0]
    begin
        //include this result.
    end
next
白色秋天 2024-11-07 05:10:13

将选择更改为读取

SELECT table_name as ` ` 
FROM table_info 
WHERE load_order IS NOT NULL 
ORDER BY load_order;

SELECT table_name as `\0` 
FROM table_info 
WHERE load_order IS NOT NULL 
ORDER BY load_order;

Change the select to read

SELECT table_name as ` ` 
FROM table_info 
WHERE load_order IS NOT NULL 
ORDER BY load_order;

or

SELECT table_name as `\0` 
FROM table_info 
WHERE load_order IS NOT NULL 
ORDER BY load_order;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文