duanchi0897 2018-07-06 14:04
浏览 35
已采纳

如何将一个值扫描为零而不进行处理?

In Go I'm trying to write a tool to deal with the structure of MySQL tables, so I have to use a lot of queries like this one

show keys from`table`where`Key_name`='Primary'

In MySQL, I can't wrap this command with a select command and select the columns I want, so when I only want one column (in this case Column_name), how I do deal with the columns that I don't want? Because this query returns all of these other columns as well; Table, Non_unique, Key_name, Seq_in_index, Column_name, Collation, Cardinality, Sub_part, Packed, Null, Index_type, Comment, Index_comment.

In my Go code, I have lines that look like this

err = keysData.Scan(columnName)

It would be cool if I could do something like this though

err = keysData.Scan(_, _, _, _, columnName)

But that doesn't really work, getting cannot use _ as value

Do I have to declare throw away values for each one of these unneeded columns?

  • 写回答

2条回答 默认 最新

  • doulong1987 2018-07-06 14:07
    关注

    I would use the INFORMATION_SCHEMA. This is more versatile than SHOW KEYS because you can select individual columns. For example:

    SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.STATISTICS
    WHERE TABLE_NAME='mytable' AND INDEX_NAME='PRIMARY'
    ORDER BY SEQ_IN_INDEX
    

    See https://dev.mysql.com/doc/refman/8.0/en/statistics-table.html

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器