From: Timothy S. <ti...@op...> - 2004-11-04 09:43:15
|
ok i get that but it is still giving me problems. the error i get is libpq.OperationalError: ERROR: column "groupmembership" does not exist but it DOES exisit? there must be some syntax error i'm making. pyPgSQL has bearly any real documentation so these errors are easy to make.... #Get groups which this user belongs to cur.execute("SELECT UserGroup FROM UserMenuInfo WHERE UserName = UserName") Groups = cur.fetchone() GroupMembership = Groups[0] *snip* #Get menu items which this user has access to cur.execute("SELECT MenuName FROM MenuItems WHERE UserGroup = GroupMembership") Gerhard Haering wrote: >On Thu, Nov 04, 2004 at 04:26:26PM +1000, Timothy Smith wrote: > > >>Hello, when i use fetch all i have a problem with what s returned. >>everything is returned as this string ['data'] which makes is very >>inconvienent to work it. is there better way of fetching things then >>i am using? here is my code >> >>cur = db.cursor() >>cur.execute("SELECT UserGroup FROM UserMenuInfo WHERE UserName = UserName") >>groups = cur.fetchone() >> >> > >The DB-API requires that the return value of the fetchXX methods is a >sequence. So even if you only select one column, you still get a >sequence of length 1. > >To access the columns in the sequence, you can use index-based access: >groups[0]. This will work with all database adapters. > >Much more convenient, but not portable is pyPgSQL's extension to >access columns in the result row by name. Two ways to do this are >supported, dictionary-style and attribute-style: > >groups["UserGroup"] >groups.UserGroup > >HTH, > >-- Gerhard > > |