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

SUPER column support #224

Closed
rectalogic opened this issue Jul 14, 2021 · 2 comments
Closed

SUPER column support #224

rectalogic opened this issue Jul 14, 2021 · 2 comments

Comments

@rectalogic
Copy link
Contributor

Support for Redshift SUPER column types would be useful.
https://docs.aws.amazon.com/redshift/latest/dg/super-overview.html

Currently we are using something like this (uses SUPER with redshift dialect, and text with other dialects)

import json
import sqlalchemy as sa
import sqlalchemy.ext.compiler
from sqlalchemy import types


class _JSONText(types.Text):
    def bind_expression(self, bindvalue):
        return sa.func.json_parse(bindvalue)


class SUPER(types.TypeDecorator):
    impl = types.Text

    def load_dialect_impl(self, dialect):
        if dialect.name == "redshift":
            return _JSONText()
        return super().load_dialect_impl(dialect)

    def process_bind_param(self, value, dialect):
        if not isinstance(value, str):
            return json.dumps(value)  # should make json.JSONEncoder class configurable here
        return value


@sqlalchemy.ext.compiler.compiles(SUPER, "redshift")
def compile_super_redshift(type_, compiler, **kw):
    return "SUPER"


@sa.event.listens_for(sa.Table, "column_reflect")
def setup_super_type(inspector, table, column_info):
    if isinstance(column_info["type"], types.NullType):
        column_info["type"] = SUPER()
@raajpackt
Copy link

How to import the SUPER type such that i could pass it as an argument in the dtype field while using pandas.DataFrame.to_sql ?

@jklukas
Copy link
Member

jklukas commented Nov 3, 2021

Addressed in #235

@jklukas jklukas closed this as completed Nov 3, 2021
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

3 participants