Hi *,

let's say I got a table on a postgresql database (<=9.3) with native
json support made like that:

db.define_table('sitelog',
    Field('log', 'json'),
    auth.signature.created_on,
    auth.signature.modified_on
)

introducing some records and knowing for example that the field "uuid"
is always present in all json fields of the introduced records I can
performe a query like this:

row = db(db.sitelog.id>0).select("log->'uuid' as uuid",
db.sitelog.created_on.with_alias("Creation_date")).first()
obtaining:

<Row {'_extra': {'sitelog.created_on AS Creation_date':
datetime.datetime(2015, 2, 26, 23, 18, 1), "log->'uuid' as uuid":
'Arenaccio'}, 'Creation_date': datetime.datetime(2015, 2, 26, 23, 18, 1)}>

now if I perform:

In [19]: row.Creation_date

I got a result

Out[19]: datetime.datetime(2015, 2, 26, 23, 18, 1)

it's not the same with

In [20]: row.uuid

that raises the subsequent exception

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/home/manuele/dev/portali/web2py.trunk/applications/consorzio4/models/site.py
in <module>()
----> 1 row.uuid

/home/manuele/dev/portali/web2py.trunk/gluon/dal/objects.pyc in
__getitem__(self, k)
     79                 return self[key]
     80             except:
---> 81                 raise ae
     82
     83     __setitem__ = lambda self, key, value: setattr(self,
str(key), value)

AttributeError: 'Row' object has no attribute 'uuid'

is there a way to pass the first string (i.e. "log->'uuid' as uuid") as
an Expression class instance in order to do:

In [20]: row.uuid

obtaining the wanted result?

Thankyou very mutch

    M.




-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to