This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright 2017 Gordon D. Thompson | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Alternative to_sql() *method* for mssql+pyodbc, mssql+pymssql, or mssql+pytds | |
# | |
# adapted from https://pandas.pydata.org/docs/user_guide/io.html#io-sql-method | |
# | |
# version 1.6 - 2024-03-28 | |
from datetime import date | |
import json | |
import pandas as pd | |
import sqlalchemy as sa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright 2024 Gordon D. Thompson, [email protected] | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright 2024 Gordon D. Thompson, [email protected] | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
A DataFrame that contains a lot of "null" values (NaN, etc.) can cause a | |
significant performance penalty with fast_executemany=True. For details, see | |
https://github.com/mkleehammer/pyodbc/issues/741 | |
This routine scans the specified DataFrame to see how many "row scans" would be | |
required when using .to_sql() with fast_executemany=True. The first row must | |
always be scanned, but after that a re-scan will flush the current rows to the | |
server, increasing network traffic and slowing things down. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import sqlalchemy as sa | |
from sqlalchemy_cockroachdb.transaction import run_transaction | |
connection_url = "cockroachdb+psycopg2://root@localhost:26257/defaultdb" | |
connection_url = "postgresql+psycopg2://scott:[email protected]/test" | |
engine = sa.create_engine(connection_url) | |
def read_sql_qry_trans(qry, engine_): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import sqlalchemy as sa | |
from sqlalchemy_cockroachdb.transaction import run_transaction | |
engine = sa.create_engine( | |
"cockroachdb+psycopg2://root@localhost:26257/defaultdb" | |
) | |
def crdb_insert_trans(table, eng, keys, data_iter): |