Re: Query ID Values

2018-05-15 Thread Adrian Klaver
On 05/14/2018 10:04 PM, Ian Zimmerman wrote: On 2018-05-14 21:12, Adrian Klaver wrote: Because you are doing fetchall(). That is going to fetch a list of row tuples. Either iterate over that list or iterate over the cursor: for row in cur_p: print(row) For more info see: http://initd

Re: Query ID Values

2018-05-14 Thread David G. Johnston
I'd bottom-post, as is the convention for these lists, but it seems pointless now... CASE *expression* WHEN *value* THEN *result* [WHEN ...] [ELSE *result*] END Try that where expression is the %s. The values and results are simple literals. And you compare the result of the express

Re: Query ID Values

2018-05-14 Thread tango ward
Fixed the case statement SELECT id FROM education_program WHERE name = CASE %s WHEN 'SENIOR HIGH SCHOOL GAS' THEN 'General Academic Strand' WHEN 'SENIOR HIGH SCHO

Re: Query ID Values

2018-05-14 Thread tango ward
I thing its this: " Note cursor objects are iterable, so, instead of calling explicitly fetchone() in a loop, the object itself can be used: >>> cur.execute("SELECT * FROM test;")>>> f

Re: Query ID Values

2018-05-14 Thread Ian Zimmerman
On 2018-05-14 21:12, Adrian Klaver wrote: > Because you are doing fetchall(). That is going to fetch a list of row > tuples. Either iterate over that list or iterate over the cursor: > > for row in cur_p: > print(row) > > For more info see: > http://initd.org/psycopg/docs/cursor.html Whe

Re: Query ID Values

2018-05-14 Thread tango ward
Noted Sir Adrian. The course name for the ones that are blank are not match with the ones in the profile_program table. I am writing a CASE Statement right now to verify the data but I can't make it work.: for row in cur_t: course = row['course'] cur_p.execute("""

Re: Query ID Values

2018-05-14 Thread Adrian Klaver
On 05/14/2018 08:30 PM, tango ward wrote: for row in cur_t:     course = row['course']     cur_p.execute("""   SELECT id   FROM education_program   WHERE name=%s   AND department_id

Re: Query ID Values

2018-05-14 Thread tango ward
for row in cur_t: course = row['course'] cur_p.execute(""" SELECT id FROM education_program WHERE name=%s AND department_id IN (SELECT id FROM profile_de

Re: Query ID Values

2018-05-14 Thread tango ward
Hi, Yes sorry, here's the tables: [cur_t DB] [student_profile table] Column| Type | Collation | Nullable |Default| --++---+--+---+ studentnumber| character

Re: Query ID Values

2018-05-14 Thread David G. Johnston
On Monday, May 14, 2018, tango ward wrote: > > May I ask an advice on how to approach this? > I can't make heads nor tails of your description...but there isn't IF in SQL. But you may get some mileage out of simple joins. David J.