Tagged Questions
0
votes
1answer
16 views
Insert single quotes around a specific columns data with SQL Select Query (or python)
I'm creating a drop down menu in Flask which is populated with staff names from a postgres table. I'm also using the primary key in addition to the names because with the framework I'm using, the ...
0
votes
1answer
13 views
Django 1.11 can't connect to Postgres on RDS
I created a new EC2 Instance with Postgres on RDS. I confirmed that I can connect from the EC2 instance to the database using psql without any issue which means my security settings are fine.
...
0
votes
1answer
21 views
Psql Hint Does not makes any sense
My python code for updating a table is something like this:-
def reportMatch(winner, loser):
"""Records the outcome of a single match between two players.
Args:
winner: the id number ...
1
vote
0answers
37 views
Django + Django REST Framework + PostgreSQL queries and serialization is very slow - yet not a “N+1” case
I like Django + DRF combination and I have used them for a long time, but this problem has bugged me for a while. The problem is that queries + serialization take lots of time when there are ...
0
votes
0answers
23 views
Sqlalchemy How can I slice string and covert it to int then check that is it greater than a number?
This is my db.class:
def Table(db.Model):
uid = db.Column(db.String(80), primary_key=True)
name = db.Column(db.String(80))
The uid column like '201414111', '201633', '2012411'...
The first ...
0
votes
0answers
13 views
Generic partial Index support for sqlalchemy
Along the lines of this question, SQLAlchemy - SQLite for testing and Postgresql for development - How to port?
I realize, that the (above) the consensus is don't test with a db not used in ...
0
votes
0answers
19 views
Tracing Web API calls to database tables
I'm currently looking at a codebase and trying to figure out what database tables are hit for specific API calls. I'd like a way to programmatically find out the specific tables being hit for an API ...
1
vote
0answers
23 views
Postgres Sequences as Default Value for Django Model Field
I have a PostgreSQL database that is being used by a front-end application built with Django, but being populated by a scraping tool in Node.js. I have made a sequence that I want to use across two ...
0
votes
0answers
33 views
How to introduce error handling here?
A newbie here
Thanks in advance
I have two scripts extraction.py and tech_db_queries.py
The extraction.py runs the tech_db_query script and given as json comprising of the multiple queries that are ...
0
votes
0answers
23 views
How to save a record in database with the modified fields to be known ? [on hold]
I am working on algorithm to synchronise between a mobile app and a server.
When the data is offline on the mobile and a field has been updated/changed (sqlite database ) and then need to synchronise ...
1
vote
1answer
48 views
How to query a write-heavy table in PostgreSQL?
I have a PostgreSQL table that records on average ~6 million records throughout the day. It take a very long time to query the table as the records are being recorded. Is there a way to create a ...
0
votes
0answers
28 views
return custom column flask-sqlalchemy
I have a table with below schema
class Centres(db.Model):
__table_args__ = {"schema": "carecentres"}
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
name = db.Column(db....
-2
votes
0answers
16 views
I'm looking for a good sql builder for postgresql with asyncpg [on hold]
I'm making a python server with Sanic.
I'm using asyncpg.
I need some good sql builder like knexjs in javascript.
Is there any idea??
And also I need ORM for that.
0
votes
0answers
43 views
Relation does not exist when execute makemigrations
I'm using Postgres and Django.
I changed my server on localhost to Amazon EC2.
However, when I went to do 'python manage.py makemigrations' or 'python manage.py makemigrations myapp' appeared to me ...
0
votes
0answers
19 views
Generating pre signed url for cross region PostgreSQL replica on AWS
As in the title I have a problem regarding generation of pre signed url to create an encrypted Read Replica in a different AWS Region for PostgreSQL. I am able to do this manually in AWS console ...
1
vote
1answer
45 views
Get the columns that were actually updated to a different value?
I'm running something like this:
cursor.execute(
'''
UPDATE my_table
SET name=%s, about=%s, title=%s
WHERE id=%s
''',
(name, about, title, id_)
)
Which is guaranteed to only ...
0
votes
2answers
16 views
Get the names of all schemas with Psycopg2
I'm trying to iterate all tables of a Postgresql DB in Python, to execute a query in each of them. I need to get the schema and table name of each of them in order to execute the queries, so I'd like ...
0
votes
0answers
18 views
How can update access rules of one module with using other module's access file in odoo 10?
I am working on point of sale, created a new sub module depends on POS.
how can define access rules in child module / extension which updates main module's access file.
2
votes
1answer
31 views
Remove model inheritance and keep id in newly created autofield
I have a model which inherit from a non-abstract super model:
class Person(models.Model):
pass
class User(Person):
pass
Because of a conception mistake we want to remove the Person model ...
0
votes
0answers
21 views
SQLALCHEMY: When is the with_for_update() lock released [duplicate]
does it just get released on session.commit()? I couldn't find documentation on the release of the lock
0
votes
1answer
25 views
SQLAlchemy: get average of greatest-n-per-group
I'm trying to create a Flask app (Postgresql database) that shows the latest score from individual players, including the average scores and goals for the team. So a player can have multiple scores, ...
1
vote
1answer
17 views
SQLAlchemy Postgres query is key exists in JSON
I have a model Definition:
class Definition:
meta = Column(MutableDict.as_mutable(JSON))
It stores any JSON so I want to query if a given key exists in this field.
I need something like:
defs =...
1
vote
2answers
13 views
Python cPickle from a db field TypeError
In my project i save a list as a cPickle object in a byte field of my postgresql db like this:
my_list = list(self.outhtml)
bitRst = cPickle.dumps(my_list)
cur.execute("INSERT INTO frontend_t_test (...
2
votes
1answer
22 views
Django - How to filter a ManyToMany model object?
I have the following models which are linked via a foreign key and ManyToMany relationship.
from django.db import models
from django.contrib.auth.models import User
class AssetMetadata(models.Model):...
0
votes
4answers
27 views
Connecting to Postgres Database via Pyhton
I am trying to connect to my database via Python 2.7 with this code:
import csv
import psycopg2
try:
conn = psycopg2.connect("dbname='student', user='postgres',password='password', host='...
1
vote
1answer
28 views
Django does not migrate app
I'm working on a django project for learning purpose. I've created an app organization and installed it. When I run python manage.py makemigrations organization it works fine shows the changes.
...
0
votes
2answers
24 views
Write dictionnary with tuple containing parameters as unique value for features into postgresql table
In Python 2.7, let a dictionary with features' IDs as keys.
There are thousands of features.
Each feature has a single value, but this value is a tuple containing 6 parameters for the features (for ...
0
votes
1answer
28 views
Partial matches with PostgreSQL full text search
Django's documentation for the PostgreSQL full text search uses the following example:
>>> Entry.objects.filter(body_text__search='Cheese')
[<Entry: Cheese on Toast recipes>, <Entry:...
0
votes
0answers
19 views
Django deepcopy object with foreign keys
A usual copy of a certain object of class A in Django would look like this:
obj = A.objects.get(...) # get the object
obj.id = None
obj.save()
However if class A has a foreign key of some class B ...
0
votes
2answers
19 views
Django postgres remove all data created after a point in time
How can I remove all the objects which were created after some timestamp t in django?
Plainly, I need to remove all the objects (all rows in all tables) which have created_at > t. Is there any ...
2
votes
1answer
32 views
Optimizing postgres contains (LIKE) query in django for CHAR field
So I've got a query for a search endpoint in my Django (postgres) backend like so:
widgets = Widgets.objects.\
filter(user=request.user).\
filter(title__icontains="marketing director").\
...
0
votes
1answer
19 views
Openerp 7- how to run datetime update query
I am having problem with this update query and I don't understand the error here. please help me to solve this.
Field
'sign_in' : fields.datetime("Sign In"),
Variable
sgn_in1 = datetime.datetime....
-1
votes
1answer
29 views
Python: UnicodeDecodeError: 'utf8'
I'm having problem to save accented letters. I'm using POSTGRESQL and Python 2.7
POSTGRESQL - ENCODING = 'LATIN1'
I already added this line but does not worked!
#!/usr/bin/python
# -*- coding: ...
0
votes
2answers
42 views
python database application try except block
this is a login function in an application interacting with a database in postresql. I'm new to python and currently both print statements in the except blocks are being executed.
The error is in: ...
0
votes
0answers
17 views
pyodbc connection issue with psqlodbc driver on osx
I'm trying to connect to my local postgres database via pyodbc(i'd like to use MySQL workbench to import/view a postgres schema eventually), and I can't seem to get anything to find my psqlodbc driver....
0
votes
0answers
17 views
psycopg2.ProgrammingError: non-integer constant in ORDER BY [duplicate]
I have the following code to run a postgres query with a dictionary, which allow order by from user input.
query = "select * from table1 order by %(sort)s"
params = {'sort': 'id'}
cursor.execute(...
1
vote
2answers
40 views
Django QuerySet vs. raw SQL performance considerations
I'm learning Django and its ORM data access methodology and there is something that I'm curious about. In one particular endpoint, I'm making a number of database calls (to Postgres) - below is an ...
0
votes
1answer
9 views
Luigi passing small data between tasks
Using Luigi I want to do a query on my postgres DB to get a lat/lng coordinate pair then pass that pair onto another task.
I have a task QueryPostgres() that takes a SQL string as an input and ...
1
vote
1answer
21 views
Python Postgres - psycopg2.ProgrammingError: no results to fetch
I have been stuck at this since an hour. I am new to postgres. The CRUD operations are too wierd in postgres.
I cannot fetch the id of latest inserted row
I used the cursor.fetchone()[0] after cur....
0
votes
1answer
30 views
Executing SQL Server stored procedures with parameters in Python
I'm trying to execute a stored procedure to query a table, and am having trouble passing through a parameter successfully.
title=cursor.execute("SELECT titlequery(%s)", str(member_id))`
titlequery()...
0
votes
1answer
12 views
Python Postgres - AttributeError: 'unicode' object has no attribute 'data'
The error i received is
Traceback (most recent call last): File "main.py", line 75, in
VALUES (%d,%f,%s,%s,%s,%s,%s,%f,%d)",(company_id,data["FOB_value"],str(data["FOB_currency"]),data["...
0
votes
0answers
21 views
Column is marked as a member of the primary key for table, but has no Python-side or server-side default generator
Here is a table I'm making:
URL = 'postgresql://{}:{}@{}:{}/{}'
DB_URL = URL.format(
DB_USER_NAME,
DB_PASSWORD,
DB_HOST,
str(DB_PORT),
DB_NAME)
print("creating db engine.....
0
votes
1answer
33 views
Best way to use input and output tables
There is a data model(sql) with a scenario where it uses one input table and it is fed into the prediction model(python) and some output variables are generated onto another table and final join is ...
0
votes
1answer
22 views
objects deleted from table still persist when accessing model objects via django
I am working on a django app with a postgresql backend. I am working on a separate python script to access the table (model via django) to make some modifcations, then launch web forms for the ...
0
votes
0answers
15 views
Celery 4 how to best structure tasks?
Fairly new to Celery and am trying to understand how to best structure tasks since class-based tasks are no longer ideal.
For example, when trying to write a simple class to backup a postgres ...
1
vote
1answer
48 views
How to build up a nested query using Django's Database API
I need to create a queryset in Django of the following PostgreSQL statement.
SELECT * FROM
(
SELECT DISTINCT ON("atech_cars".
"model")
"atech_cars".
"make", "atech_cars".
"model", "atech_cars".
"...
1
vote
1answer
25 views
How to create a table in PostgreSQL using pyscopg2?
I'm running a Docker Compose application which includes postgres as a service. Here is a portion of docker-compose.yml:
version: '3'
services:
postgres:
image: postgres
environment:
-...
-1
votes
1answer
24 views
Get the data by one from psql database
On my Postgres database I have two tables the dates and the stocks (tickers). i need for a specific period of time (2014-1-1 to 2015-1-1) in each day d on that period i need to go back 10 days and go ...
0
votes
1answer
56 views
Writing dataframe to postgres database
I want to write a pandas dataframe to a postgres table. I make a connection to db as follows:
import psycopg2
import pandas as pd
import sqlalchemy
def connect(user, password, db, host='localhost', ...
0
votes
1answer
35 views
Flask Postgres client on Azure: No module named 'psycopg2' but it is installed
I've build a Flask app that connects with Azure PostgreSQL database and uploads data from API to that database. Everything is working fine on my PC but when I open my webpage I get an error:
The page ...