Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #37567

Re: mysql solution

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 <rosuav@gmail.com>
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 <rosuav@gmail.com>
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.966.1359026954.2939.python-list@python.org> (permalink)
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

Show key headers only | View raw


On Thu, Jan 24, 2013 at 10:25 PM, Lele Gaifax <lele@metapensiero.it> 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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

mysql solution Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-24 03:04 -0800
  Re: mysql solution Chris Angelico <rosuav@gmail.com> - 2013-01-24 22:16 +1100
    Re: mysql solution Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-24 05:31 -0800
      Re: mysql solution Chris Angelico <rosuav@gmail.com> - 2013-01-25 01:46 +1100
    Re: mysql solution Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-24 05:31 -0800
  Re: mysql solution Lele Gaifax <lele@metapensiero.it> - 2013-01-24 12:25 +0100
    Re: mysql solution Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-24 04:01 -0800
      Re: mysql solution Lele Gaifax <lele@metapensiero.it> - 2013-01-24 13:22 +0100
        Re: mysql solution Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-24 05:24 -0800
          Re: mysql solution Lele Gaifax <lele@metapensiero.it> - 2013-01-24 14:37 +0100
            Re: mysql solution Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-24 06:35 -0800
            Re: mysql solution Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-24 06:35 -0800
              Re: mysql solution Duncan Booth <duncan.booth@invalid.invalid> - 2013-01-24 15:19 +0000
                Re: mysql solution Chris Angelico <rosuav@gmail.com> - 2013-01-25 02:27 +1100
                Re: mysql solution Lele Gaifax <lele@metapensiero.it> - 2013-01-24 16:39 +0100
                Re: mysql solution Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-24 10:22 -0800
                Re: mysql solution Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-24 10:22 -0800
        Re: mysql solution Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-24 05:24 -0800
    Re: mysql solution Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-24 04:01 -0800
  Re: mysql solution Chris Angelico <rosuav@gmail.com> - 2013-01-24 22:29 +1100
  Re: mysql solution Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-01-24 15:43 -0500
    Re: mysql solution Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-25 07:43 -0800
      Re: mysql solution Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-01-25 16:56 -0500
        Re: mysql solution Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-26 02:35 -0800
        Re: mysql solution Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-26 02:35 -0800
    Re: mysql solution Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-25 07:43 -0800

csiph-web