Tia’s log – 190430 :: mysql

Notes to self:

  1. SHOW FULL TABLES WHERE TABLE_TYPE LIKE ‘VIEW’; – shows all views in the current mysql database. Add to that "IN dbname" after TABLES to specify which database. Adding the word FULL gives a new "table_type" column, which gives the type of table including a view or system table. No FULL such as just "SHOW TABLES" will list all in a database.
  2. CONCAT_WS has a seperator vs just CONCAT. Additionally, if anything is NULL in concat YOU ARE SCREWED AND THE WHOLE THING WILL BE NULL (as of today and MySQL folks). Otherwise, _WS allows nulls. They are skipped, in this case.
  3. Group_Concat, which groups values data together in a nice comma seperated string, has a default value of 1024. It can be changed at runitime by setting group_concat_max_len to a valid positive integrer. It is, however, constrained by max_allowed_packet.

Angsts:

  1. Shared hosting is no good. If I can’t create a proper stored procedure or view because you want me to use your web view and restrict those, we are not friends.
  2. MySQL isn’t as friendly for creating pivot tables compared to some of the other RDMS systems. So how do you? You group by a common ID (typically, ID) and then you get the max (probs value) or some other aggregation method of the records you want (probs name/field/etc.). How does this work? Know this: you group by an id, once there, you are pulling in the value that fits your aggregate. In my case, the max entry for that grouped id.
  3. Stored procedures in MySQL are still not one of my favorite things to write.
  4. ARGH jkljouoweur. All the good JSON functions are in MySQL 7+. Guess it is off to let the codebase do it properly.
  5. There is, currently, no "CREATE OR REPLACE PROCEDURE". MariaDB has it, but I’m on MySQL, so, oh well. Drop and recreate is the best way to go. There is an alter procedure, but according to the docs (@see https://dev.mysql.com/doc/refman/5.7/en/alter-procedure.html): "However, you cannot change the parameters or body of a stored procedure using this statement; to make such changes, you must drop and re-create the procedure using DROP PROCEDURE and CREATE PROCEDURE." HECK.

Passionates:

  1. SQL Fiddle is pretty great for sharing SQL.
  2. CREATE OR REPLACE for a SQL view is pretty nice.

Olio:

There is this little thingy to create Pivot tables in MySQL. I guess if you don’t want to write out the sql, this will help? mysqlpivottable

Leave a comment