[web2py] Re: alias field names

2015-10-03 Thread 黄祥
perhaps you can use dal alias
ref:
http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Self-Reference-and-aliases

best regards,
stifan

On Saturday, October 3, 2015 at 3:03:45 PM UTC+7, Nguyen Minh Tuan wrote:
>
> Hi all,
>
> My situation is that I have to work with already defined tables.
> There is a field name 'pass', this is keyword of Python, I don't how to 
> solve this.
> So I think alias for table field is necessary.
>
> Anyone can suggest for this situation?
> Thanks in advance!
>
> Regards,
> Tuan.
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: alias field names

2015-10-03 Thread Nguyen Minh Tuan
Hi all,

My situation is that I have to work with already defined tables.
There is a field name 'pass', this is keyword of Python, I don't how to 
solve this.
So I think alias for table field is necessary.

Anyone can suggest for this situation?
Thanks in advance!

Regards,
Tuan.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Re: alias field names

2011-05-25 Thread howesc
i don't see the reason for this.  true, from GAE's docs 
(http://code.google.com/appengine/articles/storage_breakdown.html):

Because App Engine's datastore is essentially schemaless, every entity of a 
particular kind must store the name of each property in addition to the 
value, even if every other entity of that kind uses the same set of 
properties. While this redundancy does result in a slight storage overhead, 
it also offers more flexibility for model definitions (see Effective 
PolyModel http://code.google.com/appengine/articles/polymodel.html for an 
example).

i understand saving space on limited hardware, and yes with millions of rows 
you might have a GB of storage for those names, so that might cost you $0.15 
a month, but i believe that cluttering your code with extra things like 
aliases, and making a database that can't be used without the code (no one 
would be able to understand the data if viewed in the GAE console), i'd pay 
the $0.15 a month.

just my $0.03. ;)

cfh


Re: [web2py] Re: alias field names

2011-05-25 Thread Richard Baron Penman
Currently the datastore is at 1.3GB and costs next to nothing, so normally I
wouldn't care. But this project is for a client who doesn't want to enable
billing so I am trying every optimization I can find.


On Thu, May 26, 2011 at 7:16 AM, howesc how...@umich.edu wrote:

 i don't see the reason for this.  true, from GAE's docs (
 http://code.google.com/appengine/articles/storage_breakdown.html):

 Because App Engine's datastore is essentially schemaless, every entity of
 a particular kind must store the name of each property in addition to the
 value, even if every other entity of that kind uses the same set of
 properties. While this redundancy does result in a slight storage overhead,
 it also offers more flexibility for model definitions (see Effective
 PolyModel http://code.google.com/appengine/articles/polymodel.html for
 an example).

 i understand saving space on limited hardware, and yes with millions of
 rows you might have a GB of storage for those names, so that might cost you
 $0.15 a month, but i believe that cluttering your code with extra things
 like aliases, and making a database that can't be used without the code (no
 one would be able to understand the data if viewed in the GAE console), i'd
 pay the $0.15 a month.

 just my $0.03. ;)

 cfh



[web2py] Re: alias field names

2011-05-24 Thread Massimo Di Pierro
How about

my_descriptive_field_name = db.a

On May 24, 9:06 am, Plumo richar...@gmail.com wrote:
 the database I use (GAE) has a big overhead for long field names.
 So I want to change Field('my_descriptive_field_name') to Field('a') and use
 an alias to keep accessing with 'my_descriptive_field_name'.
 Can this be done?


Re: [web2py] Re: alias field names

2011-05-24 Thread Richard Baron Penman
would this work?
db.table_name.my_descriptive_field_name = db.table_name.a

I would rather avoid extra global variables and changing my database
queries.


On Wed, May 25, 2011 at 12:21 AM, Massimo Di Pierro 
massimo.dipie...@gmail.com wrote:

 How about

 my_descriptive_field_name = db.a

 On May 24, 9:06 am, Plumo richar...@gmail.com wrote:
  the database I use (GAE) has a big overhead for long field names.
  So I want to change Field('my_descriptive_field_name') to Field('a') and
 use
  an alias to keep accessing with 'my_descriptive_field_name'.
  Can this be done?



Re: [web2py] Re: alias field names

2011-05-24 Thread Vinicius Assef
I think he is talking about this, if it would be SQL:
SELECT my_descriptive_name as a FROM my_table

In web2py, something near:
Field('my_descriptive_field_name', 'string', alias='a')

And, in code:
print db.my_table.a

--
Vinicius Assef.



On Tue, May 24, 2011 at 11:21 AM, Massimo Di Pierro
massimo.dipie...@gmail.com wrote:
 How about

 my_descriptive_field_name = db.a

 On May 24, 9:06 am, Plumo richar...@gmail.com wrote:
 the database I use (GAE) has a big overhead for long field names.
 So I want to change Field('my_descriptive_field_name') to Field('a') and use
 an alias to keep accessing with 'my_descriptive_field_name'.
 Can this be done?


Re: [web2py] Re: alias field names

2011-05-24 Thread Richard Baron Penman
For space reasons I want the database to internally store 'a', but be able
to use the longer name in code for readability.

So I think your example should instead be:
Field('a', 'string', alias='my_descriptive_field_name')

But does that alias parameter exist? Not according to docs:
http://web2py.com/book/default/chapter/06#Record-Representation

http://web2py.com/book/default/chapter/06#Record-Representation

On Wed, May 25, 2011 at 1:18 AM, Vinicius Assef vinicius...@gmail.comwrote:

 I think he is talking about this, if it would be SQL:
 SELECT my_descriptive_name as a FROM my_table

 In web2py, something near:
 Field('my_descriptive_field_name', 'string', alias='a')

 And, in code:
 print db.my_table.a

 --
 Vinicius Assef.



 On Tue, May 24, 2011 at 11:21 AM, Massimo Di Pierro
 massimo.dipie...@gmail.com wrote:
  How about
 
  my_descriptive_field_name = db.a
 
  On May 24, 9:06 am, Plumo richar...@gmail.com wrote:
  the database I use (GAE) has a big overhead for long field names.
  So I want to change Field('my_descriptive_field_name') to Field('a') and
 use
  an alias to keep accessing with 'my_descriptive_field_name'.
  Can this be done?



Re: [web2py] Re: alias field names

2011-05-24 Thread Vinicius Assef
Richard,
I didn't understand your space reasons, but alias param does not exist today.

Massimo can tell us if it will be implemented.
IMHO it is a good idea, mainly for legacy tables, with legacy names.

--
Vinicius Assef.



On Tue, May 24, 2011 at 12:36 PM, Richard Baron Penman
richar...@gmail.com wrote:
 For space reasons I want the database to internally store 'a', but be able
 to use the longer name in code for readability.
 So I think your example should instead be:
 Field('a', 'string', alias='my_descriptive_field_name')
 But does that alias parameter exist? Not according to docs:
 http://web2py.com/book/default/chapter/06#Record-Representation


 On Wed, May 25, 2011 at 1:18 AM, Vinicius Assef vinicius...@gmail.com
 wrote:

 I think he is talking about this, if it would be SQL:
 SELECT my_descriptive_name as a FROM my_table

 In web2py, something near:
 Field('my_descriptive_field_name', 'string', alias='a')

 And, in code:
 print db.my_table.a

 --
 Vinicius Assef.



 On Tue, May 24, 2011 at 11:21 AM, Massimo Di Pierro
 massimo.dipie...@gmail.com wrote:
  How about
 
  my_descriptive_field_name = db.a
 
  On May 24, 9:06 am, Plumo richar...@gmail.com wrote:
  the database I use (GAE) has a big overhead for long field names.
  So I want to change Field('my_descriptive_field_name') to Field('a')
  and use
  an alias to keep accessing with 'my_descriptive_field_name'.
  Can this be done?




Re: [web2py] Re: alias field names

2011-05-24 Thread pbreit
Massimo's example gets you roughly the same result. Having a constant or an 
alias is pretty much the same.


Re: [web2py] Re: alias field names

2011-05-24 Thread Vinicius Assef
Right, pbreit.

But if it could be addressed by the DAL, it would demand less
programmer's effort and DRY would be an ally.

I vote for an alias param in Field(). Who is in?

Just a suggestion.

--
Vinicius Assef.


On Tue, May 24, 2011 at 1:13 PM, pbreit pbreitenb...@gmail.com wrote:
 Massimo's example gets you roughly the same result. Having a constant or an 
 alias is pretty much the same.


Re: [web2py] Re: alias field names

2011-05-24 Thread Richard Baron Penman
On Wed, May 25, 2011 at 1:50 AM, Vinicius Assef vinicius...@gmail.comwrote:

 I didn't understand your space reasons


see first post


Re: [web2py] Re: alias field names

2011-05-24 Thread Richard Baron Penman
On Wed, May 25, 2011 at 2:13 AM, pbreit pbreitenb...@gmail.com wrote:

 Massimo's example gets you roughly the same result.


so are you saying this would work too?

db.table_name.my_descriptive_field_name = db.table_name.a


 Having a constant or an alias is pretty much the same.


main drawback is additional global variables, which may accidentally be
overridden elsewhere


Re: [web2py] Re: alias field names

2011-05-24 Thread pbreit
An alias would be global too?

I don't think this would work:
db.table_name.my_descriptive_field_name = db.table_name.a

But these would:
db_table_name_my_descriptive_field_name = db.table_name.a

db_table_name = Storage()
db_table_name.my_descriptive_field_name = db.table_name.a


Re: [web2py] Re: alias field names

2011-05-24 Thread Anthony
On Tuesday, May 24, 2011 11:57:00 PM UTC-4, pbreit wrote: 

 An alias would be global too? 

 I don't think this would work:
 db.table_name.my_descriptive_field_name = db.table_name.a

 
As far as I can tell, the above does appear to work, at least for some 
purposes.
 
Anthony