Hi guys,
I need to perform some automated tasks in a stored procedure that require the table name to be generated in the stored procedure.
I basically have to look at a few tables, and based on their size determine where to insert data or whether or not to create a new shard to insert data to (rewriting java based shard inserts into storedprocs to speed things up).
Unfortunately, mySQL interprets the variable in an INSERT/SELECT query as literal text, so
assuming_table_name is a VARCHAR(20) and _table_name_2 is VARCHAR(20)
INSERT INTO _table_name SET (id,name) SELECT id,name FROM _table_name_2 WHERE some_condition
While _table_name is a variable, it will always be treated literally and mySQL returns "table doesn't exist" error. Doesn't matter if I put a @_table_name or not.
I know of a way to do this by calling another storedproc from within this proc (thanks Jacob) but I was wondering if there was a simpler solution
Thanks!
Luc
I need to perform some automated tasks in a stored procedure that require the table name to be generated in the stored procedure.
I basically have to look at a few tables, and based on their size determine where to insert data or whether or not to create a new shard to insert data to (rewriting java based shard inserts into storedprocs to speed things up).
Unfortunately, mySQL interprets the variable in an INSERT/SELECT query as literal text, so
assuming_table_name is a VARCHAR(20) and _table_name_2 is VARCHAR(20)
INSERT INTO _table_name SET (id,name) SELECT id,name FROM _table_name_2 WHERE some_condition
While _table_name is a variable, it will always be treated literally and mySQL returns "table doesn't exist" error. Doesn't matter if I put a @_table_name or not.
I know of a way to do this by calling another storedproc from within this proc (thanks Jacob) but I was wondering if there was a simpler solution
Thanks!
Luc