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 1pOAMU-0006zT-Du for pgsql-general@arkaria.postgresql.org; Sat, 04 Feb 2023 04:41:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pOAMT-0001oX-7j for pgsql-general@arkaria.postgresql.org; Sat, 04 Feb 2023 04:41:13 +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 1pOAMS-0001m1-Qr for pgsql-general@lists.postgresql.org; Sat, 04 Feb 2023 04:41:12 +0000 Received: from mail-oa1-x36.google.com ([2001:4860:4864:20::36]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pOAMP-00048z-Pj for pgsql-general@lists.postgresql.org; Sat, 04 Feb 2023 04:41:12 +0000 Received: by mail-oa1-x36.google.com with SMTP id 586e51a60fabf-142b72a728fso9011684fac.9 for ; Fri, 03 Feb 2023 20:41:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=ISSe1Z1pk/GkqQC1GYfH9ZQN0L+FfYrk7xotV1ol0yY=; b=TxYSnCu5cyCWWBzz1MzQzY+ST3XuP8xACHSthQxfI9L4gUT2fHcTufa78vntqbZv0D N1qBWGKgxTbx0YiUHMchTUTNbmAwOFqO0A7yCaQB3/N3ICEyu3GRDyaqnik3jSiFB3va X6u8mzC/XysWo+NF6fDY/tdVqb1YBwAQkvB9HW6AAWA4KiCiu8AgFpp95SiisfO/K34Z dkY0jFZQw/W6OIzFsr2S0CG1dyG5nfdg5o0Yie1s1l3RBHuZtuC/gBh5sAXWrMrceuMr cyj0uSNd3ImiaTwA3EYCyVI9AMfLOUQcFDxJoYUlCEQMQjhrQRxQjOxH+zW5YhXkexrc SICQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=ISSe1Z1pk/GkqQC1GYfH9ZQN0L+FfYrk7xotV1ol0yY=; b=vU/tH0SpfJCxtkvuz/QPk+5jsKmB4UcuyKiUetEgd53CFHg9rXt8c5UrwvU3gkWIO9 3CNx3Sch9OCRloBo8k5X5Bisnvt7qWA9aKSXJQP26HL98BzKDqBQUXb/fpRmMEolIsL0 QhI+0Jv151VIb0I5HBCqCL1GCgviJ80M4ubObktWrKq4HZdYAkk8CORwumdgECj7A62x gy4j4ezX9Izb5UVx8LIBMc+H5lia8JMK6EHHwyMYGEhsmeZjQt0vl3NxaebSHfWU4dwu 4iL+8h0PFYdgL6ToEIi8J0CVGfPAr0G4gw7rQRbdzIHKNBRHCRHX3JzHbDfcEn6qXVH0 M35w== X-Gm-Message-State: AO0yUKUwTk63hEV5RiVRGgfwMOz1CmdMLy1fE/hhOkMyBTbs/Pdaxjop 60WFcBbhe/fsYLt68odYyTZDCiwDrHQ= X-Google-Smtp-Source: AK7set8rVt2P21Kd+R0crfpQi08/kApBBjNX9F5F8qw7GKDvDCAUGan84xAa7yABfVqfanlNdBvehw== X-Received: by 2002:a05:6871:8aa:b0:15f:420:d7f6 with SMTP id r42-20020a05687108aa00b0015f0420d7f6mr7290901oaq.23.1675485667652; Fri, 03 Feb 2023 20:41:07 -0800 (PST) Received: from ?IPV6:2600:1700:bd2c:b810::43? ([2600:1700:bd2c:b810::43]) by smtp.googlemail.com with ESMTPSA id r6-20020a056830448600b00688449397d3sm1986703otv.15.2023.02.03.20.41.06 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 03 Feb 2023 20:41:06 -0800 (PST) Content-Type: multipart/alternative; boundary="------------QaqvecOWbxfr2XaMMVdvfpEd" Message-ID: <0400e92f-0d77-4276-be50-6e16321f4ae0@gmail.com> Date: Fri, 3 Feb 2023 22:41:06 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: Switching identity column to serial Content-Language: en-US To: pgsql-general@lists.postgresql.org References: <1828022907.15226.1675472079824@office.mailbox.org> From: Ron In-Reply-To: <1828022907.15226.1675472079824@office.mailbox.org> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------QaqvecOWbxfr2XaMMVdvfpEd Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2/3/23 18:54, Erik Wienhold wrote: > I was wondering if it's possible to drop a column identity (not the column > itself) while keeping the attached sequence. This would avoid recreating > an identical sequence (especially with a correct start value and owner). Why doesn't this work? BEGIN; DROP SEQUENCE t_id; CREATE SEQUENCE new_t_id_seq AS INTEGER OWNED BY t.id; ALTER SEQUENCE new_t_id_seq OWNER TO new_owner; SELECT setval('new_t_id', (SELECT MAX(id) FROM t)); SELECT nextval('new_t_id'); COMMIT; > Changing the sequence owner to NONE before dropping identity is not allowed. > Also changing pg_class.relowner to some role did not help. The sequence is > still dropped together with the column identity. Manually diigging around the system catalog is /never/ recommended. -- Born in Arizona, moved to Babylonia. --------------QaqvecOWbxfr2XaMMVdvfpEd Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit On 2/3/23 18:54, Erik Wienhold wrote:
I was wondering if it's possible to drop a column identity (not the column
itself) while keeping the attached sequence.  This would avoid recreating
an identical sequence (especially with a correct start value and owner).

Why doesn't this work?
BEGIN;
DROP SEQUENCE t_id;
CREATE SEQUENCE new_t_id_seq AS INTEGER OWNED BY t.id;
ALTER SEQUENCE new_t_id_seq OWNER TO new_owner;
SELECT setval('new_t_id', (SELECT MAX(id) FROM t));
SELECT nextval('new_t_id');
COMMIT;

Changing the sequence owner to NONE before dropping identity is not allowed.
Also changing pg_class.relowner to some role did not help.  The sequence is
still dropped together with the column identity.

Manually diigging around the system catalog is never recommended.

--
Born in Arizona, moved to Babylonia.
--------------QaqvecOWbxfr2XaMMVdvfpEd--