[sqlalchemy] Re: Track a "column FOO does not exist" bug.

2019-09-05 Thread Jonathan Vanasco


On Thursday, September 5, 2019 at 8:58:16 AM UTC-4, Riccardo Cagnasso wrote:
>
> I don't think so. Wouldn't postgres prevented me deleting the column if it 
> were? 
>

PostgreSQL will prevent you from deleting the column if it were a 
CONSTRAINT, but would not necessarily notice it on a trigger / function.

I would check the db to see if there are any triggers/functions that used 
that column.

I would also trash any/all .pyc and .pyo files (or other compiled filed) to 
make sure you're not picking up an old file. That sometimes happens.



For example:


 CREATE TABLE foo_bar (
 id INT PRIMARY KEY,
 foo BOOLEAN DEFAULT NULL,
 bar BOOLEAN DEFAULT NULL
 );


 CREATE OR REPLACE FUNCTION foo_bar__trigger() RETURNS trigger AS 
$foo_bar__trigger$
 BEGIN
 IF NEW.foo is True
 THEN
 NEW.bar := True;
 END IF;
 RETURN NEW;
 END;
 $foo_bar__trigger$ LANGUAGE plpgsql;


 DROP TRIGGER IF EXISTS foo_bar__trigger on foo_bar;


 CREATE TRIGGER foo_bar__trigger BEFORE INSERT OR UPDATE ON foo_bar
 FOR EACH ROW EXECUTE PROCEDURE foo_bar__trigger();


 ALTER TABLE foo_bar DROP foo;
 
 INSERT INTO foo_bar (id, foo) VALUES (1, True);



That creates this error:

ERROR: record "new" has no field "bar"
 CONTEXT: PL/pgSQL function foo_bar__trigger() line 5 at assignment


-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/5e927026-97a5-4bd9-ab5f-6ca6df700108%40googlegroups.com.


Re: [sqlalchemy] Complex Constraints in Many to Many relationships

2019-09-05 Thread Mike Bayer
I wasn't totally sure if it worked! glad i could help

On Thu, Sep 5, 2019, at 12:26 PM, Michael P. McDonnell wrote:
>  You make it seem so easy.
> 
> Thank you!
> 
> On Thu, Sep 5, 2019 at 11:11 AM Mike Bayer  wrote:
>> __
>> 
>> 
>> On Wed, Sep 4, 2019, at 5:12 PM, Michael P. McDonnell wrote:
>>> Hey - 
>>> I'm again at a loss of what to google, and as this will ultimately need to 
>>> be represented in some fashion in sqlalchemy, I figured this is a great 
>>> place to start:
>>> 
>>> I have a |person| table and a |team| table with a many to many table in 
>>> between |team_person|.
>>> Simple enough!
>>> 
>>> Now - to make it fun.
>>> |team| has a relationship to |tournament|
>>> How can I prevent a user from joining more than 1 team in a given 
>>> tournament?
>>> 
>>> I thought about adding a 3rd column to my M2M table, 
>>> (team_tournament_person), but that could still fail because it could be a 
>>> team from tournament x, tournament y's ID and a Person Q's ID. 
>> 
>> if you make team_person have tournament_id, person_id, team_id, then 
>> team_person has (tournament_id, person_id) as primary key, that means 
>> person_id can only be part of a tournament_id once. Then you create foreign 
>> key on team_person for (team_id, tournament_id) to team_table(id, 
>> tournament_id). this might need you to create a unique constraint on 
>> team(id, tournament_id) or set that as its primary key.
>> 
>> 
>>> 
>>> So any suggestions on what I should be googling, and then how to implement 
>>> in SA would be hugely appreciated!
>>> 
>>> Thanks!
>>> 

>>> --
>>> 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 view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/sqlalchemy/CAHmCLHq%2BCorBMogufyGh6jpX%2BBt6gNpT38oPe4TJ85xDoahHxQ%40mail.gmail.com
>>>  
>>> .
>> 
>> 

>> --
>>  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 view this discussion on the web visit 
>> https://groups.google.com/d/msgid/sqlalchemy/e644c7a1-c72e-42a3-b9dc-262775c46cf5%40www.fastmail.com
>>  
>> .
> 

> --
>  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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/CAHmCLHoOqeBCL9ZEnBy7zsu0WJQtAuvOz7USanfSMe4bVXqqPw%40mail.gmail.com
>  
> .

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/22f3367c-4b16-4ccb-9c35-2fa652b723a2%40www.fastmail.com.


Re: [sqlalchemy] Complex Constraints in Many to Many relationships

2019-09-05 Thread Michael P. McDonnell
 You make it seem so easy.

Thank you!

On Thu, Sep 5, 2019 at 11:11 AM Mike Bayer  wrote:

>
>
> On Wed, Sep 4, 2019, at 5:12 PM, Michael P. McDonnell wrote:
>
> Hey -
> I'm again at a loss of what to google, and as this will ultimately need to
> be represented in some fashion in sqlalchemy, I figured this is a great
> place to start:
>
> I have a |person| table and a |team| table with a many to many table in
> between |team_person|.
> Simple enough!
>
> Now - to make it fun.
> |team| has a relationship to |tournament|
> How can I prevent a user from joining more than 1 team in a given
> tournament?
>
> I thought about adding a 3rd column to my M2M table,
> (team_tournament_person), but that could still fail because it could be a
> team from tournament x, tournament y's ID and a Person Q's ID.
>
>
> if you make team_person have tournament_id, person_id, team_id, then
> team_person has (tournament_id, person_id) as primary key, that means
> person_id can only be part of a tournament_id once.  Then you create
> foreign key on team_person for (team_id, tournament_id) to team_table(id,
> tournament_id).  this might need you to create  a unique constraint on
> team(id, tournament_id) or set that as its primary key.
>
>
>
> So any suggestions on what I should be googling, and then how to implement
> in SA would be hugely appreciated!
>
> Thanks!
>
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/sqlalchemy/CAHmCLHq%2BCorBMogufyGh6jpX%2BBt6gNpT38oPe4TJ85xDoahHxQ%40mail.gmail.com
> 
> .
>
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/sqlalchemy/e644c7a1-c72e-42a3-b9dc-262775c46cf5%40www.fastmail.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/CAHmCLHoOqeBCL9ZEnBy7zsu0WJQtAuvOz7USanfSMe4bVXqqPw%40mail.gmail.com.


Re: [sqlalchemy] Complex Constraints in Many to Many relationships

2019-09-05 Thread Mike Bayer


On Wed, Sep 4, 2019, at 5:12 PM, Michael P. McDonnell wrote:
> Hey - 
> I'm again at a loss of what to google, and as this will ultimately need to be 
> represented in some fashion in sqlalchemy, I figured this is a great place to 
> start:
> 
> I have a |person| table and a |team| table with a many to many table in 
> between |team_person|.
> Simple enough!
> 
> Now - to make it fun.
> |team| has a relationship to |tournament|
> How can I prevent a user from joining more than 1 team in a given tournament?
> 
> I thought about adding a 3rd column to my M2M table, 
> (team_tournament_person), but that could still fail because it could be a 
> team from tournament x, tournament y's ID and a Person Q's ID. 

if you make team_person have tournament_id, person_id, team_id, then 
team_person has (tournament_id, person_id) as primary key, that means person_id 
can only be part of a tournament_id once. Then you create foreign key on 
team_person for (team_id, tournament_id) to team_table(id, tournament_id). this 
might need you to create a unique constraint on team(id, tournament_id) or set 
that as its primary key.


> 
> So any suggestions on what I should be googling, and then how to implement in 
> SA would be hugely appreciated!
> 
> Thanks!
> 

> --
>  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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/CAHmCLHq%2BCorBMogufyGh6jpX%2BBt6gNpT38oPe4TJ85xDoahHxQ%40mail.gmail.com
>  
> .

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/e644c7a1-c72e-42a3-b9dc-262775c46cf5%40www.fastmail.com.


Re: [sqlalchemy] Re: Complex Constraints in Many to Many relationships

2019-09-05 Thread Michael P. McDonnell
*bump* anything?

On Wed, Sep 4, 2019 at 5:02 PM Michael P. McDonnell 
wrote:

> So I must be missing something, but here's what I have right now:
>
> tournament_table = Table(
> 'tournament',
> Base.metadata,
> Column('id', UUID(as_uuid=True), primary_key=True))
>
> team_table = Table(
> 'team',
> Base.metadata,
> Column('id', UUID(as_uuid=True), primary_key=True,
> *Column('tournament_id', UUID(as_uuid=True), ForeignKey('tournament.id
> '), nullable=False),*
> Column('display_name', String(length=255), nullable=False),
> UniqueConstraint('tournament_id', 'display_name'))
>
> team_person_table = Table(
> 'team_person',
> Base.metadata,
> *Column('team_id', UUID(as_uuid=True), ForeignKey('team.id
> '), primary_key=True*),
> *Column('person_id', UUID(as_uuid=True), ForeignKey('person.id
> '), primary_key=True)*)
>
> person_table = Table(
> 'person',
> Base.metadata,
> Column('id', UUID(as_uuid=True), primary_key=True))
>
>
> In my current model I can create
>
> Tournament A, Team A (paired to Tournament A), Team B (also paired to
> Tournament A), and Team C (also paired to Tournament A)
> I can then assign *Person Z* to Team A, Team B and Team C separately
> without throwing an integrity exception.
>
> How can I make it so that doesn't happen?
>
>
> On Wed, Sep 4, 2019 at 4:53 PM Derek Lambert 
> wrote:
>
>> If I'm understanding correctly...
>>
>> You're on the right track. I'd use a composite primary key on
>> |team_person|, consisting of foreign keys from |person| and |team|, and
>> another composite key (or unique index) on the |team| to |tournament|
>> table. This lets the database do all the work.
>>
>> -Derek
>>
>> On Wednesday, September 4, 2019 at 4:16:02 PM UTC-5, Michael P. McDonnell
>> wrote:
>>>
>>> Hey -
>>> I'm again at a loss of what to google, and as this will ultimately need
>>> to be represented in some fashion in sqlalchemy, I figured this is a great
>>> place to start:
>>>
>>> I have a |person| table and a |team| table with a many to many table in
>>> between |team_person|.
>>> Simple enough!
>>>
>>> Now - to make it fun.
>>> |team| has a relationship to |tournament|
>>> How can I prevent a user from joining more than 1 team in a given
>>> tournament?
>>>
>>> I thought about adding a 3rd column to my M2M table,
>>> (team_tournament_person), but that could still fail because it could be a
>>> team from tournament x, tournament y's ID and a Person Q's ID.
>>>
>>> So any suggestions on what I should be googling, and then how to
>>> implement in SA would be hugely appreciated!
>>>
>>> Thanks!
>>>
>> --
>> 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/sqlalchemy/d93a10e6-cae8-4346-bae4-99782546becf%40googlegroups.com
>> 
>> .
>>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/CAHmCLHrPTG63dYfxnPvR2Ej3jQ8zF9q6w-7hzP1w%3DQ3qfA-T4Q%40mail.gmail.com.


Re: [sqlalchemy] Track a "column FOO does not exist" bug.

2019-09-05 Thread Mike Bayer


On Thu, Sep 5, 2019, at 7:50 AM, Riccardo Cagnasso wrote:
> I have a table Activity that had a strategic_project_name column.
> I removed the strategic_project_name column from the declarative definition 
> of the Activity table and then the strategic_project_name column from the 
> database itself.
> 
> Now I get this error message every time I try to update the one Activity 
> record.
> 
> File 
> "/home/phas/virtualenvs/o35/lib/python3.5/site-packages/SQLAlchemy-1.3.8-py3.5-linux-x86_64.egg/sqlalchemy/engine/default.py",
>  line 552, in do_execute
>  cursor.execute(statement, parameters)
> sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedColumn) column 
> "strategic_project_name" does not exist
> 
> [SQL: UPDATE activity SET subtitle=%(subtitle)s WHERE activity.id = 
> %(activity_id)s]
> [parameters: {'activity_id': 200, 'subtitle': 'gjh'}]
> 
> which is very odd because the SQL doesn't contain the column 
> strategic_project_name
> 
> If I manually create a strategic_project_name column in the database activity 
> table, it starts to work again, so it's not referring to some different 
> table.``
> 
> I can't track why does sqlalchemy think that Activity would still have a 
> "strategic_project_name" column. I removed all the occurrencies of the word 
> "strategic_project_name" from my whole project, but I'm still getting this 
> error.
> 
> Do you have any advice on how to track this in the internals of sqlalchemy?

the internals of SQLAlchemy don't have this string name either. your best bet 
would be to turn on logging in the Postgresql server and see what it's seeing 
directly

https://www.postgresql.org/docs/9.0/runtime-config-logging.html




> 

> --
>  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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/729b8817-a4e5-45ef-b31d-17772ab9016b%40googlegroups.com
>  
> .

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/2e1a3e39-de7d-4e03-a8a2-a15169c0d899%40www.fastmail.com.


[sqlalchemy] Re: Track a "column FOO does not exist" bug.

2019-09-05 Thread Riccardo Cagnasso
I don't think so. Wouldn't postgres prevented me deleting the column if it 
were? 

Il giorno giovedì 5 settembre 2019 14:42:26 UTC+2, Steven James ha scritto:

> Do you have a trigger or a constraint that references that column?

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/afc7495f-da55-468a-ba2d-94092aad041e%40googlegroups.com.


[sqlalchemy] Track a "column FOO does not exist" bug.

2019-09-05 Thread Steven James
Do you have a trigger or a constraint that references that column?

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/ae2db410-910e-4ae1-96ea-6255b2fb5c73%40googlegroups.com.


[sqlalchemy] Track a "column FOO does not exist" bug.

2019-09-05 Thread Riccardo Cagnasso
I have a table Activity that had a strategic_project_name column.
I removed the strategic_project_name column from the declarative definition 
of the Activity table and then the strategic_project_name column from the 
database itself.

Now I get this error message every time I try to update the one Activity 
record.

  File 
"/home/phas/virtualenvs/o35/lib/python3.5/site-packages/SQLAlchemy-1.3.8-py3.5-linux-x86_64.egg/sqlalchemy/engine/default.py"
, line 552, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedColumn) column 
"strategic_project_name" does not exist

[SQL: UPDATE activity SET subtitle=%(subtitle)s WHERE activity.id = %(
activity_id)s]
[parameters: {'activity_id': 200, 'subtitle': 'gjh'}]

which is very odd because the SQL doesn't contain the column 
strategic_project_name

If I manually create a strategic_project_name column in the database 
activity table, it starts to work again, so it's not referring to some 
different table.

I can't track why does sqlalchemy think that Activity would still have a 
"strategic_project_name" column. I removed all the occurrencies of the word 
"strategic_project_name" from my whole project, but I'm still getting this 
error.

Do you have any advice on how to track this in the internals of sqlalchemy?

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/729b8817-a4e5-45ef-b31d-17772ab9016b%40googlegroups.com.


Re: [sqlalchemy] Distinct within group by query

2019-09-05 Thread Andrew M
Yes, I'm using Postgres.

This does exactly what I need:

session.query(Product.attribute_x, func.min(Product.price), 
func.array_agg(func.distinct(Product.color))).group_by(Product.attribute_x)

Thanks Varun, that's saved me a real headache. I appreciate your help.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/116757f4-6b07-4c48-96da-35dd938d8049%40googlegroups.com.