Updating rows in LSD catalogs

9 views
Skip to first unread message

Branimir Sesar

unread,
Mar 22, 2012, 2:13:11 PM3/22/12
to lsd-...@googlegroups.com
Dear all,

I would like to update certain rows in my LSD database. Does anyone now
how this can be accomplished?

Cheers,

Brani

Mario Juric

unread,
Mar 22, 2012, 3:26:56 PM3/22/12
to lsd-...@googlegroups.com
On 3/22/12 11:13 , Branimir Sesar wrote:
> Dear all,
>
> I would like to update certain rows in my LSD database. Does anyone now
> how this can be accomplished?
>

That feature does exist, but is a bit cludgy, undocumented, and prone to
bitrot (it's not used frequently). Thou have been warned :).


That said, one way to do updates is using the INTO clause:

SELECT ... FROM ... INTO table_to_update WHERE dest_col==query_col

The other way is programmatically using table.append() with _update=True
keyword argument:

rows = ... create ndarray or ColGroup of rows to update, with IDs ...
tbl = db.table("table_to_update")
tbl.append(rows, _update=True)

I think Eddie as actually used one of these some point -- maybe he has
better examples?

Cheers,
--
Mario Juric,
Data Mgmt. Project Scientist, Large Synoptic Survey Telescope
Web : http://www.cfa.harvard.edu/~mjuric/
Phone : +1 617 744 9003 PGP: ~mjuric/crypto/public.key

Eddie Schlafly

unread,
Mar 22, 2012, 3:49:02 PM3/22/12
to lsd-...@googlegroups.com
> The other way is programmatically using table.append() with _update=True
> keyword argument:
>
>  rows = ... create ndarray or ColGroup of rows to update, with IDs ...
>  tbl = db.table("table_to_update")
>  tbl.append(rows, _update=True)
>
> I think Eddie as actually used one of these some point -- maybe he has
> better examples?

I use table.append(rows, _update=True) fairly frequently, though only
to set or clear a single bit. I think I'm happily breaking some good
practices using qresult_to_table to get the table I want to update,
though, but it was convenient and works.

--
def clear_mask(bounds=None):
query = db.query("select mjd_obs, mask, _id from uberobj")
with db.transaction():
out = query.execute([aux_clear_mask], group_by_static_cell=True)
for x in out:
pass

def aux_clear_mask(qresult):
res = colgroup.fromiter(qresult, blocks=True)
if res.nrows() != 0:
table = qresult_to_table(qresult)
res['mask'] = 0
table.append(res, _update=True)
yield 0

def qresult_to_table(qresult):
return (qresult.tables.values())[0].table
--

Thanks,

Eddie Schlafly

Reply all
Reply to author
Forward
0 new messages