Re: [sqlalchemy] rendering "NOT EXISTS ()" in PostgreSQL ?

2019-03-20 Thread Jonathan Vanasco
thanks, mike. I may just make a 'not exists' op. there are a handful of places in the docs that show `NOT EXISTS` with no parenthesis. Do you think this is because of a change in the codebase or a difference in the backends? If it's because of legacy code, I can generate a PR to update the

[sqlalchemy] Foreign Key Constraint In Different Database Support

2019-03-20 Thread mkwyche
Hi, I have two classes: ```python class PlayerPro(MESA_BASE): ''' player_pro model ''' __tablename__ = "player_pro" # Primary Keys ebis_id = Column(MEDIUMINT(9), primary_key=True) bam_id = Column(MEDIUMINT(9), index=True) phil_id = Column(MEDIUMINT(9), index=True)

[sqlalchemy] Index on nested JSONB field

2019-03-20 Thread david scheck
Hi everyone, I'm trying to implement a nested JSONB index on a nested field in the json file. I searched through internet and came at the conclusion that I had to create it manually. so that's where I am. op.create_index('ix_law_search_vector', 'law', ['search_vector'], unique=False,

[sqlalchemy] binding parameters in quotes

2019-03-20 Thread mdob
Hi, Is it correct behavior that parameter placeholders *in quotes* e.g. SELECT * FROM Artist WHERE Name LIKE "%:pattern%" are recognized as valid parameters? from sqlalchemy.sql import text from sqlalchemy.dialects import sqlite from sqlalchemy import create_engine engine =

Re: [sqlalchemy] Event do not fire on m2m relation

2019-03-20 Thread Денис Ралко
Sorry, my mistake Site.entity_id == MODEL_2.id And I solve my problem by change mapper.attrs -> mapper.column_attrs And now I want to ask you Can event directly set on Table colums? On Monday, March 18, 2019 at 10:28:54 PM UTC+2, Mike Bayer wrote: > > On Mon, Mar 18, 2019 at 11:07 AM Денис

[sqlalchemy] Re: Foreign Key Constraint In Different Database Support

2019-03-20 Thread mkwyche
Also I tried to put in their mesa.player_pro.phil_Id instead of the actual column and I get this error: ``` sqlalchemy.exc.NoReferencedTableError: Foreign key associated with column 'eval_pro_hit.phil_id' could not find table 'mesa.player_pro' with which to generate a foreign key to target

[sqlalchemy] Re: Foreign Key Constraint In Different Database Support

2019-03-20 Thread mkwyche
For anyone else that runs into a similar issue. This https://stackoverflow.com/questions/43584453/how-to-handle-cross-schema-foreign-key-in-sqlalchemy was helpful. I needed to add ``` __table_args__ = {'schema': 'mesa'} ``` To `player_pro` model. Then it worked. Why isn't the schema derived

[sqlalchemy] is it possible to use a secondary lookup against a session's object map (or other ideas to handle a weird use-case)?

2019-03-20 Thread Jonathan Vanasco
I doubt this is possible, but SqlAlchemy supports so many oddities it might be... I have an association class/table which has a primary key on the serial column `id`, and a unique constraint on the columns `id_a` and `id_b` which acts as a secondary key. is there a sane way to use something

Re: [sqlalchemy] is it possible to use a secondary lookup against a session's object map (or other ideas to handle a weird use-case)?

2019-03-20 Thread Simon King
On Wed, Mar 20, 2019 at 5:13 PM Jonathan Vanasco wrote: > > I doubt this is possible, but SqlAlchemy supports so many oddities it might > be... > > I have an association class/table which has a primary key on the serial > column `id`, and a unique constraint on the columns `id_a` and `id_b`

[sqlalchemy] rendering "NOT EXISTS ()" in PostgreSQL ?

2019-03-20 Thread Jonathan Vanasco
Is it possible to easily render "NOT EXISTS( " with a current API command? Both `~exists(` and `not_(exists(` will render "NOT ( EXISTS( ". I need to remove the superfluous parenthesis (this has to do with unit tests and ensuring parity of SQL across a handful of apps and custom commands). I

Re: [sqlalchemy] Re: Foreign Key Constraint In Different Database Support

2019-03-20 Thread mkwyche
Here's the code I'm using to create `declarative_base`: ``` PHIL_DATA = "phil_data" PHIL_DATA3 = "phil_data3" MESA = "mesa" SQL_DEBUG = bool(os.getenv("SQL_DEBUG", False)) _ENGINE_PHIL_DATA = get_mysql_engine(database=PHIL_DATA, echo=SQL_DEBUG) _ENGINE_PHIL_DATA3 =

Re: [sqlalchemy] Index on nested JSONB field

2019-03-20 Thread Mike Bayer
On Wed, Mar 20, 2019 at 11:04 AM david scheck wrote: > > Hi everyone, > > I'm trying to implement a nested JSONB index on a nested field in the json > file. I searched through internet and came at the conclusion that I had to > create it manually. > > so that's where I am. > >

Re: [sqlalchemy] Event do not fire on m2m relation

2019-03-20 Thread Mike Bayer
On Wed, Mar 20, 2019 at 7:54 AM Денис Ралко wrote: > > Sorry, my mistake > > Site.entity_id == MODEL_2.id > And I solve my problem by change mapper.attrs -> mapper.column_attrs > > And now I want to ask you > Can event directly set on Table colums? events for changes of value need to be set for

Re: [sqlalchemy] binding parameters in quotes

2019-03-20 Thread Mike Bayer
On Wed, Mar 20, 2019 at 7:59 AM mdob wrote: > > Hi, > > > Is it correct behavior that parameter placeholders in quotes e.g. SELECT * > FROM Artist WHERE Name LIKE "%:pattern%" are recognized as valid parameters? > > > from sqlalchemy.sql import text > from sqlalchemy.dialects import sqlite >

Re: [sqlalchemy] Re: Foreign Key Constraint In Different Database Support

2019-03-20 Thread Mike Bayer
On Wed, Mar 20, 2019 at 7:43 AM mkwyche wrote: > > For anyone else that runs into a similar issue. This > https://stackoverflow.com/questions/43584453/how-to-handle-cross-schema-foreign-key-in-sqlalchemy > was helpful. > > I needed to add > ``` > __table_args__ = {'schema': 'mesa'} > ``` > > To

Re: [sqlalchemy] rendering "NOT EXISTS ()" in PostgreSQL ?

2019-03-20 Thread Mike Bayer
The precedence for EXISTS is lower than that of neg in sql/operators.py so it will always render the parenthesis unless those precedences are changed. otherwise you can use op() or whatever, ~op("EXISTS")("foo") from sqlalchemy import select, column, Boolean from sqlalchemy.sql.expression import

Re: [sqlalchemy] is it possible to use a secondary lookup against a session's object map (or other ideas to handle a weird use-case)?

2019-03-20 Thread Jonathan Vanasco
Thanks Simon! For now I'm using a dirty hack - I created a view of the table, and mapped another class to that view. So I have a writeable class based on the 'id', and a readable based on the tuple. This fixes my database traffic issue for the time being. -- SQLAlchemy - The Python SQL

Re: [sqlalchemy] Re: Foreign Key Constraint In Different Database Support

2019-03-20 Thread mkwyche
Thanks for the help. Is it best practice to use one declarative_base for all models and set the schema on any Models that reference separate databases? On Wednesday, March 20, 2019 at 5:14:30 PM UTC-4, Mike Bayer wrote: > > the biggest issue is that you are being confused by the ".bind" >

Re: [sqlalchemy] Re: Foreign Key Constraint In Different Database Support

2019-03-20 Thread Mike Bayer
On Wed, Mar 20, 2019 at 5:52 PM mkwyche wrote: > > Thanks for the help. Is it best practice to use one declarative_base for all > models and set the schema on any Models that reference separate databases? I think people usually use one declarative_base shared for all the classes in their

Re: [sqlalchemy] Re: Foreign Key Constraint In Different Database Support

2019-03-20 Thread mkwyche
Awesome thanks again really appreciate it! On Wednesday, March 20, 2019 at 5:58:44 PM UTC-4, Mike Bayer wrote: > > On Wed, Mar 20, 2019 at 5:52 PM mkwyche > > wrote: > > > > Thanks for the help. Is it best practice to use one declarative_base for > all models and set the schema on any Models

Re: [sqlalchemy] Re: Foreign Key Constraint In Different Database Support

2019-03-20 Thread mkwyche
I think I see my biggest issue now. I thought that I needed multiple `declarative_base` for each database but I can use the same one for all models and specify schema. On Wednesday, March 20, 2019 at 1:02:47 PM UTC-4, mkwyche wrote: > > Here's the code I'm using to create `declarative_base`: >

Re: [sqlalchemy] Re: Foreign Key Constraint In Different Database Support

2019-03-20 Thread Mike Bayer
the biggest issue is that you are being confused by the ".bind" argument to MetaData, in that it suggests the MetaData would know about the default schema name of the engine which is not the case. The .bind argument will be going away in a future release for reasons like this. On Wed, Mar 20,