psycopg2

Andre' John joa at hrz.tu-chemnitz.de
Fri Feb 1 05:02:30 EST 2008


Thanks very much, this was indeed the problem. That column was an array. 
I created it via GUI and was wondering why it did append a '[]' to the 
variable type, but didn't bother, because there was no other varchar 
available.

Cheers

Andre

PS: Weird though how few results turn up when running that through 
Google.


On Thu, 31 Jan 2008, Steve Holden wrote:

> Andre' John wrote:
> > Hi
> > 
> > I am trying to do this for a Postgresql database:
> > 
> > conn = psycopg2.connect('host=localhost')
> > cur = conn.cursor()
> > cur.execute("SELECT * FROM names WHERE name=%s", ['S'])
> > 
> > , which doesn't work, and neither does
> > 
> > cur.execute("SELECT * FROM names WHERE name='%s'", ['S'])
> > 
> > or
> > 
> > cur.execute("SELECT * FROM names WHERE name='S'")
> > 
> > work.
> 
> I'm more inclined to believe the first two than the third, but I suppose if
> you are telling the truth (House: "Patients always lie") then I am guessing
> you have defined your table's "names" columns to be an array type.
> 
> I haven't worked with those (since they don't confirm to the strict relational
> model I prefer to work with), but I am guessing you might try
> 
> 
> cur.execute("SELECT * FROM names WHERE name='%s'", (['S'], ))
> 
> as this provides the necessary tuple as the second argument to execute, and
> the on;y element of the tuple is a list of a single element.
> 
> > It always returns:
> > 
> > Traceback (most recent call last):
> > 
> >   File "<stdin>", line 1, in <module>
> > 
> > psycopg2.ProgrammingError:  array value must start with ?{½ or dimension
> > information
> > 
> > 
> > Though, when doing
> > 
> > cur.execute("SELECT * FROM names")
> > 
> > it works.
> > I am totally helpless here. Does anyone have an idea?
> > 
> If my suggestion doesn't work, you should probably let us know more about the
> structure of your table.
> 
> regards
>  Steve
> 


More information about the Python-list mailing list