Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'case.': 0.05; 'mysql,': 0.07; 'fetch': 0.09; 'inserted': 0.09; 'newly': 0.09; 'record.': 0.09; '"insert': 0.16; '(%s,': 0.16; '24,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'simplest': 0.16; 'wrote:': 0.17; 'thu,': 0.17; 'jan': 0.18; 'insert': 0.23; 'nearly': 0.23; 'header:In-Reply-To:1': 0.25; 'common': 0.26; 'select': 0.26; 'values': 0.26; 'message- id:@mail.gmail.com': 0.27; 'key,': 0.29; 'primary': 0.30; 'could': 0.32; 'to:addr:python-list': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'returning': 0.35; 'doing': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'but': 0.36; 'should': 0.36; 'execute': 0.37; 'received:209': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'supports': 0.38; 'page': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; 'most': 0.61; 'covers': 0.65; 'pin': 0.65; '2013': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=A7eG79v2L2boZO3ev9G7u83EyZdCRnxo1Gnrba1GCKk=; b=Qu+/Vi3+Qj8QUmuKoq36JjRJL1BHWgHOp1TFKN1pUackVOgd1r+T+Ac1HVo8wMs2yT 7i/ZD77nwiaz+L7jRCrFvqfFNMpU/lyrAkDEWNOM+qkj6c0NpLyEYPtxVOwcpH94YUMf pOes+45qD1og/lEeIPv9NERCBPJKweAnL5bIZqUK1rbccbeFPi+YqSuDZsmTww3bG7wn 5WnqvVlxk6u6vef+/NslhX2eBm+vbsH0/ZFxT+cv2+OH9kEFOqHbqqcw1iiVdqLEuLix JyvXgM2rCqc2hsSAjCb7C5r93kn6MW9RtQhCcJbwC0ulf82Oio6zUoRgYfXxd3yMYZ+Z gzWg== MIME-Version: 1.0 X-Received: by 10.68.234.229 with SMTP id uh5mr3810383pbc.123.1359026945987; Thu, 24 Jan 2013 03:29:05 -0800 (PST) In-Reply-To: <87pq0u961r.fsf@metapensiero.it> References: <88306c73-dfa2-44e1-ab0c-d90dba05be1c@googlegroups.com> <87pq0u961r.fsf@metapensiero.it> Date: Thu, 24 Jan 2013 22:29:05 +1100 Subject: Re: mysql solution From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 18 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1359026954 news.xs4all.nl 6953 [2001:888:2000:d::a6]:33706 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:37567 On Thu, Jan 24, 2013 at 10:25 PM, Lele Gaifax wrote: > The simplest way is to execute a SELECT just after the insertion, doing > a > > SELECT pin FROM counters WHERE page = %s > > I don't use MySQL, so I can't say if it supports "INSERT ... RETURNING ..." > SQL syntax: should it, then you could insert the data and fetch > the pin in one shot, with something like > > INSERT INTO counters (page, hits) VALUES (%s, %s) RETURNING (pin) AFAIK it doesn't, but if pin is an AUTO_INCREMENT primary key, you can retrieve the ID of the newly inserted record. It's not nearly as flexible as INSERT... RETURNING, but it covers the most common use case. ChrisA