Skip to content

add full control for return type under PG ARRAY, HSTORE, JSON, JSONB indexed (element) access #3503

Closed

Description

@sqlalchemy-bot

Migrated issue, originally created by Michael Bayer (@zzzeek)

e.g., if I want myhstorecol['somecol'] to have a custom type, how do I do that? Some system that works for all of these types that defines the return types for indexed access should be devised.

1.1 because this is like a big deal, it's going to come up a lot, but no concrete plan right now.

Perhaps a "schema" dictionary. "*" is a wildcard:

HSTORE(schema={'*': String})
JSON(schema={'subdict': JSON(schema={'elements': ARRAY(Integer)}})
HSTORE(schema={'foob': String, 'bar': MyMagicType})


dictionary too coarse-grained? Supply a callable instead:

HSTORE(schema=lambda key: String if key =="foo" else MyMagicType)

Activity

  1. sqlalchemy-bot commented on Jul 29, 2015

    @sqlalchemy-bot
    CollaboratorAuthor

    Michael Bayer (@zzzeek) wrote:

    see also #3499 and #3487 which should refer to this system.

  2. sqlalchemy-bot commented on Aug 11, 2015

    @sqlalchemy-bot
    CollaboratorAuthor

    Michael Bayer (@zzzeek) wrote:

    The ongoing work here is in https://bitbucket.org/zzzeek/sqlalchemy/src/39adada25d71ac33d2a468cc19eb61c0fdfa9280/?at=ticket_3499, however the idea of the "schema" or "index_map" has been scaled back; it's not appropriate given that the PG JSON type always returns a json object no matter what you do to it; what index_map/schema would need to do is to automatically render CAST clauses for all of these types and that's just too elaborate and unnecessary.

    The latest in that branch has all three of array, hstore, json/jsonb working fully with a much simpler architecture than before.

  3. sqlalchemy-bot commented on Aug 17, 2015

    @sqlalchemy-bot
    CollaboratorAuthor

    Michael Bayer (@zzzeek) wrote:

    → ceeb033

  4. sqlalchemy-bot commented on Aug 17, 2015

    @sqlalchemy-bot
    CollaboratorAuthor

    Michael Bayer (@zzzeek) wrote:

    → ceeb033

  5. sqlalchemy-bot commented on Aug 17, 2015

    @sqlalchemy-bot
    CollaboratorAuthor

    Michael Bayer (@zzzeek) wrote:

    → ceeb033

  6. sqlalchemy-bot commented on Aug 17, 2015

    @sqlalchemy-bot
    CollaboratorAuthor

    Changes by Michael Bayer (@zzzeek):

    • changed status to closed
  7. added this to the 1.1 milestone on Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions