postgresql

update column to two based on condition

update column to two based on condition Question: I am trying to modify ONE column, I want to set some rows as true the others convert them to false update products set on_sale=False where status=1 and seller=test; update products set on_sale=true Where price > 100 and status=1 and seller=test; the above works, but I believe …

Total answers: 1

python + psycopg2.errors.SyntaxError: syntax error at end of input

python + psycopg2.errors.SyntaxError: syntax error at end of input Question: I’m getting this error message cursor.execute(query, variables) psycopg2.errors.SyntaxError: syntax error at end of input My code data = { ‘country’: data[‘country’][x], ‘year’: data[‘year’][x].astype(float), ‘month’: data[‘month’][x].astype(float) } db_connection.execute( f""" INSERT INTO my_table (country, year, month) VALUES (%(country)s, %(year)s, %(month)s) ON CONFLICT (country, year, month) """, data, …

Total answers: 1

Moving tables data from sqlite3 to postgressql

Moving tables data from sqlite3 to postgressql Question: What is the simplest way to move data from sqlite3 tables to posgressql in Django project Asked By: Islam Fahmy || Source Answers: To perform a data backup, we use the following command: python manage.py dumpdata > data.json #use this command adding before postgres in django This …

Total answers: 1

Load JSON data into postgres table using airflow

Load JSON data into postgres table using airflow Question: I have an Airflow DAG that runs a spark file (reads two parquet files, performs transformations on them, and loads the data into a single JSON file). Now the data from this JSON file needs to be pushed into a Postgres table. At first, I was …

Total answers: 1

combine python lists into sql table

combine python lists into sql table Question: I have two lists which I want to combine into an sql table using pandas.read_sql. I tried using unnest, but it gives me the wrong output. Attempt below: import pandas as pd from sqlalchemy import create_engine engine = create_engine( "postgresql+psycopg2://postgres:[email protected]:5432/database" ) list1 = ["a", "b", "c"] list2 = …

Total answers: 1

pandas read_sql_query with params matching multiple columns

pandas read_sql_query with params matching multiple columns Question: I’m trying to query a table using pandas.read_sql_query, where I want to match multiple columns to python lists passed in as param arguments. Running into various psycopg2 errors when trying to accomplish this. Ideally, I would provide a reproducible example, but unfortunately, that’s not possible here due …

Total answers: 2

Using parameters to return table column values?

Using parameters to return table column values? Question: I want to be able to use a parameter to determine which columns value to return. But, since ‘owner’ is a model, the ‘assetType’ in ‘owner.assetType’ is treated as an attribute and not as the parameter. This is just an example of the code I’m working on. …

Total answers: 1

How to add different type of files in postgresql on Python

How to add different type of files in postgresql on Python Question: I need to add different types of files (CSV, XML, xlsx, etc.) to the database (Postgresql). I know how I can read it via pandas, but I have some issues with adding this to the database. What libraries do I need to use? …

Total answers: 1

Trying to dockerize Django app receive error "ERROR [3/6] RUN apk update"

Trying to dockerize Django app receive error "ERROR [3/6] RUN apk update" Question: I’m completely new to Dockers, I’m trying to dockerize a Django application using: FROM python:3.10.4-alpine3.15 ENV PYTHONUNBUFFERED=1 WORKDIR /app RUN apk update && apk add –no-cache gcc musl-dev postgresql-dev python3-dev libffi-dev && pip install –upgrade pip COPY ./requirements.txt ./ RUN pip install …

Total answers: 1

Why does my Django form data not appear in the database?

Why does my Django form data not appear in the database? Question: I try to develop a simple input form to save a deposit for a fishing vessel. The vessel and the net are tables in the database. There is no error when the form is submitted but there is nothing happening in the background. …

Total answers: 2