Skip to content

Instantly share code, notes, and snippets.

@johnidm
Created April 3, 2023 13:46
Show Gist options
  • Save johnidm/5089d7dc1a1ab7d9a98be611906541d1 to your computer and use it in GitHub Desktop.
Save johnidm/5089d7dc1a1ab7d9a98be611906541d1 to your computer and use it in GitHub Desktop.
SQLAlchemy get RDBMS name

Each RDBMS has a specify DB-API, if you app is able to work with differentes RDBMS probably in some cases you will need to execute specifics SQL statements for ech one.

The SQLAlchemy dialect defines the behavior of a specific database and DB-API combination. The dialect name can be used to identify the vendor of the RDBMS.

The connection string provides various database information, so you can get these parameters by following the code below:

from sqlalchemy.engine import make_url

CONNs = [
  "oracle+cx_oracle://user:pass@127.0.0.1:1521/?service_name=data01base",
  "postgresql+psycopg2://user:pass@127.0.0.1:5432/data01base",
  "sqlite:////tmp/database.db",
]

for conn in CONNs:
    url = make_url(conn)
    print(url.get_backend_name())    

The function get_backend_name can be used to identify the RDBMS vendor of you database.

The most common RDBMS providers are: Oracle, Postgresql, MySQL, MYSQL, etc.

Full documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment