Skip to main content

Truncate existing table and write to the table with new entries

Project description

A small package for truncating a table before writing to it

Install

pip install truncate-and-write-to-sql

Example usage

import pandas as pd
from sqlalchemy import create_engine

from truncat_and_write_to_sql.methods import truncate_and_write_sql

# Establish a connection to a SQL database
connection_string = 'a connection string to a database'
engine = create_engine(connection_string)

# Create a dataframe to write to the database
data = {'First Column Name':  ['First value', 'Second value'],
        'Second Column Name': ['First value', 'Second value']}
df = pd.DataFrame(data)

# Truncate existing values and write in new ones
truncate_and_write_sql(
    con=engine,
    df=df,
    table='name of database table',
    schema='database schema e.g. stg',
    if_exists='append',
    mulit=True
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

truncate-and-write-to-sql-0.1.1.tar.gz (2.4 kB view hashes)

Uploaded Source

Built Distribution

truncate_and_write_to_sql-0.1.1-py2.py3-none-any.whl (3.7 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page