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 1lHZPM-0005TR-Ef for psycopg@arkaria.postgresql.org; Wed, 03 Mar 2021 21:51:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lHZPL-00077H-Dy for psycopg@arkaria.postgresql.org; Wed, 03 Mar 2021 21:51:51 +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 1lHZPL-00077A-8P for psycopg@lists.postgresql.org; Wed, 03 Mar 2021 21:51:51 +0000 Received: from postak.karlin.mff.cuni.cz ([195.113.30.11]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lHZPD-0005Ck-7Y for psycopg@postgresql.org; Wed, 03 Mar 2021 21:51:49 +0000 Received: from artax.karlin.mff.cuni.cz (artax.karlin.mff.cuni.cz [195.113.26.195]) by postak.karlin.mff.cuni.cz (Postfix) with ESMTPS id 6617320272 for ; Wed, 3 Mar 2021 22:51:37 +0100 (CET) Received: by artax.karlin.mff.cuni.cz (Postfix, from userid 1975) id 4C2A1828001; Wed, 3 Mar 2021 22:51:37 +0100 (CET) Date: Wed, 3 Mar 2021 22:51:37 +0100 From: Hans Ginzel To: psycopg@postgresql.org Subject: insert DEFAULT value Message-ID: <20210303215137.GI11758@artax.karlin.mff.cuni.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk How to insert DEFAULT value, please? import psycopg2 from psycopg2.sql import DEFAULT # https://www.postgresql-archive.org/Inserting-default-values-into-execute-values-td6130148.html db = psycopg2.connect(host='host', dbname='db') cursor = db.cursor() cursor.execute("DROP TABLE IF EXISTS test_default") cursor.execute("CREATE TABLE test_default(i int NOT NULL DEFAULT 1)") cursor.execute("INSERT INTO test_default VALUES (%s)", (DEFAULT,)) cursor.execute("DROP TABLE IF EXISTS test_default") cursor.execute("CREATE TABLE test_default(j jsonb NOT NULL DEFAULT '{}'::jsonb)") cursor.execute("INSERT INTO test_default VALUES (%s)", (DEFAULT,)) For both cases I get psycopg2.ProgrammingError: can't adapt type 'SQL' Thank you in advance, HG