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 1mXie7-0000kN-S7 for psycopg@arkaria.postgresql.org; Tue, 05 Oct 2021 11:30:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mXie6-0006fl-PE for psycopg@arkaria.postgresql.org; Tue, 05 Oct 2021 11:30:06 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mXie6-0006fb-3A for psycopg@lists.postgresql.org; Tue, 05 Oct 2021 11:30:06 +0000 Received: from bumble.birch.relay.mailchannels.net ([23.83.209.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mXie1-0001fr-Gu for psycopg@postgresql.org; Tue, 05 Oct 2021 11:30:05 +0000 X-Sender-Id: cp7oy65bvo|x-authuser|paolo@paolodestefani.it Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id C404222557 for ; Tue, 5 Oct 2021 11:29:55 +0000 (UTC) Received: from lu-shared04.cpanelplatform.com (100-96-18-141.trex.outbound.svc.cluster.local [100.96.18.141]) (Authenticated sender: cp7oy65bvo) by relay.mailchannels.net (Postfix) with ESMTPA id EBFE4220A7 for ; Tue, 5 Oct 2021 11:29:54 +0000 (UTC) X-Sender-Id: cp7oy65bvo|x-authuser|paolo@paolodestefani.it Received: from lu-shared04.cpanelplatform.com ([UNAVAILABLE]. [107.189.4.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.96.18.141 (trex/6.4.3); Tue, 05 Oct 2021 11:29:55 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: cp7oy65bvo|x-authuser|paolo@paolodestefani.it X-MailChannels-Auth-Id: cp7oy65bvo X-Celery-Power: 151411f5610c2b2c_1633433395515_3492638733 X-MC-Loop-Signature: 1633433395515:3496633755 X-MC-Ingress-Time: 1633433395515 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=paolodestefani.it; s=default; h=Content-Transfer-Encoding:Content-Type: Message-ID:Subject:To:From:Date:MIME-Version:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=G5gEKA00DKCadb+svZkARhMInA6+65QhWy4QTuj6oDg=; b=LGqw4foOL9AfoqFc8I7Ul3MeOP evWXzD0N9cCT2MgVxX8gLFeweONAYzC0r8OjdJF++cidl2S+14/fNE9EDCGKRU/R5br1zcRroSgcr ZxxDt/O6sYbZ2ABJvlWBIRfb/eTq5Yq/o/V7Vd6dFVNB5eJIJpz+32nrDKVkAgveLnlQW3FD9sKWZ tCLbGuMjYIETxEYCRJnZqOXBaZY2mKxaTBvxW33ZYBH+e3vN67FWgmtX0FygCwFGr7pwzUAUsQu40 QixVLyYOvXnzjGPFGxnvXNNwAzpqn8LBqRv6HLxwHYH+l21j5yeV/BMvSTqcvTQaK0rTYKTvYwBvU +BWgMKaA==; Received: from [::1] (port=33878 helo=lu-shared04.cpanelplatform.com) by lu-shared04.cpanelplatform.com with esmtpa (Exim 4.94.2) (envelope-from ) id 1mXids-00GtDs-LL for psycopg@postgresql.org; Tue, 05 Oct 2021 13:29:52 +0200 MIME-Version: 1.0 Date: Tue, 05 Oct 2021 13:29:52 +0200 From: Paolo De Stefani To: Psycopg Subject: From spycopg2 to psycopg3 data adaptation User-Agent: Roundcube Webmail/1.4.11 Message-ID: <4c05fd7ddf571bfc82baeede1449f7f0@paolodestefani.it> X-Sender: paolo@paolodestefani.it Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit X-AuthUser: paolo@paolodestefani.it List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Still working on migration to psycopg3 of my (not so) small application... I use PyQt\PySide for user interface and i convert some postgresql data types to Qt types. For example to convert timestamptz to QDateTime in psycopg2 i use: def cast_timestamp_qdatetime(value, cur): if value is None: return None dt = QDateTime.fromString(value[:23], "yyyy-MM-dd HH:mm:ss.zzz") if not dt.isValid(): # no milliseconds dt = QDateTime.fromString(value[:19], "yyyy-MM-dd HH:mm:ss") return dt QDATETIME = psycopg2.extensions.new_type((1184,), "QDATETIME", cast_timestamp_qdatetime) psycopg2.extensions.register_type(QDATETIME) I tryed this to achieve the same result in psycopg3: class TimestamptzQDateTimeLoader(Loader): def load(self, value): if value is None: return None print(value) dt = QDateTime.fromString(value[:23], "yyyy-MM-dd HH:mm:ss.zzz") if not dt.isValid(): # no milliseconds dt = QDateTime.fromString(value[:19], "yyyy-MM-dd HH:mm:ss") return dt psycopg.adapters.register_loader('timestamptz', TimestamptzQDateTimeLoader) BUT it's not working because the "value" is binary not string: So how i can get the same result of psycopg2 in psycopg3 ? -- Paolo De Stefani