Hi Toby,

A Thursday 16 April 2009, Toby Mathieson escrigué:
> Hi all,
> I think I am still thinking in terms of relational databases and
> MySQL... but now I would like to add a column to an existing  HDF5
> table... I tried something like the following:
>
> h5file.setNodeAttr(group,'cancelled',Int32Col(),name='Pdata')
>
> where 'group' is a groupNode of the table I want to alter and 'Pdata'
> is the corresponding table to which I would like to add the attribute
> (column name ) 'cancelled' and with the type Int32....
>
> This doesn't throw an error, but doesn't work either.
>
> I also tried:
>
> h5file.setNodeAttr(pnode,'cancelled',Int32Col()
> where pnode is the actual node (table) I am trying to alter... but
> that had no effect either
>
> I was pretty sure this wasn't the correct method to use here, but
> failed to find anything else!
>

What you are doing here is to set an *attribute* to the table, not a 
column.  Look at this:

In [14]: f.setNodeAttr(pnode,'cancelled',tables.Int32Col())

In [15]: pnode.attrs.cancelled
Out[15]: Int32Col(shape=(), dflt=0, pos=None)

So, definitely you don't want to follow this path.

> Which is the best way to do this?  I have tried looking through the
> tutorial / help, but have obviously not used the correct search
> terms.

Dragan already showed you a possibility if you really want to add a 
column to your existing table.  However, a much faster option is to 
create an EArray containing the info that you want to put in the table.  
Then, in order to do queries that includes the values of the new table, 
you can add use the 'nrow' attribute in table to reference the 
additional EArray column.  Something like:

[(r['field0'], earr[r.nrow]) for r in tbl.where('field0 == "1"')]

Of course, if you follow the above approach you should be responsible of 
keep in sync the rows in the table and the earray.  Depending on your 
needs, you may want to follow Dragan's path or this one.

Hope that helps,

-- 
Francesc Alted

"One would expect people to feel threatened by the 'giant
brains or machines that think'.  In fact, the frightening
computer becomes less frightening if it is used only to
simulate a familiar noncomputer."

-- Edsger W. Dykstra
   "On the cruelty of really teaching computer science"

------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
Pytables-users mailing list
Pytables-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pytables-users

Reply via email to