Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eAjDk-0002bB-MY for pgsql-general@arkaria.postgresql.org; Fri, 03 Nov 2017 21:09:44 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1eAjDk-0004mL-4j for pgsql-general@arkaria.postgresql.org; Fri, 03 Nov 2017 21:09:44 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eAjBL-0008Ns-Sl for pgsql-general@postgresql.org; Fri, 03 Nov 2017 21:07:16 +0000 Received: from mail-qk0-x230.google.com ([2607:f8b0:400d:c09::230]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1eAjBE-0006g4-Ky for pgsql-general@postgresql.org; Fri, 03 Nov 2017 21:07:14 +0000 Received: by mail-qk0-x230.google.com with SMTP id m189so4810211qke.4 for ; Fri, 03 Nov 2017 14:07:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:subject:from:to:cc:date:in-reply-to:references :mime-version:content-transfer-encoding; bh=z460sKX5sQhOlv3S63dEBLaD/YysafPO9hB3WZ9dTvY=; b=dWQI3wMPVe/H1RIr+llxhKmqHijBOPjoQzV/cUxEueFIrOK00J2rmGeaHYCMBvR0Ol GYucK18m41wXnJxsY9zaKCgFtNuGHJatA6vI2675qwpFYgx2Mfuh+3mJhEmoanI97d7o IUhK1hxq14CBv8eyc08fKNXuXgS1OdaXIPJgsr2ZBJ+umHEU42CtWWBjEo+snByyiznO t1NL7hQUvldNyiJvaK7bh8+Sw8XSgzUPsFxo/Ceh9IdQhkeR6rnwwIUfZM6Zk3fT0AWw AqZCCM7vUmu1ghO1grCy5v5hMfysA8l6BgO5TMBtuoryEBc+oMffJux1jSAZ4JuicjxS EGGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:mime-version:content-transfer-encoding; bh=z460sKX5sQhOlv3S63dEBLaD/YysafPO9hB3WZ9dTvY=; b=MDdxbk3jM6PoANe155JW7YlDGnsH4OGMhuXQgrfbhPh9oujCqxgwYfYIRuOyx3zT/C zsoo9bec7iK74AVAFVheUEqBFFbbrvVH57oL97xPeiFB4Iv8YZaLufmSNWP3vrvoHDU6 TMflSWOQ417oN1ddj5GAIgtifkoJNo4zFdeg9eNCYZ1xQEtXW2PzlnvNMSABXZO6h4N9 evQVBJlbBtxdcDsRmyv+OawpQ7tsqPK5omDMUmUDxnhFSUr01mZ5SQ6QbqG1lm0sLvkf hTmgzQMjkdeXArGGAzmX0ZY/0q6YE0Y/kuU/S0UKbgYDJcuRzVXDVfJPJxf+qu/8sXdC iyIg== X-Gm-Message-State: AMCzsaWOtJmUdOGe3rUpDutVbCalMAmBop/upfXjUHcvG0GzfFrZWHs2 TOqewvcNZzuXX28zAyf69eg= X-Google-Smtp-Source: ABhQp+Qvz41nJzcPPBZ2QmRVDzi+ZsWNlIkkqQxhARuYtlphXk1cd2Tu115qMvcLleNO49/Sxl8/vg== X-Received: by 10.55.99.69 with SMTP id x66mr11726710qkb.87.1509743227331; Fri, 03 Nov 2017 14:07:07 -0700 (PDT) Received: from roblaptop ([2804:14d:baa0:8491:461e:a1ff:fe19:c7bd]) by smtp.gmail.com with ESMTPSA id j7sm4411648qth.25.2017.11.03.14.07.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 03 Nov 2017 14:07:06 -0700 (PDT) Message-ID: <1509743223.13050.10.camel@gmail.com> Subject: Re: Adding 'serial' to existing column From: rob stone To: Tom Lane , Robert Lakes Cc: pgsql-general@postgresql.org Date: Sat, 04 Nov 2017 08:07:03 +1100 In-Reply-To: <5077.1509742072@sss.pgh.pa.us> References: <5077.1509742072@sss.pgh.pa.us> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.26.1-1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-general Precedence: bulk Sender: pgsql-general-owner@postgresql.org On Fri, 2017-11-03 at 16:47 -0400, Tom Lane wrote: > Robert Lakes writes: > > I am new to Postgres and I am trying to build this SQL statement in > > my SQL > > script: > > ALTER TABLE listings_cdc ALTER COLUMN table_id SET DEFAULT > > nextval('tab_id_seq'); > > That looks correct, but this not so much: > > > I am trying to build the above-stated command as a dynamic SQL > > statement: > > EXECUTE 'ALTER TABLE listings_cdc ALTER COLUMN table_id SET > > DEFAULT > > nextval('||quote_ident(tab_id_seq)||')'; > > I've received an error when running the script this above-stated > > command: > > ERROR: column "tab_id_seq" does not exist > > LINE 1: ...OLUMN table_id SET DEFAULT > > nextval('||quote_ident(tab_id_seq... > > You want quote_literal, not quote_ident, because you're trying to > produce > a single-quoted literal. > > regards, tom lane > > You could also do:- ALTER SEQUENCE tab_id_seq OWNED BY listings_cdc.table_id; which would establish the one-to-one relationship between the table and its sequence for that column. My 2 cents worth. HTH, Rob -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general