Re: [sqlalchemy] Re: postgresql column default

2010-04-15 Thread Michael Brickenstein
Hi!
Thanks, that was very helpful for me.
Cheers,
Michael

Am 15.04.2010 um 18:17 schrieb Michael Bayer:
>> 
> 
> this column is against an alias, which suggests you've mapped to an alias() 
> or select() of some kind.   To get at full table metadata you need to be 
> talking to Column objects that are directly present on a Table.
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to sqlalch...@googlegroups.com.
> To unsubscribe from this group, send email to 
> sqlalchemy+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/sqlalchemy?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] Re: postgresql column default

2010-04-15 Thread Michael Bayer

On Apr 15, 2010, at 11:35 AM, Michael Brickenstein wrote:

> Hi!
> 
> Thanks for your very prompt
> answer.
> Unluckily, my mails were a little bit unprecise:
> 
> So, I wondered why the following happened:
> 
> prop = get_mapper(Participation).get_property('remark')
> 
> c=prop.columns[0] 
> 
> c
> Column(u'remark', PGText(length=None, convert_unicode=False, 
> assert_unicode=None), table=<%(188392684 participation)s>, nullable=False)

this column is against an alias, which suggests you've mapped to an alias() or 
select() of some kind.   To get at full table metadata you need to be talking 
to Column objects that are directly present on a Table.


-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] Re: postgresql column default

2010-04-15 Thread Michael Brickenstein
Hi!

Thanks for your very prompt
answer.
Unluckily, my mails were a little bit unprecise:

So, I wondered why the following happened:

prop = get_mapper(Participation).get_property('remark')

c=prop.columns[0] 

c
Column(u'remark', PGText(length=None, convert_unicode=False, 
assert_unicode=None), table=<%(188392684 participation)s>, nullable=False)

gives me a column

c.server_default

no server default

c2=iter(c.base_columns).next()

c2
Column(u'remark', PGText(length=None, convert_unicode=False, 
assert_unicode=None), table=, nullable=False, 
server_default=DefaultClause(, for_update=False))

c2.server_default
DefaultClause(, 
for_update=False)

Somehow in base_columns the server default is detected.
It is a little bit unclear to me, why the server_default is detected in c2, but 
not in c.

In fact I used the base_columns now as a workaround for RUM, but it feels quite 
hacky.

By the way, I simply *love* SA.
Moreover, I am very impressed, 
that (while of course unable to use them) my postgresql db contains partial 
indices.
That's a very good sign for the reflection code.

Cheers,
Michael

Am 15.04.2010 um 15:19 schrieb Michael Bayer:

> 
> On Apr 15, 2010, at 7:26 AM, Michael Brickenstein wrote:
> 
>> 
>> 
>> On 15 Apr., 13:03, Michael Brickenstein  wrote:
>>> Sorry, forgot to mention, I had the same behaviour with SA 0.5.6 and
>>> 0.5.8.
>>> Cheers,
>> 
 In former times, I used
 prop.server_default to find out, that there is an default of ''.
>> Sorry, that's wrong it has always been the columns[0], that I have to
>> inspect.
>> Nevertheless, the question for an official way remains, so far the
>> situation is the following:
>> c.server_default
>> -> None
>> 
>> c2=iter(c.base_columns).next()
>> -> DefaultClause(> 0xa2507ac>, for_update=False)
>> 
>> Is that a bug or a feature?
> 
> 
> server_default is where we put whatever server side defaults were detected 
> during reflection.   They reflect as a sqlalchemy.schema.DefaultClause, "arg" 
> is a TextClause representing what was received, and calling str() on that 
> gives you the ultimate value.The TextClause is so that we can 
> differentiate it from a literal python-defined value that would require 
> quoting.
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to sqlalch...@googlegroups.com.
> To unsubscribe from this group, send email to 
> sqlalchemy+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/sqlalchemy?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] Re: postgresql column default

2010-04-15 Thread Michael Bayer

On Apr 15, 2010, at 7:26 AM, Michael Brickenstein wrote:

> 
> 
> On 15 Apr., 13:03, Michael Brickenstein  wrote:
>> Sorry, forgot to mention, I had the same behaviour with SA 0.5.6 and
>> 0.5.8.
>> Cheers,
> 
>>> In former times, I used
>>> prop.server_default to find out, that there is an default of ''.
> Sorry, that's wrong it has always been the columns[0], that I have to
> inspect.
> Nevertheless, the question for an official way remains, so far the
> situation is the following:
> c.server_default
> -> None
> 
> c2=iter(c.base_columns).next()
> -> DefaultClause( 0xa2507ac>, for_update=False)
> 
> Is that a bug or a feature?


server_default is where we put whatever server side defaults were detected 
during reflection.   They reflect as a sqlalchemy.schema.DefaultClause, "arg" 
is a TextClause representing what was received, and calling str() on that gives 
you the ultimate value.The TextClause is so that we can differentiate it 
from a literal python-defined value that would require quoting.


-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: postgresql column default

2010-04-15 Thread Michael Brickenstein


On 15 Apr., 13:03, Michael Brickenstein  wrote:
> Sorry, forgot to mention, I had the same behaviour with SA 0.5.6 and
> 0.5.8.
> Cheers,

> > In former times, I used
> > prop.server_default to find out, that there is an default of ''.
Sorry, that's wrong it has always been the columns[0], that I have to
inspect.
Nevertheless, the question for an official way remains, so far the
situation is the following:
c.server_default
-> None

c2=iter(c.base_columns).next()
-> DefaultClause(, for_update=False)

Is that a bug or a feature?

Cheers,
Michael

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: postgresql column default

2010-04-15 Thread Michael Brickenstein
Sorry, forgot to mention, I had the same behaviour with SA 0.5.6 and
0.5.8.
Cheers,
Michael

On 15 Apr., 12:27, Michael Brickenstein  wrote:
> Hi!
>
> I have reflected my table from the db (Postgresql 8.4.2, tried psyco
> 2.0.12 and 2.0.14) using
>
> Table(name, metadata, autoload=True, autoload_with=engine)
>
> After that I map the table.
> When later in my app, I try to access the default values from the DB,
> I use
> the columnproperty:
>
> from owconf.model import Participation
> from rumalchemy.util import get_mapper
> prop = get_mapper(Participation).get_property('remark')
> prop
> 
>
> c=prop.columns[0]
> repr(c.default)
> repr(c.server_default)
>
> prop = get_mapper(Participation).get_property('number_of_companions')
>
> This is the reflection of a simple text field:
>
> remark                  | text    | not null default ''::text
>
> In former times, I used
> prop.server_default to find out, that there is an default of ''.
> This does not exist any more at that place, so I have inspected the
> property:
>
> c=prop.columns[0]
> repr(c.default)
> -> None
> repr(c.server_default)
> -> None
>
> The same occurs with integer fields like that:
>
>  number_of_companions    | integer | not null default 0
>
> Which is now the proper way to find out the right default for the
> column?
>
> The functionality is very useful for the RUM CRUD application.
>
> http://python-rum.org/
>
> Cheers,
> Michael

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.