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 1jJPLx-0005Q5-TI for psycopg@arkaria.postgresql.org; Tue, 31 Mar 2020 22:27:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jJPLw-0002Gv-Oi for psycopg@arkaria.postgresql.org; Tue, 31 Mar 2020 22:27:24 +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 1jJPLw-0002Gm-GF for psycopg@lists.postgresql.org; Tue, 31 Mar 2020 22:27:24 +0000 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jJPLq-0005zv-76 for psycopg@postgresql.org; Tue, 31 Mar 2020 22:27:23 +0000 Received: by mail-lf1-x129.google.com with SMTP id e7so18751222lfq.1 for ; Tue, 31 Mar 2020 15:27:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=E5HYe0FOsIut4zMhG1KXLCCPpD858qBU4gtBRWp8yOA=; b=fKH44qgZ7hBFK/1xfAcv1QhKtJYcC3CABeCy4fhmJRH7pG+SByYmPGP/PIrgsILCoC 8QabnZs5enTuVw7xii1ijNEYWQzWdOwvq+H+z7EyoHnJ9WIkEGwQkS2udZfOIvu2p2Pj Kxd/sRAsnHIoLcFH40RLa0ZMqUbZ0L9F5KNepblOqjjwOKfp90wKs4gh7ChGhOsVhhP2 270VUj+b5XVM4wVqKkLdollUWt+LazGtCqOcVxDfRQhFpeKk60hOT/HR47aTJQpczOxa cZNcue6gmrwMmnW9KiDMLuJFUak3Ghh3+wLY2Zk8OMDL+wIBDKyip4PN/YvS8h0V87Kj ALZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=E5HYe0FOsIut4zMhG1KXLCCPpD858qBU4gtBRWp8yOA=; b=eY2lTdZv9vDwGWkcrmbrVRFMRynXZ+XqPj3LUYvVz0vG8ZX99E4VZIYaT31GpL3Tbf IhrsMP/8cWWOGTyUTWlvPimd6CHo8MqPHTCYtiv0R9fQ5HZaWDYWBkTEW1AFOjghGLEr EfvTxOc2OdGBkFuz3yle2k3qJEL4qHatAEudb1ABzLVa8ku66v/HQ9vfMOXKJAXpuofW 3EIynbGvVOEavAQ0r3GVf6Zet3T6d1v/g2yOabIqvxX3ZmImy31QjfRyOufThGMJBKcF /nCvopSPrF39ZPYN+7OimZZSSk0DrwggmEQzP28JbBB33wR/AmPivXKZhD8hpmn0pqhp VnTg== X-Gm-Message-State: AGi0PuahnKRyYiTcvt8nE+hWnOtF3wrsle9+38CgoUSkmvd5Q1haTUdh /bP2M6O5VSg0fuqGrIx74EVJG4pmzodLbIpbauTZL/i0BxM= X-Google-Smtp-Source: APiQypI5kGmx//z3smri2h9w4KvOi8zO6QMcMTm1hV5uxqKFlnNgSPPIvwU2A0H00AHVX/zeh2XRN9OnOWxxf2L9/dI= X-Received: by 2002:a05:6512:686:: with SMTP id t6mr885483lfe.163.1585693636189; Tue, 31 Mar 2020 15:27:16 -0700 (PDT) MIME-Version: 1.0 From: Stephen Lagree Date: Tue, 31 Mar 2020 15:27:05 -0700 Message-ID: Subject: Inserting default values into execute_values To: psycopg@postgresql.org Content-Type: multipart/alternative; boundary="000000000000e8633505a22e1178" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --000000000000e8633505a22e1178 Content-Type: text/plain; charset="UTF-8" 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)" Thanks, Steve --000000000000e8633505a22e1178 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello,

I am trying to insert into a tab= le to generate sequential ids.=C2=A0 Is there a way to do this repeatedly u= sing execute_values if there is only one column and it is auto incremented?= =C2=A0=C2=A0
It seems the execute_values requires at least one no= n-default value.

I am trying to do this:
=C2=A0 =C2=A0 query =3D "INSERT INTO MYTABLE (id) VALUES (DEFAULT) RE= TURNING id;"
=C2=A0 =C2=A0 execute_values(cursor, query,= args_list, template=3DNone, page_size=3D100, fetch=3DTrue)

<= /div>
If I don't use a %s argument and just put dummy values in the= arglist, I get error
E =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ValueE= rror: the query doesn't contain any '%s' placeholder
<= div>I understand why this doesn't work because it can't extract the= placeholder and replicate values there.

If I chan= ge DEFAULT to %s and try to use blank tuples I get this
E =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 psycopg2.errors.SyntaxError: syntax error a= t or near ")"
E =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 LINE 1: INS= ERT 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.=C2=A0 Is there a way to inse= rt the default value here?=C2=A0 I don't see anything like this in the = documentation.

My table looks like this:
"CREATE TABLE MYTABLE (id SERIAL PRIMARY KEY)"
Thanks,
Steve
--000000000000e8633505a22e1178--