Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u72WK-009O66-Ag for pgsql-general@arkaria.postgresql.org; Tue, 22 Apr 2025 01:33:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1u72WI-00A2Qh-EX for pgsql-general@arkaria.postgresql.org; Tue, 22 Apr 2025 01:33:55 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u72WI-00A2QY-2N for pgsql-general@lists.postgresql.org; Tue, 22 Apr 2025 01:33:54 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1u72WD-001K3n-1g for pgsql-general@lists.postgresql.org; Tue, 22 Apr 2025 01:33:54 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 53M1Xkxo878367; Mon, 21 Apr 2025 21:33:46 -0400 From: Tom Lane To: Marcelo Fernandes cc: pgsql-general@lists.postgresql.org Subject: Re: pg_get_serial_sequence not working for manually set seq In-reply-to: References: Comments: In-reply-to Marcelo Fernandes message dated "Tue, 22 Apr 2025 13:22:50 +1200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <878365.1745285626.1@sss.pgh.pa.us> Date: Mon, 21 Apr 2025 21:33:46 -0400 Message-ID: <878366.1745285626@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Marcelo Fernandes writes: > I've been testing the pg_get_serial_sequence function and noticed that I can > only get reliable results when using a SERIAL or IDENTITY column. > However, shouldn't it work for manually set sequences too? pg_get_serial_sequence looks for pg_depend entries that make sequences depend on columns, so no you won't get it to work that way. You could use ALTER SEQUENCE OWNED BY to establish the dependency link, if you are intent on reimplementing SERIAL by hand. See the documentation about what SERIAL does: https://www.postgresql.org/docs/current/datatype-numeric.html#DATATYPE-SERIAL regards, tom lane