psycopg2

Steve Holden steve at holdenweb.com
Thu Jan 31 19:38:29 EST 2008


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
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC              http://www.holdenweb.com/




More information about the Python-list mailing list