0

I refactored a project and wanted to try out PostgreSQL instead of MySQL. I now want to migrate the table contents of some tables.

The problem is, when I use a select query like this (don't bother about the names, is just an example)

SELECT id AS id_x, name AS name_x, name2 AS name2_x

I want to export the table data and import it into MySQL. The problem is, that the syntax for INSERT INTO is different in MySQL and PostgreSQL. I don't want to export the whole table, because I also changed some parts of the structure, tried to make it more performant etc. So I just want to get the table data, but I need those AS x thing, because the names of the columns have changed

I already found several links on this topic.

I can use mysqldump to dump the table and set the --compatible=name parameter. The problem here is, that I can't add a SELECT statement, right? I can only add a where check.

Then, I could use the mysql command to export the query I want, but mysql doesn't have any compatible parameter. How would I achieve that?

1 Answer 1

1

You could consider to create a temporaty table by issuing

SELECT id AS id_x, name AS name_x, name2 AS name2_x FROM oldtable INTO temptable

And then as a second step export the temptable using mysqldump with the --compatible= parameter.

See https://dev.mysql.com/doc/refman/5.7/en/select-into.html

Sign up to request clarification or add additional context in comments.

1 Comment

I'm an idiot for not thinking about that haha. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.