Skip to main content

Generates SQL insert values script for data

Project description

Purpose

Generates an SQL insert script based on data. Useful when developing databases and an insert script should be defined as post-deploy step.

from ScriptorQL.script import df_to_SQL_insert

# Define a dataframe
# Table example:
# SchemaName.TableName
#
#   col1  |  col2  |  col3
# --------------------------
#   abc  |  val1  |  1
#   def  |  val2  |  2
#   hij  |  val3  |  3
#
# See pandas data frame

sql_script = df_to_SQL_insert(df, table="TableName", schema="SchemaName")
print(sql_script)

Result:

INSERT INTO SchemaName.TableName(col1, col2, col3)
VALUES  ('abc','val1','1'),
        ('def','val2','2'),
        ('hij','val3','3')

To Do

  • Better documentation
  • Recognize datatypes (Always quoted right now)

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

ScriptorQL-0.0.3.tar.gz (2.3 kB view hashes)

Uploaded Source

Built Distribution

ScriptorQL-0.0.3-py3-none-any.whl (16.3 kB view hashes)

Uploaded 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