I am new to SqlAlchemy and Firebird DB.
I can directly create a table using DBeaver:
CREATE TABLE NEWTABLE (
COLUMN1 FLOAT,
COLUMN2 FLOAT
);
but if I try to do the same using pyndas+sqlalchemy I get an error:
import sqlalchemy as sa
import pandas as pd
engine = sa.create_engine(r'firebird+fdb://user:pwd@localhost:3050/c:\XXX.FDB', echo=False)
df = pd.DataFrame({"COLUMN1":[], "COLUMN2":[]})
df.to_sql(name="NEWTABLE", con=engine, if_exists = 'replace', index=False, method=None)
DatabaseError: (fdb.fbcore.DatabaseError) ('Error while preparing SQL statement:\n- SQLCODE: -817\n- Dynamic SQL Error\n- SQL error code = -817\n- Metadata update statement is not allowed by the current database SQL dialect 1', -817, 335544569)
[SQL:
CREATE TABLE "NEWTABLE" (
COLUMN1 FLOAT,
COLUMN2 FLOAT
)
The problem is due to the quotation marks "..."
in to_sql
query.
- How to tell sqlalchemy not to use quotation marks to be compatible with Firebird (dialect 1)?
as an alternative:
- Instead of executing the query immediately, is it possible to produce the query string only from
to_sql
and execute it later withresult = engine.execute(query)
? This would give the possibility to fix these incompatibilities before execution.