core.wrds_pg_to_pg

core.wrds_pg_to_pg(
    table_name,
    schema,
    *,
    wrds_id=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 WRDS PostgreSQL table to another PostgreSQL database.

Parameters

Name Type Description Default
table_name str Name of the WRDS source table. required
schema str Name of the WRDS source schema. required
wrds_id str WRDS user ID used to access the WRDS PostgreSQL service. If omitted, resolve from WRDS_ID / WRDS_USER and related .env configuration. 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 WRDS. 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 WRDS PostgreSQL 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

Name Type Description
bool True after the destination table has been created or replaced.

Examples

>>> wrds_pg_to_pg("dsi", "crsp", dst_database="research")
>>> wrds_pg_to_pg("company", "comp", dst_schema="comp_mirror", obs=1000)