the enum type should be doing that check client side at this point, which is usually good enough. I would not have done the CHECK constraint feature of enum/boolean by default if it were today it has caused enormous problems.

On 01/05/2017 09:01 AM, Tim-Christian Mundt wrote:
That works, thanks.

There is no (easy) way to CHECK the elements of the array?


Am 05.01.2017 um 14:53 schrieb mike bayer <mike...@zzzcomputing.com>:

you probably want to add create_constraint=False, see if that works

http://docs.sqlalchemy.org/en/latest/core/type_basics.html?highlight=enum#sqlalchemy.types.Enum.params.create_constraint



On 01/05/2017 01:34 AM, Tim-Christian Mundt wrote:
Hi,

I've been using an array of enums with postgres and SQLAlchemy
successfully over the past year like so:

|classMyModel(BaseModel):enum_field
=Column(postgresql.ARRAY(EnumField(MyEnum,native_enum=False)))|

The |EnumField| is from the sqlalchemy_enum34
<https://github.com/spoqa/sqlalchemy-enum34> library, a small wrapper
around the builtin enum that uses Python enums as Python representation
instead of strings.

Although the docs say
<http://docs.sqlalchemy.org/en/rel_1_1/dialects/postgresql.html#using-enum-with-array>,
array of enum is not supported, I guess it worked, because I chose
'native_enum=False'. Recently I noticed that it doesn't work anymore, I
think it's due to the upgrade from SQLA 1.0 to 1.1, but I'm not sure.

The problem is, that it generates invalid DDL:

|CREATE TABLE my_model (enum_field VARCHAR(5)[3]NOT NULL CHECK (contexts
IN ('ONE','TWO','THREE')))|

The error I get is:

|ERROR: malformed array literal:"ONE"DETAIL: Arrayvalue must start
with"{"ordimension information.|

Any idea how I can get back my enum array?
By the way: when it worked, no CHECK constraint was actually created,
just an array of varying. I'm ok with that as long as I can use enums in
my Python code (e.g. |query.filter(enum_field==MyEnum.ONE)|)

Regards
Tim

--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and
Verifiable Example. See http://stackoverflow.com/help/mcve for a full
description.
---
You received this message because you are subscribed to the Google
Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to sqlalchemy+unsubscr...@googlegroups.com
<mailto:sqlalchemy+unsubscr...@googlegroups.com>.
To post to this group, send email to sqlalchemy@googlegroups.com
<mailto:sqlalchemy@googlegroups.com>.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

--
SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to