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 1lwOlN-0000wg-M5 for pgsql-general@arkaria.postgresql.org; Thu, 24 Jun 2021 12:47:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lwOlM-0003Jz-MY for pgsql-general@arkaria.postgresql.org; Thu, 24 Jun 2021 12:47:20 +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 1lwOlM-0003Jm-77 for pgsql-general@lists.postgresql.org; Thu, 24 Jun 2021 12:47:20 +0000 Received: from mail-qv1-xf2a.google.com ([2607:f8b0:4864:20::f2a]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lwOlJ-00017e-DG for pgsql-general@lists.postgresql.org; Thu, 24 Jun 2021 12:47:19 +0000 Received: by mail-qv1-xf2a.google.com with SMTP id h10so3198413qvz.2 for ; Thu, 24 Jun 2021 05:47:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joeconway.com; s=google; h=to:references:from:subject:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=mRRZOGGtF/Zxrk6fnxyycmaCDR3IRonlCJt7lqkFItk=; b=ohBfaKjaFvn/pO5RykTIX+Eqz4PtuH9qpR3bIxxf609+eBPeWCrZtb24aTXgECsBPp mlW8n9S8Lkl3yBJbxfc6MvBrHdZ5SLN7yYBbVUfIxwEeOJb4Kue/roAMHVa3IY8cfRl5 Q252swPpHQVa6FwIktKNzCv1MTtamA/XsGwlnX7M/squ1DkUYnNO8UdvYpfLQkwsOYd8 dKvJ4lTlWwdusgpfP8HVx/aqW9NTWfFp9GlK6Edq4hOzgNcw7sCY+uH7ydrf0cvOpned 3hu+VWuFZM2UCYm+gCwIwuEEchbHJa6xuoTBXLfG3yiA5AOtwFnBgzcQLtx7bU/U0STc 0FGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:references:from:subject:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=mRRZOGGtF/Zxrk6fnxyycmaCDR3IRonlCJt7lqkFItk=; b=R+HpKq1/drnFkl1KgfYehGV/+T2CCpvkMrRFspe/2NrL5VmwdkNzEzqC7NIGDoxrEQ er5OVUHuQ1mgzsRJ7m+8BpEoZzT72IVC24sA5NkLNCICDpwewfcTfbR4+ENDw8GH2l8D s5a4kn0GSMHUqCCzLgkFLYn/Ejqk/NZ0iRzasdg7h+4RVfeBqcu8gg9KJjU1oCYjKbIq ksODe+7BiyY8Bl0yZSBU6eYdpAXfV4hu1MoYcW+z6bOhAlYfz7b2UCeffqP7lhSAcu8a 6joGVhprx6T7ssRxv61BYAz9y2rG0P+vibN52Wcmlbfi8Jj0OhaAENNlUfLYFr0CUQOi 0QAQ== X-Gm-Message-State: AOAM531i79raBVbpcgqfGXC9Y5ThMejXWNZ0tsCSJL+ppEqQmyVngGsH rQS4dJFfpXNLidvk+KzReo81fdpF4OTOuPyQgNL396VxNXGKWk0p2gL3ijxDY3Iwd/igXMlRlym yHIoLPYU6mao2SOZxwLmFBSqf1/7Nz1fu9eY//ik9UYf37rvQBtHs6EjULsZTA6+YMhEbwFpLPv F1yr1ra+XWqCk= X-Google-Smtp-Source: ABdhPJz51GJqLuk7px9M3XpJu7oNSDUnaYPy6edLbt7d5KSyxxokPVtkvDQD1ztbKn2kjbCNyy5L2A== X-Received: by 2002:a05:6214:1089:: with SMTP id o9mr5115801qvr.36.1624538835455; Thu, 24 Jun 2021 05:47:15 -0700 (PDT) Received: from [192.168.4.41] (072-017-018-098.res.spectrum.com. [72.17.18.98]) by smtp.gmail.com with ESMTPSA id a11sm2441324qkc.34.2021.06.24.05.47.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 24 Jun 2021 05:47:15 -0700 (PDT) To: Marc Mamin , pgsql-general References: From: Joe Conway Subject: Re: removing "serial" from table definitions. Message-ID: Date: Thu, 24 Jun 2021 08:47:14 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 6/24/21 8:33 AM, Marc Mamin wrote: > Hi, > > Is there  a way to change a data type from serial to int? > > I tried with : > >   ALTER TABLE "admin".db_jobs ALTER COLUMN id TYPE int USING id::int; > > But this seems not to change anything, as if Posgres woud consider the > statement as a no-op. serial is not an actual data type -- it is essentially an integer with a default and an automatically created sequence. See: https://www.postgresql.org/docs/13/datatype-numeric.html#DATATYPE-SERIAL > My problem is that "serial" is not exported with pg_dump. > > Creating a db from the dump will hence result into a different table > definition (which is equivalent tough) > > We are trying a transfer/migration tool on Azure, that check the table > definitions between the source and target before starting the data > transfer, and it blocks on that difference. From the linked doc above: -------------- The data types smallserial, serial and bigserial are not true types, but merely a notational convenience for creating unique identifier columns (similar to the AUTO_INCREMENT property supported by some other databases). In the current implementation, specifying: CREATE TABLE tablename ( colname SERIAL ); is equivalent to specifying: CREATE SEQUENCE tablename_colname_seq AS integer; CREATE TABLE tablename ( colname integer NOT NULL DEFAULT nextval('tablename_colname_seq') ); ALTER SEQUENCE tablename_colname_seq OWNED BY tablename.colname; --------------- I haven't checked, but I am guessing that creating the table using the former method results in a dump that looks like the latter? In that case, just define the table in the second way to begin with and they will match from the migration tools standpoint I should think. Joe -- Crunchy Data - http://crunchydata.com PostgreSQL Support for Secure Enterprises Consulting, Training, & Open Source Development