Another crack at this: I have a frequent problem with python's psycopg2, perhaps in 2 parts. First, I consistently screw up string assignment, if anyone can lobotomize line 5 below for me, much appreciated (The first answer does work with 1 value.) Second, when I try to add a long sequence to a table, something like string-number pair i...
Hello,
For some reasons, I would like to do an explicit quoting of a string value (becoming a part of constructed SQL query) instead of waiting for implicit quotation performed by cursor.execute method on contents of its second parameter.
By "implicit quotation" I mean:
value = "Unsafe string"
query = "SELECT * FROM some_table WHERE s...
Hi again,
I have been using python with RDBMS' (MySQL and PostgreSQL), and I have noticed that I really do not understand how to use a cursor.
Usually, one have his script connect to the DB via a client DB-API (like psycopg2 or MySQLdb):
connection = psycopg2.connect(host='otherhost', etc)
And then one creates a cursor:
cursor = co...
I am getting the error OperationalError: FATAL: sorry, too many clients already when using psycopg2. I am calling the close method on my connection instance after I am done with it. I am not sure what could be causing this, it is my first experience with python and postgresql, but I have a few years experience with php, asp.net, mysql, a...
I'm trying to insert binary data (a whirlpool hash) into a PG table and am getting an error:
TypeError: not all arguments converted during string formatting
code:
cur.execute("""
INSERT INTO
sessions
(identity_hash, posted_on)
VALUES
(%s, NOW())
""", identity_hash)
I tried adding conn.Binary("identit...
Is there a way to get savepoint support in a Zope connection to Postgres?
I'm currently using ZPsycopgDA, which doesn't support savepoints, and is also hard to install with buildout. Would switching to something like SQLAlchemyDA make things easier?
Background: I've got my users in a postgres database, but when I try look at the histor...
We have a rather specific application that uses PostgreSQL 8.3 as a storage backend (using Python and psycopg2). The operations we perform to the important tables are in the majority of cases inserts or updates (rarely deletes or selects).
For sanity reasons we have created our own Data Mapper-like layer that works reasonably well, but...
Is there any way to share same transaction between two threads in a django-based code?
The problem is that I have 1.1's TestCase (those that wrap individual tests into transactions) that are intended to test code that is running in a different thread [a sort of asynchronous testing]. So these test create some data that is intended to be...
I am using Python with psycopg2 and I'm trying to run a full VACUUM after a daily operation which inserts several thousand rows. The problem is that when I try to run the VACUUM command within my code I get the following error:
psycopg2.InternalError: VACUUM cannot run inside a transaction block
How do I run this from the code outsid...
I have a pair of Django models with a foreign key, one of which is searchable with django-fts, say:
class Foo(models.Model):
...
class Bar(fts.SearchableModel):
foo = models.ForeignKey(Foo)
When I have an instance of Foo, in view I can insert print foo.bar_set.all() and I see an array of results. However if I try to use it in...
Hi folks,
I have a python application that opens a database connection that can hang online for an hours, but sometimes the database server reboots and while python still have the connection it won't work with OperationalError exception.
So I'm looking for any reliable method to "ping" the database and know that connection is alive. I'...
>>> import psycopg2
Traceback (most recent call last):
File "", line 1, in
File "C:\Python26\lib\site-packages\psycopg2\__init__.py", line 60, in
from _psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: DLL load failed: The application has failed to start because its si
de-by-side configuration is incorrect. P...
i have configured pgpool-II for postgres connection pooling and i want to disable psycopg2 connection pooling. how do i do this?
thanks!
...
Just for the record, i just started programing on python, and this is the first time i try to do a daemon.
I have a problem handling DB connections in a daemon i've been working on, the first thing i do, is connect to my postgres db with:
try:
psycopg2.apilevel = '2.0'
psycopg2.threadsafety = 3
cnx = psycopg2.connect( "host='192....
I need to generate a list of insert statements (for postgresql) from html files, is there a library available for python to help me properly escape and quote the names/values? in PHP i use PDO to do the escaping and quoting, is there any equivalent library for python?
Edit: I need to generate a file with sql statements for execution lat...
I've been tackling this for a while. I setup a completely new machine. I've installed a fresh copy of postgresql and all my other dependencies. Basically, I get these database disconnections at random times. I can perform identical requests and either it works or it doesn't. Very nondeterministic in outward appearance. Watching logs at P...
I am trying to setup roundup on a windows XP machine.
I use psycopg2 v2.0.13 and when i import the psycopg2 module from the shell it all works fine, but when mod_python tries to do it, I get this error:
MOD_PYTHON ERROR
ProcessId: 3464
Interpreter: 'roundup'
ServerName: 'roundup'
DocumentRoot: 'C:/Dev/roundup/tracker'
U...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.6/site-packages/psycopg2/__init__.py", line 60, in <module>
from _psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: dlopen(/Library/Python/2.6/site-packages/psycopg2/_psycopg.so, 2): Symbol not found: _PQbackendPID
R...
I'll take the simplest of the SQL functions as an example:
CREATE OR REPLACE FUNCTION skater_name_match(INTEGER,VARCHAR)
RETURNS BOOL AS
$$
SELECT $1 IN (SELECT skaters_skater.competitor_ptr_id FROM skaters_skater
WHERE name||' '||surname ILIKE '%'||$2||'%'
OR surname||' '||name ILIKE '%'||$2||'%');
$$ LANGUAGE SQL;
If I ...
Dear all
I have small code like below :
#!/usr/bin/python
import psycopg2, sys
try:
conn = psycopg2.connect("dbname='smdr' user='bino'");
except:
print "I am unable to connect to the database"
cur = conn.cursor()
v_num = '1'
cur.execute("SELECT * from genctr WHERE code = %(num)s", dict(num=v_num))
rows = cur.fetchall()
print ...