Skip to content
Advertisement

Tag: postgresql

How does a Django UUIDField generate a UUID in Postgresql?

After reading this blog post https://blog.starkandwayne.com/2015/05/23/uuid-primary-keys-in-postgresql/ I wanted to know more about how Django generates uuid because I am using them as my pk. Well, according to the docs, https://docs.djangoproject.com/es/1.9/ref/models/fields/#uuidfield, Django is relying on the Python UUID module https://docs.python.org/3/library/uuid.html#uuid.UUID. But there are many kinds of UUID, and it is not at all clear to me which one is being generated

Error Installing Psycopg2 on MacOS 10.9.5

I’m trying to install Psycopg2 on my Macbook, but I am getting an error. I found a lot of the same questions on StackOverflow but no answer seems to work. I’m using: OS: MacOS 10.9.5 Python Version: 3.4.3 My error code is: Answer I ran pip install psycopg2-binary and it worked like charm More info about the binary package Python

Django change database field from integer to CharField

I have a Django app with a populated (Postgres) database that has an integer field that I need to change to a CharField. I need to start storing data with leading zeros in this field. If I run migrate (Django 1.8.4), I get the following error: I tried searching Google, but didn’t really find much help. I don’t really know

Installing psycopg2 in a virtualenv in ubuntu os

I using a virtualenv and I am trying to set up postgresql. I have psycopg2 installed on my system, but it appears that my virtual env does not recognize psycopg2. Is it possible to just copy the system wide psycopg2 files into my django project directory or is this a bad approach to take? This is the relevant part of

Postgresql Database Backup Using Python

I would like to backup database using Python code. I want to backup some tables of related data. How to backup and how to choose desired tables using “SELECT” statement? e.g. I want to get data from 2014-05-01 to 2014-05-10 of some tables and output this result as .sql extension file How can I get this format using python code?

How to write DataFrame to postgres table

There is DataFrame.to_sql method, but it works only for mysql, sqlite and oracle databases. I cant pass to this method postgres connection or sqlalchemy engine. Answer Starting from pandas 0.14 (released end of May 2014), postgresql is supported. The sql module now uses sqlalchemy to support different database flavors. You can pass a sqlalchemy engine for a postgresql database (see

query from postgresql using python as dictionary

I’m using Python 2.7 and postgresql 9.1. Trying to get dictionary from query, I’ve tried the code as described here: http://wiki.postgresql.org/wiki/Using_psycopg2_with_PostgreSQL It is printing the next answer: printing the item itself, show me that it is list. The excepted answer was dictionary. Edit: Trying the next: returns Answer If you don’t want to use a psycopg2.extras.DictCursor you can create a

Advertisement