temp-tables

Trying to insert pandas dataframe to temporary table

≡放荡痞女 提交于 2021-02-08 08:37:15
问题 I'm looking to create a temp table and insert a some data into it. I have used pyodbc extensively to pull data but I am not familiar with writing data to SQL from a python environment. I am doing this at work so I dont have the ability to create tables, but I can create temp and global temp tables. My intent is to insert a relatively small dataframe (150rows x 4cols)into a temp table and reference it throughout my session, my program structure makes it so that a global variable in the session

How to prevent pandas dataframe from adding double quotes around #tmp when using sqlalchemy and sybase?

天大地大妈咪最大 提交于 2021-02-05 07:43:49
问题 I have reduced the issue to pandas to_sql adding double quotes around #tmp when dealing with sybase using sqlalchemy as the pooling framework. Code : def get_data_with_tmp(): engine = get_connection("sybase") with engine.connect() as conn: df = pd.DataFrame({'alias_id': ['345402KP5', '3454014R1']}) df.to_sql(name='#tmp', con=conn, schema=None, if_exists='append', index=False) df = pd.read_sql_query("SELECT alias_id from #tmp", con=conn) Error: statement = '\nCREATE TABLE "#tmp" (\n\talias_id

How to update multiple rows in a temp table with multiple values from another table using only one ID common between them?

筅森魡賤 提交于 2021-01-29 07:00:22
问题 I am trying to reconcile the IDs in a temp table (top) from another DB table (bottom). Since I only have one ID that's common between the two, I am only getting the top result for all the rows (ReconGlobalRemunerationGrantID) in my temp table. I am aiming to get each of the unique ID and update my temp table as such. Right now, my update query is simple and I update using the ID common between the 2 tables. Is there a function or another command statement I can use to get the result intended?

How to allow temporary tables to accept null values

五迷三道 提交于 2020-12-08 10:52:34
问题 If you create temp tables using "insert into" in SQL Server it uses the first insert to determine whether a column accepts null value or not. if the first insert has null value the column become nullable otherwise it will be non-nullable. Is there a way to create temp tables using "insert into" to accept null values? Example This works without any problem Select 'one' as a , null as b into #temp insert into #temp Select 'two' as a , 500 as b However this throws "Cannot insert the value NULL

Use temp table with SQLAlchemy

爷,独闯天下 提交于 2020-12-01 06:19:32
问题 I am trying to use use a temp table with SQLAlchemy and join it against an existing table. This is what I have so far engine = db.get_engine(db.app, 'MY_DATABASE') df = pd.DataFrame({"id": [1, 2, 3], "value": [100, 200, 300], "date": [date.today(), date.today(), date.today()]}) temp_table = db.Table('#temp_table', db.Column('id', db.Integer), db.Column('value', db.Integer), db.Column('date', db.DateTime)) temp_table.create(engine) df.to_sql(name='tempdb.dbo.#temp_table', con=engine, if_exists

How to Add a Set of Keys (UniqueIDs) to a Temp table to later INSERT into Production Table

[亡魂溺海] 提交于 2020-06-17 09:54:30
问题 I have the data ready to Insert into my Production table however the ID column is NULL and that needs to be pre-populated with the IDs prior to Insert. I have these IDs in another Temp Table... all I want is to simply apply these IDs to the records in my Temp Table. For example... Say I have 10 records all simply needing IDs. I have in another temp table exactly 10 IDs... they simply need to be applied to my 10 records in my 'Ready to INSERT' Temp Table. I worked in Oracle for about 9 years