Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL file: MySQL import errors #52

Open
hankszeto opened this issue Jan 15, 2025 · 0 comments · May be fixed by #53
Open

SQL file: MySQL import errors #52

hankszeto opened this issue Jan 15, 2025 · 0 comments · May be fixed by #53

Comments

@hankszeto
Copy link

Importing the .sql file into MySQL/MaraiDB results in errors:

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'INSERT INTO auspostcodes (otherid, pcode,locality,state,auspostcodes.long,l...' at line 2

The issue seems to be with the table name and column names in the INSERT INTO statement. The column names shouldn't be prefixed with the table name (at least from MySQL's point of view).

INSERT INTO `auspostcodes` (otherid, pcode,locality,state,auspostcodes.long,lat,deliveryoffice,auspostcodes.type,dateofupdate) VALUES ('230','0200','ANU','ACT','0','0','','','2020-02-06 05:03')

Here is the corrected SQL statement using backticks to quote the reserved words:

INSERT INTO `auspostcodes` (otherid, pcode, locality, state, `long`, lat, deliveryoffice, `type`, dateofupdate) VALUES ('230','0200','ANU','ACT','0','0','','','2020-02-06 05:03')

Here is a sed command to do a bulk change to the SQL file:

sed -i '' -e 's/auspostcodes\.long/`long`/g' -e 's/auspostcodes\.type/`type`/g' australian_postcodes.sql

The other error the came up was that a semi-colon ; is needed between each insert statement.

Here is another sed command to fix this:

sed -i '' -e '/INSERT INTO `auspostcodes`.*[^;]$/s/$/;/' australian_postcodes.sql

After these changes I was able to import the .sql file into MariaDB.

@hankszeto hankszeto linked a pull request Jan 15, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant