Re: [sqlalchemy] selecting null

2014-08-20 Thread Michael Bayer

On Aug 20, 2014, at 7:16 PM, Dave Vitek  wrote:

> Hi all,
> 
> I recently upgraded from 0.7.10 to 0.9.7.  I'm seeing what looks like a 
> regression:
> 
> (Pdb) p str(select([null(), null()]))
> 'SELECT NULL AS anon_1'
> 
> After the upgrade, sqlalchemy seems to coalesce multiple adjacent nulls into 
> a single one.  I can work around the problem by doing this instead:
> 
> (Pdb) p str(select([literal_column('NULL'), literal_column('NULL')]))
> 'SELECT NULL, NULL'
> 
> Is there a better way of doing this?  Is this a bug?
> 
> I'm doing this to feed an INSERT statement as in insert().from_select(...).


select()'s generally like for expressions to be named, so at the very least, 
give these a label, e.g. select([null().label('n1'), null().label('n2')]).

as far as why it's doing that, sure its probably a bug

-- 
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 http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] selecting null

2014-08-20 Thread Dave Vitek

Hi all,

I recently upgraded from 0.7.10 to 0.9.7.  I'm seeing what looks like a 
regression:


(Pdb) p str(select([null(), null()]))
'SELECT NULL AS anon_1'

After the upgrade, sqlalchemy seems to coalesce multiple adjacent nulls 
into a single one.  I can work around the problem by doing this instead:


(Pdb) p str(select([literal_column('NULL'), literal_column('NULL')]))
'SELECT NULL, NULL'

Is there a better way of doing this?  Is this a bug?

I'm doing this to feed an INSERT statement as in insert().from_select(...).

- Dave

--
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 http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] Re: How can I make a rollback in a sequence?

2014-08-20 Thread Rafael Henrique da Silva Correia
I did not know that  thanks!

For future reference: 
http://www.postgresql.org/docs/9.1/static/functions-sequence.html



Em quarta-feira, 20 de agosto de 2014 15h02min55s UTC-3, Rafael Henrique da 
Silva Correia escreveu:
>
> Hi !
>
> I have a block of code similar to this I made to test:
>
> def TEST():
>> teste = Test(descricao=str('wololo'))
>>
>> try:
>> db.session.add(wololo)
>> db.session.commit()
>> db.session.close()
>> except IntegrityError, e:
>> db.session.rollback()
>> db.session.close()
>> print e.message
>>
>> sql = db.session.execute('select * from public.test_id_seq;')
>> result = sql.fetchall()
>> print "Sequence select:"
>> print result[0][0]
>> print result[0][1]
>>
>> TEST()
>>
>
> My model is:
>
> class Test(db.Model):
>>   id = db.Column(db.BigInteger, db.Sequence('test_id_seq', 
>> metadata=db.metadata), primary_key = True)
>>   description = db.Column(db.String(50), unique=True, nullable=False)
>>   def __init__(self, description):
>> self.description = description
>>
>
> I dont receive any error BUUUTT my sequence increases even in a case 
> except. My database is PostgreeSQL 9.3.5 and configuration is:
>
> SQLALCHEMY_DATABASE_URI = 'postgresql://' + database_username + ':' + \
>>  database_password + "@" + database_address +":" + database_port + "/" + \
>>  database_name
>
>
> I created the base of my project following the official documentation 
> Flask Flask-SQLAlchemy on http://flask.pocoo.org/docs/patterns/sqlalchemy/
>
> I read many many many examples on google, but none helped me ... already 
> tried many things ... can anyone help me? 
>
> Thank you!
>
>

-- 
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 http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] How can I make a rollback in a sequence?

2014-08-20 Thread Wichert Akkerman

> On 20 Aug 2014, at 20:02, Rafael Henrique da Silva Correia 
>  wrote:
> 
> Hi !
> 
> I have a block of code similar to this I made to test:
> 
> def TEST():
> teste = Test(descricao=str('wololo'))
> 
> try:
> db.session.add(wololo)
> db.session.commit()
> db.session.close()
> except IntegrityError, e:
> db.session.rollback()
> db.session.close()
> print e.message
> 
> [..]
> I dont receive any error BUUUTT my sequence increases even in a case except


That’s just how PostgreSQL works. From the PostgreSQL documentation:

Important: To avoid blocking concurrent transactions that obtain numbers from 
the same sequence, a nextval operation is never rolled back; that is, once a 
value has been fetched it is considered used, even if the transaction that did 
the nextval later aborts. This means that aborted transactions might leave 
unused "holes" in the sequence of assigned values.

Wichert.

-- 
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 http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] How can I make a rollback in a sequence?

2014-08-20 Thread Rafael Henrique da Silva Correia
Hi !

I have a block of code similar to this I made to test:

def TEST():
> teste = Test(descricao=str('wololo'))
>
> try:
> db.session.add(wololo)
> db.session.commit()
> db.session.close()
> except IntegrityError, e:
> db.session.rollback()
> db.session.close()
> print e.message
>
> sql = db.session.execute('select * from public.test_id_seq;')
> result = sql.fetchall()
> print "Sequence select:"
> print result[0][0]
> print result[0][1]
>
> TEST()
>

My model is:

class Test(db.Model):
>   id = db.Column(db.BigInteger, db.Sequence('test_id_seq', 
> metadata=db.metadata), primary_key = True)
>   description = db.Column(db.String(50), unique=True, nullable=False)
>   def __init__(self, description):
> self.description = description
>

I dont receive any error BUUUTT my sequence increases even in a case 
except. My database is PostgreeSQL 9.3.5 and configuration is:

SQLALCHEMY_DATABASE_URI = 'postgresql://' + database_username + ':' + \
>  database_password + "@" + database_address +":" + database_port + "/" + \
>  database_name


I created the base of my project following the official documentation Flask 
Flask-SQLAlchemy on http://flask.pocoo.org/docs/patterns/sqlalchemy/

I read many many many examples on google, but none helped me ... already 
tried many things ... can anyone help me? 

Thank you!

-- 
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 http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.