[Psycopg] problem creating a table and array value must start with "{"

bussiere maillist bussieremaillist at gmail.com
Fri Aug 24 09:23:28 CEST 2007


i have two problems the first one is that when i execute my init code
it seems to works and i have no errors but it doesn't create the table
=_=
so i've done it by hand with the psql exec
here is my init code :
=============================================
import psycopg2
import psycopg2.extensions
import logging
class LoggingCursor(psycopg2.extensions.cursor):
    def execute(self, sql, args=None):
        logger = logging.getLogger('sql_debug')
        logger.info(self.mogrify(sql, args))
DSN = "dbname='image' user='postgres' password='rpgjdr09'"
conn = psycopg2.connect(DSN)
curs = conn.cursor(cursor_factory=LoggingCursor)
requete = "CREATE TABLE images (nom TEXT,contenu TEXT);"
curs.execute(requete,(10, 20, 30))
=================================================
And the result when i execute it :
>>>
>>>
It seems to work but it doesn't create my table =_=
so i've done it by hand cool =_=

Then i've wanted to binary read image and put them in my db with this code :
=====================
import os.path
import re
import psycopg2
import psycopg2.extensions
import logging
import base64
class LoggingCursor(psycopg2.extensions.cursor):
    def execute(self, sql, args=None):
        logger = logging.getLogger('sql_debug')
        logger.info(self.mogrify(sql, args))

        try:
            psycopg2.extensions.cursor.execute(self, sql, args)
        except Exception, exc:
            logger.error("%s: %s" % (exc.__class__.__name__, exc))
            raise
DSN = "dbname='image' user='postgres' password='rpgjdr' host='localhost'"


def listdirectory2(path):
    fichier=[]
    for root, dirs, files in os.walk(path):
        for i in files:
            fichier.append(os.path.join(root, i))
    return fichier
liste = []
cherchefichier =
re.compile('\.((j|J)(p|P)(e|E)?(g|G))|((g|G)(i|I)(f|F))|((p|P)(n|N)(g|G))|((b|B)(m|M)(p|P))|((r|R)|(a|A)|(w|W))')
fichier = listdirectory2('')
for files in fichier :
    if cherchefichier.search(files):
        liste.append(files)

for fichier in liste :
    file = open(fichier,"rb")
    data = base64.b64encode(file.read())
    data = str(data)
    file.close()
    print fichier + "\n"
    fichier = str(fichier)
    conn = psycopg2.connect(DSN)
    curs = conn.cursor(cursor_factory=LoggingCursor)
    requete = """
    INSERT INTO images VALUES ('%s','%s');
    """ % (fichier,data)
    curs.execute(requete)
    conn.close()
=====================
then i have this ***** problems :
Traceback (most recent call last):
  File "E:\Mes Documents\Mes images\100SSCAM\miseenbd.py", line 45, in <module>
    curs.execute(requete)
  File "E:\Mes Documents\Mes images\100SSCAM\miseenbd.py", line 13, in execute
    psycopg2.extensions.cursor.execute(self, sql, args)
ProgrammingError: array value must start with "{" or dimension information


And i truly doesn't understand why i've tried a lot of things and
searching on the internet i've found this :
rom fog at initd.org  Fri Jun 17 10:40:06 2005
From: fog at initd.org (Federico Di Gregorio)
Date: Fri Jun 17 10:50:14 2005
Subject: [Psycopg] Insert a scalar value into an array field and it
	blows up :(

But it doesn't truly help me

By the way help will be truly appreciated and here in france it's 9 am
and i'haven't sleep all night now i will go to sleep and pray in my
dream to someone could explain me this bug when i will wake up

Good night

and regards
Bussiere


More information about the Psycopg mailing list