From: Gerhard H. <gh...@gh...> - 2004-11-04 10:23:06
|
On Thu, Nov 04, 2004 at 05:55:11PM +1000, Timothy Smith wrote: > ok i get that but it is still giving me problems. the error i get is > libpq.OperationalError: ERROR: column "groupmembership" does not exist >=20 > but it DOES exisit? there must be some syntax error i'm making. pyPgSQL= =20 > has bearly any real documentation so these errors are easy to make.... >=20 > #Get groups which this user belongs to > cur.execute("SELECT UserGroup FROM UserMenuInfo WHERE UserName =3D=20 > UserName") > Groups =3D cur.fetchone() > GroupMembership =3D Groups[0] >=20 > *snip* =20 > =20 > #Get menu items which this user has access to > cur.execute("SELECT MenuName FROM MenuItems WHERE UserGroup =3D=20 > GroupMembership") "WHERE UserGroup =3D GroupMembership" means you join two columns in SQL. To compare a column with a string, you use something like "WHERE UserGroup =3D 'Group1'", to compare it with a number "WHERE UserGroup =3D 42'. Now, it appears you want to parametrize your query. That's what the additio= nal parameter of .execute() is for: to give it a sequence of query parameters: cur.execute("SELECT Menuname FROM MenuItems WHERE UserGroup =3D %s", (Group= Membership,)) The placeholder in pyPgSQL is always %s. -- Gerhard --=20 A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet and in e-mail? |