Re: [sqlalchemy] Modifying Query Object

2023-04-14 Thread Mike Bayer
On Tue, Apr 11, 2023, at 9:17 PM, Luis Del Rio IV wrote: > The sql query itself returns several rows, as it should. But when trying to > combine the max using sqlalchemy the rows return as the following. > > Received incompatible instance \"( 0x7f2c6cfd6670>, '2021-04-10 18',

Re: [sqlalchemy] Modifying Query Object

2023-04-14 Thread Peter Harrison
I have some additional context on the issue Luis mentioned. 1. We are using the graphene-sqlalchemy package. 2. When you do a GraphQL web api query, the package creates a sqlalchemy.orm.query.Query object. 3. We want to modify this standard query that the package creates so that

Re: [sqlalchemy] Modifying Query Object

2023-04-14 Thread Peter Harrison
I have some additional context on the issue Luis mentioned. 1. We are using the graphene-sqlalchemy package. 2. When you do a GraphQL web api query, the package creates a sqlalchemy.orm.query.Query object. 3. We want to modify this standard query that the package creates so that we

Re: [sqlalchemy] Modifying Query Object

2023-04-14 Thread Luis Del Rio IV
The sql query itself returns several rows, as it should. But when trying to combine the max using sqlalchemy the rows return as the following. Received incompatible instance \"(, '2021-04-10 18', Decimal('7294.0'))\".", Here I am able to get the max for that row group, but am unable to pass

Re: [sqlalchemy] Modifying Query Object

2023-04-14 Thread Luis Del Rio IV
The sql query itself returns several rows, as it should. But when trying to combine the max using sqlalchemy the rows return as the following. Received incompatible instance "(server.db.models.Data object at , '2021-04-10 18', Decimal('7294.0'))".", Here I am able to get the max for that

Re: [sqlalchemy] Modifying Query Object

2023-04-14 Thread Luis Del Rio IV
The sql query itself returns several rows, as it should. But when trying to combine the max using sqlalchemy the rows return as the following. Received incompatible instance \"(, '2021-04-10 18', Decimal('7294.0'))\".", Here I am able to get the max for that row group, but am unable to

Re: [sqlalchemy] Modifying Query Object

2023-04-14 Thread Peter Harrison
I have some additional context on the issue Luis mentioned. 1. We are using the graphene-sqlalchemy package. 2. When you do a GraphQL web api query, the package creates a sqlalchemy.orm.query.Query object. 3. We want to modify this standard query that the package creates so that we

Re: [sqlalchemy] Modifying Query Object

2023-04-14 Thread Luis Del Rio IV
The sql query itself returns several rows, as it should. But when trying to combine the max using sqlalchemy the rows return as the following. Received incompatible instance \"(, '2021-04-10 18', Decimal('7294.0'))\".", Here I am able to get the max for that row group, but am unable to

Re: [sqlalchemy] Re: Dealing with readonly column

2023-04-14 Thread Mike Bayer
On Fri, Apr 14, 2023, at 3:02 PM, Lele Gaifax wrote: > "Mike Bayer" writes: > >> On Fri, Apr 14, 2023, at 8:03 AM, Lele Gaifax wrote: >>> I now have >>> >>> CREATE TABLE something (id SERIAL, name TEXT) >>> >>> CREATE FUNCTION counter(something) >>> RETURNS INTEGER AS $$ >>> SELECT

Re: [sqlalchemy] Using joins+max with sql server

2023-04-14 Thread Mike Bayer
this line of code: query = session.query(CodigoProduto.CdChamada, Produto.IdProduto, Produto.NmProduto, ProdutoEmpresa.VlPrecoCusto, ProdutoEmpresa.VlPrecoSugerido, EstoqueEmpresa.DtReferencia, EstoqueEmpresa.QtEstoque) should look like this: query =

Re: [sqlalchemy] Using joins+max with sql server

2023-04-14 Thread Elias Coutinho
*I am suffering!It showed the same message.* # Subquery para buscar o maior registro de estoqueempresa para cada produto estoqueAtual = session.query( EstoqueEmpresa.IdProduto, EstoqueEmpresa.QtEstoque, func.max(EstoqueEmpresa.DtReferencia).label('MaxDtReferencia')

[sqlalchemy] Re: Dealing with readonly column

2023-04-14 Thread Lele Gaifax
"Mike Bayer" writes: > On Fri, Apr 14, 2023, at 8:03 AM, Lele Gaifax wrote: >> I now have >> >> CREATE TABLE something (id SERIAL, name TEXT) >> >> CREATE FUNCTION counter(something) >> RETURNS INTEGER AS $$ >> SELECT count(*) FROM something_else se >> WHERE se.something_id = $1.id

Re: [sqlalchemy] Using joins+max with sql server

2023-04-14 Thread Mike Bayer
the initial issue is that you want DtReferencia from the subquery on the outside: session.query(..., estoqueAtual.c.DtReferencia, ...) and not "EstoqueEmpresa.DtReferencia", that's not available in the FROM list, it's inside a subquery. also I dont think you'd want to "group by" the same

[sqlalchemy] Using joins+max with sql server

2023-04-14 Thread Elias Coutinho
Good afternoon. I am having trouble transforming a SQL Server query to SQL Alchemy. *The SQL Server query is this* SELECT CP.CdChamada, P.NmProduto, PE.VlPrecoCusto, PE.VlPrecoSugerido, EE.QtEstoque, EE.DtReferencia FROM Produto P INNER JOIN Produto_Empresa PE ON P.IdProduto = PE.IdProduto

Re: [sqlalchemy] Dealing with readonly column

2023-04-14 Thread Mike Bayer
On Fri, Apr 14, 2023, at 8:03 AM, Lele Gaifax wrote: > Hi, > > I wonder if there is a way to declare a particular column of a table as > "readonly", either for the purpose of documenting the model, or to get > early error should someone try to update it. "readonly" can mean a few different

[sqlalchemy] Dealing with readonly column

2023-04-14 Thread Lele Gaifax
Hi, I wonder if there is a way to declare a particular column of a table as "readonly", either for the purpose of documenting the model, or to get early error should someone try to update it. Some context: I have to maintain an old application, based on PostgreSQL, with several surrounding tools