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

update gives no such table error #83

Open
SteveScott opened this issue Jun 5, 2020 · 2 comments
Open

update gives no such table error #83

SteveScott opened this issue Jun 5, 2020 · 2 comments

Comments

@SteveScott
Copy link

I try the following code:
daily_df = pd.DataFrame({'date': [1, 2, 3, 4, 5], 'visitor_count': [10, 20, 30, 40, 50] }) row_df = pd.DataFrame({'date': [1, 2, 3], 'visitor_count': [60, 70, 80]}) column_name = 'visitor_count' test = sqldf("SELECT * FROM daily_df") sqldf("UPDATE daily_df SET {} = row_df.{} WHERE date = row_df.date;".format(column_name, column_name), globals())

The select statement works. the update statement fails and says there is no such table. If you can read a dataframe as a table, shouldn't you be able to write to a dataframe as if it were a table?

@TheGlobalist
Copy link

As far as I've seen in their source code, there is no support at all for UPDATE or DELETE actions.

def extract_table_names(query):
    """ Extract table names from an SQL query. """
    # a good old fashioned regex. turns out this worked better than actually parsing the code
    tables_blocks = re.findall(r'(?:FROM|JOIN)\s+(\w+(?:\s*,\s*\w+)*)', query, re.IGNORECASE)
    tables = [tbl
              for block in tables_blocks
              for tbl in re.findall(r'\w+', block)]
    return set(tables)

The regex is based only on a SELECT clause, so UPDATEs and DELETEs will fail

@TheGlobalist
Copy link

@SteveScott if you need it, I've made a PR for this
#85

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

2 participants