Tagged Questions
0
votes
0answers
3 views
How to format a SQLAlchemy ORM Postgresql CIDR contains (>>) query
I have a model defined with:
from app import db
from sqlalchemy.dialects import postgresql
class TableIpAddress(db.Model):
__tablename__ = 'ipaddress'
idipaddress = db.Column( postgresql.UUID, ...
0
votes
1answer
23 views
Best way to avoid data loss in a high-load Django app?
Imagine a quite complex Django application with both frontend and backend parts. Some users modify some data on the frontend part. Some scripts modify the same data periodically on the backend part.
...
0
votes
2answers
24 views
Can't access Postgres DB on Heroku app
I have a Python 2.7 / Flask app running on Heroku that scrapes data and I now want to store that information in a database.
I've tried to follow tutorials like this one and apply this to my case but ...
1
vote
2answers
32 views
How to avoid race condition with unique checks in Django
I have a simple model:
class InvitationRequest(models.Model):
email = models.EmailField(max_length=255, unique=True)
And a simple model form:
class InvitationRequestForm(forms.ModelForm):
...
0
votes
1answer
59 views
Why is django using sqlite3 when I want to use postgresql
I get this stupid error when I try to log into admin.
Exception Type:
OperationalError
Exception Value:
unable to open database file
Exception Location:
...
0
votes
0answers
21 views
postgres - remote connection - PgAdmin connects, php/python doesn't
I've got a VPN to my server network set up. Everything works fine, I can ping servers and ssh around the network. Except for the database connection.
When I use PgAdmin on ubuntu and insert ...
0
votes
0answers
12 views
django cursor excute sql does not return the right value
simple table:
id username gw_id lastlogin
1 180 1 2014-09-04 16:48:57+8
2 181 1 2014-09-04 16:48:04+8
the sql and use the navicat client exute the sql the result
SELECT
...
0
votes
2answers
25 views
Django: distinct on a foreign key, then ordering
I have two models, Track and Pair. Each Pair has a track1, track2 and popularity. I'm trying to get an ordered list by popularity (descending) of pairs, with no two pairs having the same track1. ...
1
vote
1answer
22 views
Getting Started with Python on Heroku - pg_config executable not found
I have been following the documentation until I got to the point of installing the requirements.txt file. It always fails when trying to install line 6 "psycopg2==2.5.3". Here is the message -
...
1
vote
1answer
55 views
Pull large amounts of data from a remote server, into a DataFrame
To give as much context as I can / is needed, I'm trying to pull some data stored on a remote postgres server (heroku) into a pandas DataFrame, using psycopg2 to connect.
I'm interested in two ...
0
votes
1answer
32 views
Python read and write 2 DBs
I have never really used python before.
Before getting into it, I had a quick question to check the feasibility of something I am planning to do here.
I have two servers, MySQL server and postgresql ...
1
vote
2answers
43 views
Manually escape a string for raw SQL
I have a raw SQL statement to be executed using SqlAlchemy. The query contains this:
FROM unnest(array['sku1', 'sku2', 'sku3'])
Building the query manually, I could not find a way to escape each ...
2
votes
1answer
29 views
Why does upgrading Django 1.7c2 to 1.7c3 create new database migrations?
This is not a problem so much as a curiosity, but I've looked around and can't find an answer to this.
When I upgraded Django 1.7c2 to 1.7c3 today, Django identified that I needed new migrations (ie ...
0
votes
1answer
43 views
Celerybeat schedule executing task multiple times?
I have a task calculate_common_locations which runs once via CELERYBEAT_SCHEDULE.
The task simply calls a function in the database:
@app.task
def calculate_common_locations():
db.execute("SELECT ...
0
votes
1answer
35 views
Copy (from) csv with heades in postgres with python
I'm trying to fill a table from CSV files in a python script.
The SQL statement, which follows, runs without error:
COPY registro
FROM '/home/pablo/Escritorio/puntos/20140227.csv'
DELIMITER ','
CSV ...
0
votes
0answers
32 views
Django operational error in postgresql
im having an issue with django, im trying to create a data base on django for my application i have set my conection like this
DATABASES = {
'default': {
'ENGINE': ...
1
vote
0answers
20 views
Django SQL backend strange output with timestamp/epoch
I don't understand what's going on and what to write to google to find solution:
Seems like Django PostgreSQL database engine doing something strange?
first - simple query:
>>> data = ...
0
votes
2answers
42 views
How to efficiently define daily constant?
Using the (awesome) Python Flask framework, I'm building a website, for which I have 3 "constants" which change every morning (so my constants are not very constant, I know, but still). I need these ...
1
vote
1answer
46 views
Creating a query with few related tables in Pyramid with SQLAlchemy
I have defined few tables in Pyramid like this:
# coding: utf-8
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Integer, Float, DateTime, ForeignKey, ...
0
votes
1answer
34 views
Error: `gyp` failed with exit code: 1 while installing jugglingdb-postgres
I am getting this error while installing jugglingdb-postgres in my ubuntu.help me to sort out this problem.Using Python 2.7.4 in my ubuntu.
gyp: Call to 'pg_config --libdir' returned exit status 1.
...
0
votes
1answer
15 views
How to write a SQLAlchemy event listener for when a view within a specific Postgres schema is dropped?
In my app, whenever a view within a certain Postgres schema is dropped, I want to call a specific function. I am familiar with SQLAlchemy's event.listener functionality, but I have mainly seen it used ...
0
votes
1answer
17 views
Postgresql ssl connection through python
I found below link
http://python.projects.pgfoundry.org/docs/1.0/driver.html#connection-keywords
it says...
import postgresql.driver as pg_driver
is the way to import
i used -
import ...
0
votes
1answer
15 views
Storing to database in sqlalchemy with no values
I am trying an api in sql alchemy in which i am storing details of courses into database. The below code is the one i am used in which course name, start date, end date and hours per day are from the ...
0
votes
2answers
42 views
How to Profile Python Database Code
I have a small Python project (~5000 lines) that runs certain heavy statistical calculations on medium-sized Postgres database tables (~50 million entries), using the pg library.
The nature of the ...
0
votes
1answer
14 views
SQLAlchemy One-To-One and One-To-Many at the same time (AmbiguousForeignKeysError)
I'm working with SQLAlchemy and I try to achieve one-to-one and one-to-many relationships on the same parent class.
This is for the simplicity of keeping track of the main child entity.
Unfortunately ...
1
vote
2answers
21 views
How to do division of cells in a csv file before importing into postgres using a python script?
I want to insert price of a product by doing sales dollars/sales units (or 0 if sales unit is 0) into a postgres sql. Is there I can do this when inserting into the database or do I have to run an ...
0
votes
1answer
27 views
Why is Django ManyToManyField causing admin interface to crash? Why is no through table being created?
Why is this line
users_favorited_by = models.ManyToManyField('auth.User')
or this one, which causes the same error:
users_favorited_by = models.ManyToManyField(User)
in this model
class ...
0
votes
0answers
39 views
Why am I gaining an hour when converting to/from epoch timestamp? [duplicate]
example = datetime.datetime(2014, 8, 19, 14, 18, 49, 435413, tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=-240, name=None))
datetime.datetime.fromtimestamp(time.mktime(example.timetuple()))
...
0
votes
0answers
27 views
Passing a string with “accents” to psycopg
I'm trying to create a script that will upload everyday some files to our Postgres DB.
I create a python script that reads all the .csv files in a given directory:
# -*- coding: utf-8 -*-
import os
...
0
votes
1answer
27 views
psycopg2: Insert a numpy array of strings into an PostgreSQL table
Please consider me to be a complete novice with psycopg2. My aim is to insert a 1D numpy array of dtype object (where the elements are only strings) into a postgresQL table. My main program saves the ...
0
votes
1answer
47 views
Update PostgreSQL database with daily stock prices in Python
So I found a great script over at QuantState that had a great walk-through on setting up my own securities database and loading in historical pricing information. However, I'm not trying to modify the ...
0
votes
0answers
42 views
TransactionManagementError - This is forbidden when an 'atomic' block is active
While upgrading my project from django 1.5.1 to 1.6.5, I am facing this weird issue.
This is forbidden when an 'atomic' block is active.
I am aware of the Database Transaction changes for django ...
1
vote
1answer
51 views
For an SQLAlchemy query, how to combine ilike search operator with in_ operator?
I am writing SQLAlchemy code that takes a search bar's input and runs a query against my PostgreSQL database. To allow for misspellings and name fragments, I had this code that did the trick:
q = ...
0
votes
1answer
49 views
Limiting the subquery with SQLAlchemy
I have defined few models in SQLAlchemy:
class Location(Base):
__tablename__ = 'Location'
__table_args__ = {u'schema': 'Location'}
Unit_id = ...
1
vote
1answer
27 views
Postgresql hmac-sha1 signature differs from python signature
Postgres:
Code:
SELECT encode(
hmac(
E'PUT\n\n1\n1408355972\nx-amz-acl:bucket-owner-full-control\n/1/1',
'1sf235123',
'sha1'
),
'base64'
);
Result: ...
0
votes
1answer
31 views
Django-cities exits with “killed”
I am trying to install django-cities on a server with 500mb RAM. Whenever I run:
manage.py cities
the system exits just saying killed.
Trying to run:
manage.py cities --import=country ...
0
votes
0answers
36 views
Installing and using postgis on ubuntu
I have a site running on django and I'm adding the django-cities module to it.
So far I have installed postgresql-9.3-postgis-2.1 and made the necessary changes to the database by running the CREATE ...
0
votes
1answer
22 views
Commit() in psycopg2 seems to be not executed
And so I have this Python file (dosql.py):
import sys
import psycopg2
class doSql(object):
#attributes
_cxn = ""
_cur = ""
errmsg =""
#methods
def __init__(self): ...
0
votes
0answers
24 views
Using psycopg2 cursor.copy_from and StringIO with strings including newline characters
I've been trying to find a solution to the following problem without success.
I want to copy data (different types, floats, strings, etc.) using copy_from method of psycopg2 cursor class, to my db.
...
1
vote
2answers
91 views
using list on postgresql JSON type with sqlalchemy
I am using pyramid with sqlalchemy, pyramid_tm and postgresql to test this.
DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
Base = declarative_base()
class ...
0
votes
2answers
20 views
On what page is my row displayed?
I have a table of posts. I display the list of posts paginated organized by time descending with each page limited to 20 rows. How do I figure out what page a specific row is by id is on so I can link ...
0
votes
0answers
21 views
Django + Postgres __in optimization
I have a few queries that are taking up the majority of my DB access time in production, and I want to optimize them. This is complicated because the slow execution shows up in production, but not in ...
0
votes
1answer
26 views
Type geometry does not exist after CREATE EXTENSION postgis
After creating new postgres db and loading necessary postgis extension
$ createdb demodb
$ psql demodb
> CREATE EXTENSION postgis;
> CREATE EXTENSION postgis_topology;
I get ...
1
vote
1answer
42 views
pyramid transaction manager not committing on update
Sorry i wasn't clear before,
Edited:
I am using default pyramid application with sqlalchemy (backend: postgresql), generated using
pcreate -s alchemy
So i have all the settings related to ...
0
votes
1answer
54 views
Cannot login to django
I cannot login to dango-admin with valid username and password. The problem started when I changed the db from sqlite to postgresql.
I tried to create new users through ./manage.py createsuperuser ...
0
votes
1answer
8 views
Can I use Psycopog2's LoggingConnection with SQLAlchemy?
I am using SQLAlchemy 0.9.7 over Postgres with psyopg2 as the driver.
I have a stray transaction that isn't being closed properly, and in order to debug it, I would like to log all of the operations ...
0
votes
2answers
36 views
Syntax error in FOR loop declare section
I'm attempting to use a FOR loop in Postgres to calculate data averages over a range of (variable) for each geolocation in my db. I am using python/psycopg2. Here is the code:
query ='''
DECLARE ...
0
votes
1answer
47 views
Django Model BooleanField, not required, but also not null choice
It doesn't seem like the Django model.BooleanField has an attribute for required, only for a null choice. However, I only want a "Yes", "No" choices without the null choice, without forcing the user ...
1
vote
1answer
36 views
Postgres: Is there a way of executing code following a INSERT statement?
This may seem strange, but I was curious to know if it was possible for a code block to be executed following an INSERT statement in a postgres database?
Specifically, I'm interested in executing ...
0
votes
1answer
24 views
Django + Postgres + Large Time Series
I am scoping out a project with large, mostly-uncompressible time series data, and wondering if Django + Postgres with raw SQL is the right call.
I have time series data that is ~2K objects/hour, ...