Skip to content
Advertisement

Tag: python

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

psycopg2 not escaping quotation from tuple arguments? Using sql.SQL to format arguments

I’m trying to dynamically create a table in postgres with psycopg2. It seems when the arguments are passed, pyscopg2 is not escaping quotations and understanding my query. Code looks like this: The error I’m getting: What print(create_table_str.as_string(conn)) outputs: Edit to show modified answer that works with no string concatenation Thanks to Adrian for the help Answer sql.Identifier is for SQL

Storing date value into sqlite table in python3 stores integer value

I’m stuck with this bug and on how to solve it. Background: I have built a ‘Paycheck’ table in SQLite that has a date attribute, net pay attribute, and a gross pay attribute. I have set the date attribute to a date datatype in SQLite, and set the net and gross attribute to an integer datatype. The problem: I’m experiencing

‘KeyError’ while filling an SQL table with CSV data

I’m currently working on a project that’s requires wrangling OSM data (Udacity Course), and adding it to an SQLite dataset ready for queries. I’m currently trying to add a ‘.csv’ file to an exisiting SQL table with the following function: However each time I try to execute it get the following error: I’m bewildered as to why i’m getting this

Advertisement