GithubHelp home page GithubHelp logo

CIText Array about sqlalchemy-citext HOT 13 CLOSED

mahmoudimus avatar mahmoudimus commented on June 12, 2024
CIText Array

from sqlalchemy-citext.

Comments (13)

mahmoudimus avatar mahmoudimus commented on June 12, 2024 1

@lukas-gitl this is awesome! I can make it into a proper pull request and see how to integrate it. thank you so much!

from sqlalchemy-citext.

rmihael avatar rmihael commented on June 12, 2024 1

There is a better way to make CITEXT work with arrays. If CITEXT[] is registered as an array type in psycopg2, then everything works just fine without any monkey patching. That can be accomplished with that snippet:

def register_citext_array(engine):
    results = engine.execute(text("SELECT typarray FROM pg_type WHERE typname = 'citext'"))
    oids = tuple(row[0] for row in results)
    array_type = psycopg2.extensions.new_array_type(oids, b'citext[]', psycopg2.STRING)
    psycopg2.extensions.register_type(array_type, None)

It would be great to include something about it to README.

from sqlalchemy-citext.

lukas-gitl avatar lukas-gitl commented on June 12, 2024

Would be great to get this into this project somehow.

from sqlalchemy-citext.

mahmoudimus avatar mahmoudimus commented on June 12, 2024

@lukas-gitl or..you can take a stab at a PR? :)

from sqlalchemy-citext.

lukas-gitl avatar lukas-gitl commented on June 12, 2024

Edited initial post with small fix for stripping quotes

from sqlalchemy-citext.

lukas-gitl avatar lukas-gitl commented on June 12, 2024

Updated it again to use csv. This seems to solve all issues here.

from sqlalchemy-citext.

mahmoudimus avatar mahmoudimus commented on June 12, 2024

@lukas-gitl thanks for this! I'll get to it this weekend.

from sqlalchemy-citext.

rmihael avatar rmihael commented on June 12, 2024

Hi! Any hopes for releasing this fix?

from sqlalchemy-citext.

HansBouwmeester avatar HansBouwmeester commented on June 12, 2024

@rmihael Thanks!!! Works great except that for me psycopg2 told me it expected b'citext[]' as a regular string (not bytes): 'citext[]'.

from sqlalchemy-citext.

mzpqnxow avatar mzpqnxow commented on June 12, 2024

It looks like this works now

On a related note- I stumbled upon this issue while trying to make sqlacodegen produce CIText and CIText[] columns. I ended up using sqlalchemy-citext to do it. It works well and was a very, very small patch. Please see agronholm/sqlacodegen#125 if you use sqlacodegen and want CIText and CIText[] support

from sqlalchemy-citext.

mzpqnxow avatar mzpqnxow commented on June 12, 2024

I wonder if this can be closed now as it seems to be working

from sqlalchemy-citext.

mahmoudimus avatar mahmoudimus commented on June 12, 2024

I will update the README! Thanks

from sqlalchemy-citext.

mzpqnxow avatar mzpqnxow commented on June 12, 2024

@mahmoudimus I sent #19 which is the register function that @rmihael suggested. I tested this on CPython 3.7 and it works well, fixes the problem of getting back characters instead of strings. It needs to be explicitly called, so in theory it shouldn't break anyone who isn't explicitly using it

from sqlalchemy-citext.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.