How can I filter a list in jinja2 to generate a list of values from a lookup table? I have a situation where I am using Jinja2 to generate SQL. I have a list of values and I want to replace them with a list of transformed values based on a lookup: In my template, I want to be able
Tag: python
Best way to check if database already exists with flask-sqlalchemy, otherwise create
I have a database app, and want to create the tables and database on the fly when starting the app for the first time. If the app is restarted, it should only create the database and tables if they do not exist, otherwise ignore this creation. I have a few questions. 1.) Is this a proper way of dealing with
executing .py in html/php
I wrote a Python script which writes its output into a txt file. Then I included that file in my html/php website. – works good so far. Only remaining problem: I can’t execute the .py file automatically while opening the site. I know that this isn’t the best solution <?PHP exec(“python3 Auswertung.py”); ?> doesn’t seem to work Answer I used
Print Query Result in Console – Robot Framework
I’m using Robot Framework in automations. Now I’m adding SQL Server scripts. In order to facilitate, I would like to make a print of my query (select) to display in the console. How do I do? I tried with the following way, but without success: and The latter prints to the console, but the query sent, in this case, select
Convert SQL commands to Python
I have the following code in SQL: I’ve been trying to rewrite it in python like so: but I keep getting a generic error message. What am I doing wrong? EDIT: added the error message Answer IIUC, you could try the following: The equivalent of SELECT DISTINCT col is drop_duplicates(col) and the equivalent of SELECT col, count(*) is value_counts(col).
How can I Insert multiple rows with one query
I made a code allowing me to GET data from an API and insert it into a database. But I encounter a problem my api contains about 20 million data and to insert everything in my database it will take me 43 days 🙂 I think the problem comes from the fact that I insert the data one by one.
How to dynamically pass values to the Oracle bind variable using Python (Using cx_oracle module)
I need to get values a from client dynamically(using input function) and I need to pass that value to Oracle bind variable. I am using SQL queries. Answer Here’s an example: Running it gives:
pyodbc is returning binary data in char field
pyodbc with driver “iSeries Access ODBC Driver” is returning binary output, Ex: original data in the table: B06300 what it returns: b’xc2xf0xf6xf3xf0xf0@@@@@@@@@@@@@@@@@@@@@@@@’ My code: I tried putting add_output_converter and encoder to connection but didn’t work Answer I suspect the problem is that the data is defined on the server as CCSID 65535, which means to not translate the data. Using
find timestamp difference between 2 columns with sqldf
According to this answer: https://stackoverflow.com/a/25863597/12304000 We can use something like this in mysql to calculate the time diff between two cols: How can I achieve the same thing with pandasql? I tried these: but they throw an error that: Answer From the PandaSQL documentation: pandasql uses SQLite syntax. The link in your post is for MySQL. Here is a reference
sqlite query based on selecting from column string and filtering by last rows in descending order
I have a database, tick_df, that looks like this I am trying to select all columns and the last 2 rows in descending time order from only one symbol – e.g.AVAX/USD:USD. The query I have tried is But this return an error can anyone point to what I’m doing wrong here. Thanks Answer If you look at the error message