public inbox for [email protected]  
help / color / mirror / Atom feed
From: Hans Ginzel <[email protected]>
To: [email protected]
Subject: insert DEFAULT value
Date: Wed, 3 Mar 2021 22:51:37 +0100
Message-ID: <[email protected]> (raw)

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





view thread (4+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected]
  Subject: Re: insert DEFAULT value
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox