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

MySQL.load does not use column names #209

Open
jeffpollock9 opened this issue Aug 8, 2023 · 0 comments
Open

MySQL.load does not use column names #209

jeffpollock9 opened this issue Aug 8, 2023 · 0 comments

Comments

@jeffpollock9
Copy link

Hi,

As far as I can see, MySQL.load does not use any information about column names and I think this can lead to bad behaviour, see for example:

using MySQL
using DataFrames

conn = DBInterface.connect(
    MySQL.Connection,
    ...
)

df1 = DataFrame(x = [1], y = [2])
MySQL.load(df1, conn, "test")

df2 = DataFrame(y = [3], x = [4])
MySQL.load(df2, conn, "test", createtableclause = "#")

DataFrame(DBInterface.execute(conn, "select * from test"))
# =>
# 2×2 DataFrame
#  Row │ x       y
#      │ Int64?  Int64?
# ─────┼────────────────
#    1 │      1       2
#    2 │      3       4

df3 = DataFrame(foo = [5], bar = [6])
MySQL.load(df3, conn, "test", createtableclause = "#")

DataFrame(DBInterface.execute(conn, "select * from test"))
# =>
# 3×2 DataFrame
#  Row │ x       y
#      │ Int64?  Int64?
# ─────┼────────────────
#    1 │      1       2
#    2 │      3       4
#    3 │      5       6

so if someone accidentally gets the columns in a different order from the ones on the DB, or even has completely different column names, the (very likely wrong) data will still be appended to the table.

I think it would be great if MySQL.load could match up the input column names with those on the DB, and throw an error in the case it is not possible.

If there is some other way to ensure this, or if I can help at all - please let me know.

Thanks!

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

No branches or pull requests

1 participant