Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get the partition table name for a specific partition value. #37

Open
dvfabbri opened this issue May 9, 2017 · 3 comments
Open

Get the partition table name for a specific partition value. #37

dvfabbri opened this issue May 9, 2017 · 3 comments

Comments

@dvfabbri
Copy link

dvfabbri commented May 9, 2017

I want to bulk insert rows into a specific partition which all have the same date. Assume that data are partitioned by month on date_column. Does the architect API allow for:

p = get_partition(column_name='date_column', value='2015-01-01')

then run: "copy from '/my/file.txt' to %s" % p.table_name

Perhaps I am unclear on how to use the get_partition API. Can you provide an example?

@maxtepkeev
Copy link
Owner

maxtepkeev commented May 12, 2017

Unfortunately there is no API to get the partition name right now, neither in PostgreSQL nor in MySQL. In MySQL it's fairly easy to implement using existing code, but for PostgreSQL the partition name is constructed dynamically inside the trigger so we have to think about how to implement it properly in Architect, because your use case is perfectly valid and we need to add this API in one of the future versions.

The only thing that I can recommend you to do right now is to hardcode the partition name in your code if it's the one time operation, or if you plan to do this on a regular basis you can have a look at the generated partition names to get idea of the naming scheme and to implement a small function in Python somewhere in your code which will accept a date and return a generated partition name from it.

@dvfabbri
Copy link
Author

Thanks. Can I create a new partition through the API or do I need to insert one row into the master table?

@maxtepkeev
Copy link
Owner

In MySQL you should have both options, in Postgres you need to insert one row into the table for partition to be created, because everything is managed through the triggers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants