0

I often find myself doing select group_concat(COLUMN_NAME separator ', ') FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA='<current database>' AND TABLE_NAME='<argument>';. I manually copy-paste this in and change <current database> and <argument> as appropriate but it'd be wonderful if I could just do somescript(foo) or somesuch and it would automatically fill in the current database and put foo in argument.

chx
  • 11,270
  • 7
  • 55
  • 129
  • *"MySQL function (macro?) available to all databases?"* By the way do you mean databases as in `CREATE DATABASE` or in other vendor RDMS? As it is not totally clear what you mean.. – Raymond Nijland Oct 20 '19 at 00:56
  • As in `CREATE DATABASE`. MySQL `CREATE FUNCTION` as far as I am aware is database bound. – chx Oct 20 '19 at 00:57
  • *"MySQL function (macro?) available to all databases?"* i wonder, you might like [common_schema](https://github.com/shlomi-noach/common_schema) which enables [QueryScript](https://shlomi-noach.github.io/common_schema/query_script.html) to "marco" with on MySQL Servers ... But i still i might be interpreting your question wrong if i did see [Why should I provide a Minimal Reproducible Example for a very simple SQL query?](https://meta.stackoverflow.com/questions/333952/why-should-i-provide-a-minimal-reproducible-example-for-a-very-simple-sql-query) and or explain your user case better.. – Raymond Nijland Oct 20 '19 at 01:05

1 Answers1

0

While the MySQL CLI apparently can't do any of this, I just discovered https://github.com/dbcli/mycli which added most of this (except the current database part) at the end of 2017 in 1.14.0:

Add positional parameters to favorite queries (Thanks: Scrappy Soft).

While not available in the mycli version bundled with Ubuntu 18.04 (which is what WSL ships with) it is available from pip install mycli and while the readme states you "might" need root, my experience was I didn't need sudo but it was unable to find the binary, I read https://stackoverflow.com/a/46071447/308851 and ran python -m site, ran find ~/.local -name mycli and then added the resulting directory to PATH.

chx
  • 11,270
  • 7
  • 55
  • 129