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

How to create an MS SQL copy of the MaStR Database? #503

Open
tomfelder94 opened this issue Apr 3, 2024 · 6 comments
Open

How to create an MS SQL copy of the MaStR Database? #503

tomfelder94 opened this issue Apr 3, 2024 · 6 comments

Comments

@tomfelder94
Copy link

I would like to have our own copy of the MaStR database, hosted on a MS SQL server. Did I understand correctly, that this should be possible by passing the respective engine to the Mastr() instance?

I tried the following below:

from open_mastr import Mastr
from sqlalchemy import create_engine

connection_string = 'mssql+pyodbc://@<SERVER>/MarketAnalysis?driver=ODBC+Driver+17+for+SQL+Server'
ma_engine = create_engine(connection_string)
db = Mastr(engine=ma_engine)

But then I get the following error:
sqlalchemy.exc.ProgrammingError: (pyodbc.ProgrammingError) ('42000', "[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Column 'EinheitMastrNummer' in table 'basic_units' is of a type that is invalid for use as a key column in an index. (1919) (SQLExecDirectW); [42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Could not create constraint or index. See previous errors. (1750)")

Is that a bug or am I trying to do something that is not possible? What would be the best solution for me to create my own copy of the MaStR database, hosted on an MS SQL server?

@tomfelder94 tomfelder94 changed the title Your title should make sense if said after "The issue is <your issue title>" How to create an MS SQL copy of the MaStR Database? Apr 3, 2024
@FlorianK13
Copy link
Member

Hi @tomfelder94 - we only maintain code for building either an sqlite or a postgres database. So I think there are two options:

  1. you can either use one of those two options as a database.
  2. or you download the data and write it to sqlite, and then write some own code to transfer the data from sqlite to MS SQL server.

@chrwm
Copy link
Member

chrwm commented Apr 24, 2024

If this still of interest, please reopen.

@chrwm chrwm closed this as completed Apr 24, 2024
@tuxiano
Copy link

tuxiano commented Sep 30, 2024

@chrwm I have the very same issue. PostgreSQL/sqlite unfortunately is no option.

@FlorianK13 FlorianK13 reopened this Sep 30, 2024
@nesnoj
Copy link
Collaborator

nesnoj commented Oct 24, 2024

Hey, have you found a way to get this working? @tuxiano @tomfelder94
I understand your needs but this project runs on a very limited amount of time and we have to focus on the core functionalities. We are always happy about contributions :)

@tomfelder94
Copy link
Author

@nesnoj

Unfortunately, not. Transferring the data to an SQL Server is not that straightforward, regarding the amount of data there is. Especially since we want to sync/update the tables on a regular basis (ideally on a daily basis). There are solutions with paywalls that are converting SQLite to SQL tables, but they are quite expensive and therefore not an option for us.

We are working with the SQLite DB at the moment but would be highly interested if anyone has a solution for migrating from SQLite to SQL in an automated low cost way.

@nesnoj
Copy link
Collaborator

nesnoj commented Dec 3, 2024

Hey @tomfelder94!

The error message above reads like there's a problem with String columns as primary key on MS SQL (an index is created for each PK). String corresponds to SQL varchar, in this case with no predefined length in the ORM: EinheitMastrNummer = Column(String, primary_key=True).

This is ok for postgreSQL. However, a quick search revealed that MS SQL follows a more strict data typing, SQL Server requires a specified length for VARCHAR when creating indexes or primary keys to determine storage requirements and enforce uniqueness.

So to write the data into a MS SQL DB you would need to adjust the orm.py to meet these requirements: you could try to fix the lengths for the PKs beforehand and see what happens.

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

5 participants