CREATE TABLE LIKE not working on InfiniDB? - mysql

I'm trying to automate a process in which an InfiniDB table is replaced. My idea is to create one table with the same structure as the original, load it with new data, and replace the original with this new one.
The problem is that when you do:
CREATE TABLE temp_table LIKE original_table;
the service replies the good old:
ERROR 138 (HY000): The syntax or the data type(s) is not supported by InfiniDB. Please check the InfiniDB syntax guide for supported syntax or data types.
I was thinking to do a SHOW CREATE TABLE, replace the name, and run the result, but... that's a bit ugly.
Do you know of a better way?
Thanks in advance!!

Related

Can not issue data manipulation statements with executeQuery - data studio/my sql connector error

I have a query that is running just fine in MySQL Workbench but am getting a data studio-related error once I try to run it in mysql connector within data studio. I’ve been trying to google around and ask on SO and data studio message boards for some ideas, but am not getting many ideas. Most of the responses I’ve found are related to Java.
My query:
CREATE TEMPORARY TABLE cte_most_recent_record
SELECT
leeds_new.leenk_ladder_history.member_id as member_id,
max(leeds_new.leenk_ladder_history.date_trigger_event) AS date_trigger_event_max
FROM leeds_new.leenk_ladder_history
WHERE leeds_new.leenk_ladder_history.ladder_change = 1 and leeds_new.leenk_ladder_history.ladder_advocacy is not NULL
group by leeds_new.leenk_ladder_history.member_id;
CREATE TEMPORARY TABLE cte_most_recent_record_date_ladder
select
lh.member_id,
lh.ladder_advocacy,
lh.date_trigger_event
from leeds_new.leenk_ladder_history as lh
inner join
cte_most_recent_record as cte_rr on lh.member_id = cte_rr.member_id
and lh.date_trigger_event = cte_rr.date_trigger_event_max
limit 100;
CREATE TEMPORARY TABLE cte_ladder_counts_before
select
ladder_advocacy,
count(ladder_advocacy) as ladder_counts_before
from cte_most_recent_record_date_ladder
where date_trigger_event < date('2018-01-01')
group by ladder_advocacy;
CREATE TEMPORARY TABLE cte_ladder_counts_after
select
ladder_advocacy,
count(ladder_advocacy) as ladder_counts_after
from cte_most_recent_record_date_ladder
where date_trigger_event > date('2018-01-01')
group by ladder_advocacy;
select
cte_ladder_counts_before.ladder_advocacy,
cte_ladder_counts_before.ladder_counts_before,
ladder_counts_after,
ladder_counts_before - ladder_counts_after
from cte_ladder_counts_before
inner join cte_ladder_counts_after on cte_ladder_counts_before.ladder_advocacy = cte_ladder_counts_after.ladder_advocacy;
drop table cte_most_recent_record;
drop table cte_most_recent_record_date_ladder;
drop table cte_ladder_counts_before;
drop table cte_ladder_counts_after;
The error:
Sorry, we encountered an error and were unable to complete your request.
Failed to execute connection with error: Can not issue data manipulation statements with executeQuery().
Error ID: 24721465
I believe that this has something to do with that I have multiple tables within the same query - because I can run the query with just one of the select statements? But I am not sure if there are other data studio things I should be aware of.
Thoughts?
I know it's a bit late for an answer, but just in case someone needs this in the future. I ran into the same issue today. And the answer is quite frustrating as it is easy to solve.
You're using a CREATE TEMPORARY TABLE sentence (as I was doing too). Then I realized that DataStudio can't process that sentence. (Apparently, it can't do multi-queries either).
So my workaround was to actually CREATE the table in my database, not as a temporary one. (effective but not clean at all)... and delete the CREATE TEMPORARY TABLE sentence in my query. worked like a charm but on the dark side, now I have an useless table in my database just to process that query.
Hope it helps, kind regards.

MySQL Table does not exist, but it does

I am new to building databases, i have created a database for a website i am creating, and i keep getting this message "Executing SQL script in server
ERROR: Error 1146: Table 'mydb.franch' doesn't exist", when trying to forward engineer my database. The table does exist but it is not being read. (See image below). Please any help will be appreciated.
I can't add a comment, but in your image the table is "Franch" not "franch". Maybe that is the problem?
I may be wrong but I believe you are trying to access your table as (something like)
select * from 'mydb.franch'
or
select * from `mydb.franch`
In either case it's wrong and should be
select * from `mydb`.`franch`
MYSQL is case sensitive when creating a table, which means that you cannot create a table or variable with lower/upper case, and call it with upper/lower cases.
As such you must call the same name you used to create the table. In this case since the table is called mydb.Franch you would do: select * frommydb.Franch;`

Is there a way to copy the structure of a table (fields but no data) to a new table in MySQL?

For example, I have a table named movies. It has the fields/columns title VARCHAR(100) and runtime INT(5). It's loaded with 10,000 rows of data.
I want to create another table, let's call it movies_custom, that has all of the same columns, but with none of the data.
Is there a quick SQL statement to do this?
EDIT: Sorry, I noticed the SQL Server tag on this and assumed that was the technology you were using until I saw MySQL in the question title.
You can use the syntax CREATE movies_custom LIKE movies in MySQL
Sure!
In SQL Server you can do this query:
select top 0 * into movies_custom from movies
That creates the table structure without inserting any rows.
Very easy in MySQL:
CREATE newtable LIKE oldtable;
The other answers led me in the right direction, but I had to add the keyword TABLE in order to make it work with MySQL Workbench 6.
CREATE TABLE movies_custom LIKE movies;

MySQL dots in table names

I have an SQL database called copra4server, with a table called db_version.
I enter:
USE copra4server;
SELECT version FROM db_version;
And I get ERROR 1146 (42S02): Table 'copra4server.db_version' doesn't exist
Why is it trying to get a table named dbname.tablename and what does this dot notation mean?
The error is very clear. Your table db_version is not present in the copra4server database.
When you are saying USE copra4server; then it means that you want to use your copra4server database
And when you select from the table db_version the table is not present hence results in the error.
I think you are a bit confused about "databases" versus "database servers".
MySQL is a database server. You can connect to it and see databases. Note the plural here. One server, many databases.
One of the databases on your server is called copra4server. When you say:
USE copra4server
You are saying "my current database is now copra4server". So, any table you reference will be assumed to be in that database. Your query:
SELECT version FROM db_version;
Is really -- under the hood -- saying
SELECT version FROM copra4server..db_version;
And, the table does not exist, causing the error message.
By the way, if you are looking for the database version, the proper syntax is:
SELECT version()
That's how MySQL refers to tables (db.table) so it is clear that it is talking about the table in that db.
Check your spelling if you're sure the table exists.

mysql create table like to query?

Is it possible to use the create table query (create table t2 like t1) to get the query instead the actual table? Kind of like duplicating some management consoles Send To editor feature?
I think you're looking for SHOW CREATE TABLE tablename;
'tablename' can be the table within the current database, if you've selected one, or you can qualify it as in 'dbname.tablename'. The output can be used to create the table again. In fact, I sometimes use it in scripts that need to either use an existing table or create it if it doesn't exist. First I'll get the table creation info as shown above, and then I'll use something like"
CREATE TABLE IF NOT EXISTS tablename .........
Where '..........' is all the goodies that SHOW CREATE TABLE tablename gives me.
If you're interested in a good tutorial on MySQL (the database), as well as SQL (the language), you might have a look at the O'Reilly book, Learning MySQL. It's pretty good.