Skip to main content

Django backend for Snowflake

Project description

Snowflake backend for Django

Install and usage

Use the version of django-snowflake that corresponds to your version of Django. For example, to get the latest compatible release for Django 3.2.x:

pip install django-snowflake==3.2.*

The minor release number of Django doesn't correspond to the minor release number of django-snowflake. Use the latest minor release of each.

Configure the Django DATABASES setting similar to this:

DATABASES = {
    'default': {
        'ENGINE': 'django_snowflake',
        'NAME': 'MY_DATABASE',
        'SCHEMA': 'MY_SCHEMA',
        'WAREHOUSE': 'MY_WAREHOUSE',
        'USER': 'my_user',
        'PASSWORD': 'my_password',
        'ACCOUNT': 'my_account',
        # Include 'OPTIONS' if you need to specify any other
        # snowflake.connector.connect() parameters.
        # https://docs.snowflake.com/en/user-guide/python-connector-api.html#connect
        'OPTIONS': {},
    },
}

Notes on Django fields

  • Consistent with Snowflake's convention, this backend uppercases all database identifiers (table names, column names, etc.) unless they are quoted, e.g. db_table='"table_name"'.

  • Snowflake supports defining foreign key and unique constraints, however, it doesn't enforce them. Thus, Django manages these constraints and inspectdb detects them, but Django won't raise IntegrityError if they're violated.

  • Snowflake doesn't support indexes. Thus, Django ignores any indexes defined on models or fields.

  • Snowflake doesn't support check constraints, so the various PositiveIntegerField model fields allow negative values (though validation at the form level still works).

Notes on Django QuerySets

  • Snowflake has limited support for subqueries.

  • Valid values for QuerySet.explain()'s format parameter are 'json', 'tabular', and 'text'. The default is 'tabular'.

Known issues and limitations

This list isn't exhaustive. If you run into a problem, consult django_snowflake/features.py to see if a similar test is skipped. Please create an issue on GitHub if you encounter an issue worth documenting.

  • Snowflake doesn't support last_insert_id to retrieve the ID of a newly created object. Instead, this backend issues the query SELECT MAX(pk_name) FROM table_name to retrieve the ID. This is subject to race conditions if objects are created concurrently. This makes this backend inappropriate for use in web app use cases where multiple clients could be creating objects at the same time. Further, you should not manually specify an ID (e.g. MyModel(id=1)) when creating an object.

  • Snowflake only supports single layer transactions, but Django's TestCase requires that the database supports nested transactions. Therefore, Django's TestCase operates like TransactionTestCase, without the benefit of transactions to speed it up. A future version of Django (5.0 at the earliest) may leverage Snowflake's single layer transactions to give some speed up.

  • Due to snowflake-connector-python's lack of VARIANT support, some JSONField queries with complex JSON parameters don't work.

    For example, if value is a JSONField, this won't work:

    >>> JSONModel.objects.filter(value__k={"l": "m"})
    

    A workaround is:

    >>> from django.db.models.expressions import RawSQL
    >>> JSONModel.objects.filter(value__k=RawSQL("PARSE_JSON(%s)", ('{"l": "m"}',)))
    

    In addition, QuerySet.bulk_update() isn't supported for JSONField.

  • Interval math where the interval is a column is not supported.

  • Interval math with a null interval crashes.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-snowflake-3.2.tar.gz (22.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_snowflake-3.2-py3-none-any.whl (23.7 kB view details)

Uploaded Python 3

File details

Details for the file django-snowflake-3.2.tar.gz.

File metadata

  • Download URL: django-snowflake-3.2.tar.gz
  • Upload date:
  • Size: 22.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.0

File hashes

Hashes for django-snowflake-3.2.tar.gz
Algorithm Hash digest
SHA256 8b05598ac78a8a9dc7b49374ee1c22590be0b60a2a12240abf5d45792a813fa8
MD5 021092e7bc02c933685d805ed16d875a
BLAKE2b-256 aba4cbf2c3d654277750dc96373bcd02412a7d1e69dc6018c00cd5be19bce2ef

See more details on using hashes here.

File details

Details for the file django_snowflake-3.2-py3-none-any.whl.

File metadata

  • Download URL: django_snowflake-3.2-py3-none-any.whl
  • Upload date:
  • Size: 23.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.0

File hashes

Hashes for django_snowflake-3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a906b4db8102c508502927ea4a61ad7d71dcf8ad9026cd9a20a0c75c036f7b90
MD5 b5d07a4488db74ea462e3a9cb1e83375
BLAKE2b-256 1b7a1df379dae264f93d8b827d53e322f25a8ce054e8039bb8c71c984a7b6ae7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page