core.db_to_pg
core.db_to_pg(
table_name,
schema,
*,
user=None,
host=None,
database=None,
port=None,
dst_user=None,
dst_host=None,
dst_database=None,
dst_port=None,
dst_schema=None,
col_types=None,
obs=None,
alt_table_name=None,
keep=None,
drop=None,
rename=None,
tz='UTC',
create_roles=True,
)
Write a PostgreSQL table to another PostgreSQL database.
Parameters
| table_name |
str |
Name of the source PostgreSQL table. |
required |
| schema |
str |
Name of the source PostgreSQL schema. |
required |
| user |
str |
Source PostgreSQL user role. |
None |
| host |
str |
Source PostgreSQL host name. |
None |
| database |
str |
Source PostgreSQL database name. |
None |
| port |
int |
Source PostgreSQL port. |
None |
| dst_user |
str |
Destination PostgreSQL user role. |
None |
| dst_host |
str |
Destination PostgreSQL host name. |
None |
| dst_database |
str |
Destination PostgreSQL database name. |
None |
| dst_port |
int |
Destination PostgreSQL port. |
None |
| dst_schema |
str |
Destination PostgreSQL schema. If omitted, defaults to schema. |
None |
| col_types |
dict |
Explicit destination PostgreSQL column types for selected columns. |
None |
| obs |
int |
Number of rows to copy from the source table. Implemented with SQL LIMIT. |
None |
| alt_table_name |
str |
Destination PostgreSQL table name. If omitted, defaults to table_name. |
None |
| keep |
str or iterable |
Regex pattern(s) describing columns to keep or drop before loading the destination table. If both are supplied, drop is applied first. |
None |
| drop |
str or iterable |
Regex pattern(s) describing columns to keep or drop before loading the destination table. If both are supplied, drop is applied first. |
None |
| rename |
dict |
Mapping from source column names to destination/output column names. col_types entries should refer to the renamed output columns. |
None |
| tz |
str |
Default timezone used when normalizing timestamp columns. |
'UTC' |
| create_roles |
bool |
If True, ensure destination schema owner and access roles exist and apply ownership and grants to the loaded table. |
True |
Returns
|
bool |
True after the destination table has been created or replaced. |
Examples
>>> db_to_pg("dsi", "crsp", dst_database="research")
>>> db_to_pg("company", "comp", dst_schema="comp_mirror", obs=1000)