[Bucardo-general] customselect for trasforming column names for table synced from PostgreSQL to Mongo

Greg Sabino Mullane greg at endpoint.com
Mon May 7 17:17:13 UTC 2012


On Sun, May 06, 2012 at 07:04:31PM +0100, Ali Asad Lotia wrote:
> Hi All,
> I will be syncing a table between PostgreSQL and MongoDB and want to
> map the PostgreSQL column names in certain tables to other key names
> in Mongo documents. Is this doable using a custom select where the
> select does something like:
> SELECT foo as bar
> Assuming this works, I would expect the MongoDB document to contain a
> key bar with the value of the orginal column foo.

Correct.

> If this is possible, I would much appreciate pointers to documentation
> on how to write custom selects and the steps required to get them
> loaded into a bucardo set up.

The test file t/20-postgres.t has a working example: grep for 'customcols'

The basic idea is to replace the default 'SELECT * FROM table' with a modified 
select list, by calling:

$ bucardo add customcols mytable "SELECT a,b, foo AS bar"

You can optionally constrain to a certain sync:

$ bucardo add customcols mytable "SELECT a,b, foo AS bar" sync=mysync

And/or to a certain database (which is probably what you want to do here):

$ bucardo add customcols mytable "SELECT a,b, foo AS bar" db=mymongodb

Docs are definitely lacking here. At the very least, I should get a 
blog post out explaining it in more detail.

-- 
Greg Sabino Mullane greg at endpoint.com
End Point Corporation
PGP Key: 0x14964AC8
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 163 bytes
Desc: not available
URL: <https://mail.endcrypt.com/pipermail/bucardo-general/attachments/20120507/cfc7484d/attachment.sig>


More information about the Bucardo-general mailing list