Re: Query ID Values

From: tango ward <tangoward15(at)gmail(dot)com>
To: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Query ID Values
Date: 2018-05-15 05:22:06
Message-ID: CAA6wQLJ_rrzuE8KQVoEzbwXF9NcJMpvr9juOqjDVwVv7XHY4Ug@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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 SCHOOL HUMSS'
THEN 'Humanities and Social Sciences'
WHEN 'SENIOR HIGH SCHOOL STEM'
THEN 'Science, Technology, Engineering and
Mathematics'
ELSE %s
END
AND department_id
IN (SELECT id
FROM profile_department
WHERE school_id=1)
""", [course, course])

On Tue, May 15, 2018 at 1:11 PM, tango ward <tangoward15(at)gmail(dot)com> wrote:

> I thing its this:
>
> "
>
> Note
>
> cursor <http://initd.org/psycopg/docs/cursor.html#cursor> objects are
> iterable, so, instead of calling explicitly fetchone()
> <http://initd.org/psycopg/docs/cursor.html#cursor.fetchone> in a loop,
> the object itself can be used:
>
> >>> cur.execute("SELECT * FROM test;")>>> for record in cur:... print record...(1, 100, "abc'def")(2, None, 'dada')(3, 42, 'bar')
>
> Changed in version 2.4: iterating over a named cursor
> <http://initd.org/psycopg/docs/usage.html#server-side-cursors> fetches
> itersize <http://initd.org/psycopg/docs/cursor.html#cursor.itersize>
> records at time from the backend. Previously only one record was fetched
> per roundtrip, resulting in a large overhead.
> "
>
> On Tue, May 15, 2018 at 1:04 PM, Ian Zimmerman <itz(at)very(dot)loosely(dot)org>
> 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.org/psycopg/docs/cursor.html
>>
>> Where does that webpage say that I can use the cursor itself for
>> iteration? I can't find it there. (OTOH it is clearly documented for
>> the sqlite3 library).
>>
>> Until now, with psycopg2 I have done it like this:
>>
>> cur.execute(stmt)
>> results = iter(cur.fetchone, None)
>> for r in results:
>> ...
>>
>> --
>> Please don't Cc: me privately on mailing lists and Usenet,
>> if you also post the followup to the list or newsgroup.
>> To reply privately _only_ on Usenet and on broken lists
>> which rewrite From, fetch the TXT record for no-use.mooo.com.
>>
>>
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2018-05-15 05:23:01 Re: Query ID Values
Previous Message tango ward 2018-05-15 05:11:35 Re: Query ID Values