Skip to content
Advertisement

Tag: sqlalchemy

Python problem with adding table to Database with sql

Hi, I’m trying to create a function that will take a table in insert(add) to the database. My Code : this is the old code when i didn’t create a function: Answer You seem to have put table_name under quotations in your to_sql function. Also, you seem to be tackling the issue of data model creation and maintenance, which already

SQLAlchemy – How to count distinct on multiple columns

I have this query: I’ve tried to recreate it with SQLAlchemy this way: But this translates to this: Which does not call the count function inline but wraps the select distinct into a subquery. My question is: What are the different ways with SQLAlchemy to count a distinct select on multiple columns and what are they translating into? Is there

Python SQL: Error reading and executing SQL file

I’m trying to red and execute a SQL file in Python using sqlalchemy. Should be simple, right? I get this error Why am I getting this error? I’m not sure if this is a file encoding error or a SQLAlchemy error. Ideally, this should be simple. EDIT: This code works fine, assuming the table temp exists: EDIT 2: For reference,

sqlalchemy concat with more than 2 elements on Oracle DB

considering the following table definition I create a select-statement using the sqlalchemy.sql.functions.concat with 3 statements using the query is generated. However, when I run this, the exception ORA-00909: invalid number of arguments is thrown. This is because CONCAT (https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions026.htm) only allows 2 Arguments. My workaround for now ist to use concat inside of concat, which works However, this makes the

How do I select a PostgreSQL system column using SQLAlchemy?

Postgresql implicitly defines several columns on every table, such as xmax and ctid (see docs). Assuming my SQLALchemy table definition does not specify these columns, is there a way to select them using the core sql functionality (i.e. not the ORM part of SA)? The following does not work as xmax is not explicitly defined in the table definition. Specifically

Conditional Join Between SQL Table and Pandas Dataframe

I am working on an application and one step of the processing involves joining drug NDC’s from claim data with a table that contains the NDC along with a variety of other information including unit price, multisource code, and more. The table of claims data looks something like this: It was read into a Pandas dataframe as follows: The SQL

Advertisement