Re: [sqlalchemy] on_conflict_do_update (ON CONFLICT ... Postgresql 9.5) WHERE clause problem

2016-09-29 Thread Mike Bayer


I just pushed that and it should close the bitbucket issue.


On 09/29/2016 03:07 AM, pszynk wrote:

I see you already looked into it. Thanks!

W dniu środa, 28 września 2016 20:55:05 UTC+2 użytkownik Mike Bayer napisał:

this is likely use cases that have been untested, if you can file this
w/ a complete test case as a bug report on bitbucket we can start
looking into it.


On 09/28/2016 12:05 PM, Paweł Szynkiewicz wrote:
> Hello all
>
> SA: 1.1.0b3
> db: postgresql 9.5
>
> I have a problem with method on_conflict_do_update for pg specific
insert.
> Precisely with the where argument. It looks like wrong SQL
statement is
> generated.
>
> example:
>
> class Foo(Base):
>   ...
>   bar = Column(Integer)
>
> insert_stmt = insert(Foo)
>
> on_update_stmt = insert_stmt.on_conflict_do_update(
> set_=dict(
> bar=insert_stmt.excluded.bar,
> ),
> where=(Foo.bar < insert_stmt.excluded.bar)
> )
>
> session.execute(on_update_stmt, data)
>
> it gives error and rightly so:
>> column reference "bar" is ambiguous
>
> SQL looks like that:
>
> SQL: 'INSERT INTO foo (...) VALUES (...) ON CONFLICT (...) DO
UPDATE SET
> bar = excluded.bar WHERE bar < bar'
>
> WHERE clause is not expanded properly, the alias EXCLUDED is
omitted. Is
> this a bug or I'm doing sht wrong?
>
> the workaround I use is:
>
> ...
> where=(text('foo.bar < EXCLUDED.bar'))
> ...
>
> Cheers
>
>
>
> --
> 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+...@googlegroups.com 
> .
> To post to this group, send email to sqlal...@googlegroups.com

> .
> Visit this group at https://groups.google.com/group/sqlalchemy
.
> For more options, visit https://groups.google.com/d/optout
.

--
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.


--
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.


Re: [sqlalchemy] on_conflict_do_update (ON CONFLICT ... Postgresql 9.5) WHERE clause problem

2016-09-29 Thread pszynk
I see you already looked into it. Thanks!

W dniu środa, 28 września 2016 20:55:05 UTC+2 użytkownik Mike Bayer napisał:
>
> this is likely use cases that have been untested, if you can file this 
> w/ a complete test case as a bug report on bitbucket we can start 
> looking into it. 
>
>
> On 09/28/2016 12:05 PM, Paweł Szynkiewicz wrote: 
> > Hello all 
> > 
> > SA: 1.1.0b3 
> > db: postgresql 9.5 
> > 
> > I have a problem with method on_conflict_do_update for pg specific 
> insert. 
> > Precisely with the where argument. It looks like wrong SQL statement is 
> > generated. 
> > 
> > example: 
> > 
> > class Foo(Base): 
> >   ... 
> >   bar = Column(Integer) 
> > 
> > insert_stmt = insert(Foo) 
> > 
> > on_update_stmt = insert_stmt.on_conflict_do_update( 
> > set_=dict( 
> > bar=insert_stmt.excluded.bar, 
> > ), 
> > where=(Foo.bar < insert_stmt.excluded.bar) 
> > ) 
> > 
> > session.execute(on_update_stmt, data) 
> > 
> > it gives error and rightly so: 
> >> column reference "bar" is ambiguous 
> > 
> > SQL looks like that: 
> > 
> > SQL: 'INSERT INTO foo (...) VALUES (...) ON CONFLICT (...) DO UPDATE SET 
> > bar = excluded.bar WHERE bar < bar' 
> > 
> > WHERE clause is not expanded properly, the alias EXCLUDED is omitted. Is 
> > this a bug or I'm doing sht wrong? 
> > 
> > the workaround I use is: 
> > 
> > ... 
> > where=(text('foo.bar < EXCLUDED.bar')) 
> > ... 
> > 
> > Cheers 
> > 
> > 
> > 
> > -- 
> > 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+...@googlegroups.com  
> > . 
> > To post to this group, send email to sqlal...@googlegroups.com 
>  
> > . 
> > Visit this group at https://groups.google.com/group/sqlalchemy. 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
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.


Re: [sqlalchemy] on_conflict_do_update (ON CONFLICT ... Postgresql 9.5) WHERE clause problem

2016-09-28 Thread Mike Bayer
this is likely use cases that have been untested, if you can file this 
w/ a complete test case as a bug report on bitbucket we can start 
looking into it.



On 09/28/2016 12:05 PM, Paweł Szynkiewicz wrote:

Hello all

SA: 1.1.0b3
db: postgresql 9.5

I have a problem with method on_conflict_do_update for pg specific insert.
Precisely with the where argument. It looks like wrong SQL statement is
generated.

example:

class Foo(Base):
  ...
  bar = Column(Integer)

insert_stmt = insert(Foo)

on_update_stmt = insert_stmt.on_conflict_do_update(
set_=dict(
bar=insert_stmt.excluded.bar,
),
where=(Foo.bar < insert_stmt.excluded.bar)
)

session.execute(on_update_stmt, data)

it gives error and rightly so:

column reference "bar" is ambiguous


SQL looks like that:

SQL: 'INSERT INTO foo (...) VALUES (...) ON CONFLICT (...) DO UPDATE SET
bar = excluded.bar WHERE bar < bar'

WHERE clause is not expanded properly, the alias EXCLUDED is omitted. Is
this a bug or I'm doing sht wrong?

the workaround I use is:

...
where=(text('foo.bar < EXCLUDED.bar'))
...

Cheers



--
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.


--
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] on_conflict_do_update (ON CONFLICT ... Postgresql 9.5) WHERE clause problem

2016-09-28 Thread Paweł Szynkiewicz
Hello all

SA: 1.1.0b3
db: postgresql 9.5

I have a problem with method on_conflict_do_update for pg specific insert.
Precisely with the where argument. It looks like wrong SQL statement is 
generated.

example:

class Foo(Base):
  ...
  bar = Column(Integer)

insert_stmt = insert(Foo)

on_update_stmt = insert_stmt.on_conflict_do_update(
set_=dict(
bar=insert_stmt.excluded.bar,
),
where=(Foo.bar < insert_stmt.excluded.bar)
)

session.execute(on_update_stmt, data)

it gives error and rightly so:
> column reference "bar" is ambiguous

SQL looks like that:

SQL: 'INSERT INTO foo (...) VALUES (...) ON CONFLICT (...) DO UPDATE SET 
bar = excluded.bar WHERE bar < bar'

WHERE clause is not expanded properly, the alias EXCLUDED is omitted. Is 
this a bug or I'm doing sht wrong?

the workaround I use is:

...
where=(text('foo.bar < EXCLUDED.bar'))
...

Cheers



-- 
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.