Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jJPzp-0000Hw-5U for psycopg@arkaria.postgresql.org; Tue, 31 Mar 2020 23:08:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jJPzm-0002PY-3X for psycopg@arkaria.postgresql.org; Tue, 31 Mar 2020 23:08:34 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jJPzl-0002PH-Re for psycopg@lists.postgresql.org; Tue, 31 Mar 2020 23:08:33 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jJPzj-0006QY-G0 for psycopg@postgresql.org; Tue, 31 Mar 2020 23:08:32 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id A650F5C023D; Tue, 31 Mar 2020 19:08:30 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Tue, 31 Mar 2020 19:08:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:from:to:references:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm2; bh=I eGcyWQywGn7D1/S7twh6ksMXz0axPXaugSjtW255wU=; b=lEMdSnSL3v2lnxPSD g9kx+umJWjZ8q6lrCRIXrH6OGcfFfmOZwf2MuMdKEoQIBz+ZqRGmh1A47QPyky3K uUR9m+vu79sPUS1ReKvLIzJUd+PfbTC8trNBircUGw2kKNpjcwO61YZEm5BqFn3i Z3iAMtOt7TWM0Gfymtae87G5G8uIAs6N+RAzohxnx4B6LBSqtC24TCe1UhHzLBTA wVbBxzqfEjG7qj2QUiblqgrgxGRzvvvjGii6foOUlg2bHx76hlnNeOahYFgOR2I9 vXftY6ITwfDTVcSPnnOR6+GoCbbH2aCHN0YmmzKN8j9M2jC5BGhoOplvAU2pyE+9 AoFdA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=IeGcyWQywGn7D1/S7twh6ksMXz0axPXaugSjtW255 wU=; b=paQGDR0iXXY3gms6gz7CS2DGh4OseSXrJrC5+6Hi3LIgVgURehnkA+rsE 86Aau/Hl73pVQ4LOgxdur0vc0lxO0ZOh/T3DMaVjcmJHmZJsjye0l/iHS/f0pGtR Y2hhM0pPbR7U+hDuf4AtiBDVPtKUB+fLLe/HCZGgyrW/PFhpQxInLVCR38LFKG4d CuSdShjLm//DMgLAWTG/LN/KrXvlhS/0JbEJ+e+ImFP8PnJu9FdCnnV/jETx6iUN eICHyM+b80E3ubyRaX+/tg6tWkLFrYSxIBU1MdvKBUDgaA4+dbygxoIRm5el/4GI 8guQL8EwwQgbNBpV9zgMBWujzGh0Q== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrtddtgddugeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffhvfhfkffffgggjggtgfesthekredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgnecukfhppeejhedrudej vddrledtrdelvdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfh hrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Received: from [192.168.1.10] (75-172-90-92.tukw.qwest.net [75.172.90.92]) by mail.messagingengine.com (Postfix) with ESMTPA id 11A873280059; Tue, 31 Mar 2020 19:08:29 -0400 (EDT) Subject: Re: Inserting default values into execute_values From: Adrian Klaver To: Stephen Lagree , psycopg@postgresql.org References: <6db34cfa-c531-18ff-4368-bea8c171f6db@aklaver.com> Message-ID: <3cdc3522-f09a-529a-e329-b50418fb4172@aklaver.com> Date: Tue, 31 Mar 2020 16:08:29 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: <6db34cfa-c531-18ff-4368-bea8c171f6db@aklaver.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 3/31/20 3:57 PM, Adrian Klaver wrote: > On 3/31/20 3:27 PM, Stephen Lagree wrote: >> Hello, >> >> I am trying to insert into a table to generate sequential ids.  Is >> there a way to do this repeatedly using execute_values if there is >> only one column and it is auto incremented? >> It seems the execute_values requires at least one non-default value. >> >> I am trying to do this: >>      query = "INSERT INTO MYTABLE (id) VALUES (DEFAULT) RETURNING id;" >>      execute_values(cursor, query, args_list, template=None, >> page_size=100, fetch=True) >> >> If I don't use a %s argument and just put dummy values in the arglist, >> I get error >> E           ValueError: the query doesn't contain any '%s' placeholder >> I understand why this doesn't work because it can't extract the >> placeholder and replicate values there. >> >> If I change DEFAULT to %s and try to use blank tuples I get this >> E           psycopg2.errors.SyntaxError: syntax error at or near ")" >> E           LINE 1: INSERT INTO MYTABLE (id) VALUES (),(),() RETURNING >> id; >> >> If I use "DEFAULT" as a string it tries to insert a string into an int >> column, not use the DEFAULT value.  Is there a way to insert the >> default value here?  I don't see anything like this in the documentation. >> >> My table looks like this: >> "CREATE TABLE MYTABLE (id SERIAL PRIMARY KEY)" > > > A solution from Daniele Varrazzo.  I can't find the mailing list post > where it appeared, just where I use it in code: > I was searching the wrong list it is in the pgsql-general list: https://www.postgresql.org/message-id/CA%2Bmi_8ZQx-vMm6PMAw72a0sRATEh3RBXu5rwHHhNNpQk0YHwQg%40mail.gmail.com -- Adrian Klaver adrian.klaver@aklaver.com