Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: Cannot step through asynchronous iterator manually Date: Sun, 31 Jan 2016 08:19:42 +1100 Lines: 36 Message-ID: References: <56AD122F.2030904@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de /OSd/hXPxEbT6rMhPwkoLQODOUnsCd8UZrdMtgcMt8vQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'received:209.85.223': 0.03; 'counting': 0.07; 'table.': 0.07; 'api': 0.09; 'cc:addr :python-list': 0.09; 'fetch': 0.09; 'rows': 0.09; 'jan': 0.11; 'exception': 0.13; 'result.': 0.15; '2016': 0.16; 'efficiency.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'ignores': 0.16; 'query.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'returned,': 0.16; 'row': 0.16; 'succeeds,': 0.16; 'wrote:': 0.16; 'result,': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'algorithm': 0.20; '31,': 0.22; 'am,': 0.23; 'select': 0.23; 'second': 0.24; '(this': 0.24; 'header:In-Reply-To:1': 0.24; "doesn't": 0.26; 'error': 0.27; 'question': 0.27; 'message-id:@mail.gmail.com': 0.27; 'function': 0.28; 'actual': 0.28; 'fine': 0.28; 'raise': 0.29; 'you?': 0.30; 'query': 0.30; 'certain': 0.31; 'another': 0.32; 'run': 0.33; 'michael': 0.33; 'received:google.com': 0.35; 'could': 0.35; 'exist': 0.35; 'false': 0.35; 'something': 0.35; 'but': 0.36; 'there': 0.36; 'received:209.85': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'received:209': 0.38; 'anything': 0.38; 'test': 0.39; 'does': 0.39; 'where': 0.40; 'field': 0.60; 'matter': 0.63; 'is.': 0.63; 'more': 0.63; 'times': 0.63; 'statement,': 0.66; 'frank': 0.72; 'chrisa': 0.84; 'to:none': 0.91; 'results,': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=/pobmChgeJpeu+1CC3rGwXwGmnsTIa8XCI7qqK6we2w=; b=AO8KBpih1WvQw24ddlxamqn8n2mZhLocS5U9onr4DEL82/XRKgDTqPibVPWqZOi8yE UUJyWQBNjD8KBNfI635FdYSyD4Qfvzh4MKespWVE6FLoJFsLQYTti9Zc0U9ZvhSGZCs0 Zy7PNkDsiM+zI8JqIMuCYLqa9+GMkZhMguNnU+v1oxA6F8iKWomh+5Gc7aBzHzmt/ve0 ec6RfEEnxDeeCJL1mX0ewyvvKH6ZFB2ZI8uNtN5bUmbj09HHeHWjC7Hl2r17/V5hW4km fIkjNCzVScBO5DEhudM9D5rN6R9Pq9lvMRz2C0w1lvaUhCQu1JOiF57hQa0Qbi7DROKX u90A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc:content-type; bh=/pobmChgeJpeu+1CC3rGwXwGmnsTIa8XCI7qqK6we2w=; b=jDIEnWXB5lFyNeecILTAmFgG6HSbZC/ROKb20mhTeEs6hS72HGL/McEaijp+V8dVUn Nk/UZfHxiOzUsed/c5t5v2jozBSsZXSG9ZxPVW+vVX8MaoMAulyaNLOXYQp6jgvPcnKY bFXITPvmJL5enVRLJStWYhbZ59GUEtFLnm4fjTC9EHdxRTRaA6LHeHcw2ZAYkJvwsR2l dzPAlEWrYhG4njcfuPr7RtRGihB2KImQt0XkKAGXO5198qL592qoP8s+iQ1BC7bezqb/ L6RGILTG8iNq6ROEIkX5jxf0ua/tkNOJNqO71rrHt1g2ftCOAPFfHJNE16ikwMbAqECZ 3OBQ== X-Gm-Message-State: AG10YOScOzP8y49BvF1AmswiC/u0i8yPebGSDA6By72vVrExYIlIseuY1v0UT/fiYdL6I22yCMT3grnBnt4cGQ== X-Received: by 10.107.14.73 with SMTP id 70mr16217182ioo.31.1454188782853; Sat, 30 Jan 2016 13:19:42 -0800 (PST) In-Reply-To: <56AD122F.2030904@gmail.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:102311 On Sun, Jan 31, 2016 at 6:42 AM, Michael Torrie wrote: > On 01/30/2016 01:22 AM, Frank Millman wrote: >> There are times when I want to execute a SELECT statement, and test for >> three possibilities - >> - if no rows are returned, the object does not exist >> - if one row is returned, the object does exist >> - if more that one row is returned, raise an exception > > Is there a reason you cannot get SQL to answer this question for you? > Something like: > > SELECT count(some_field) WHERE condition > > That will always return one row, with one field that will either be 0, > 1, or more than 1. Efficiency. That's a fine way of counting actual rows in an actual table. However, it's massive overkill to perform an additional pre-query for something that's fundamentally an assertion (this is a single-row-fetch API like "select into", and it's an error to fetch anything other than a single row - but normal usage will never hit that error), and also, there's no guarantee that the query is looking at a single table. Plus, SQL's count function ignores NULLs, so you could get a false result. Using count(*) might be better, but the only way I can think of to be certain would be something like: select count(*) from (...) where the ... is the full original query. In other words, the whole query has to be run twice - once to assert that there's exactly one result, and then a second time to get that result. The existing algorithm ("try to fetch a row - if it fails error; then try to fetch another - if it succeeds, error") doesn't need to fetch more than two results, no matter how big the query result is. ChrisA