pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: rob stone <floriparob@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
To: Robert Lakes <robertl@propaas.com>
Cc: pgsql-general@postgresql.org
Subject: Re: Adding 'serial' to existing column
Date: Sat, 04 Nov 2017 08:07:03 +1100
Message-ID: <1509743223.13050.10.camel@gmail.com> (raw)
In-Reply-To: <5077.1509742072@sss.pgh.pa.us>
References: <CAHnqRj2zkrAw2X_JcAFZ0G_qV-=mHA0S6fNQ4NgqFvaKZQTDcQ@mail.gmail.com>
	<5077.1509742072@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-general>



On Fri, 2017-11-03 at 16:47 -0400, Tom Lane wrote:
> Robert Lakes <robertl@propaas.com> 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



view thread (3+ messages)

Message-ID: <1509743223.13050.10.camel@gmail.com>
Permalink:  ../1509743223.13050.10.camel@gmail.com/
Also on:    postgresql.org/message-id/1509743223.13050.10.camel@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: floriparob@gmail.com, tgl@sss.pgh.pa.us, robertl@propaas.com
  Subject: Re: Adding 'serial' to existing column
  In-Reply-To: <1509743223.13050.10.camel@gmail.com>
  References: <CAHnqRj2zkrAw2X_JcAFZ0G_qV-=mHA0S6fNQ4NgqFvaKZQTDcQ@mail.gmail.com> <5077.1509742072@sss.pgh.pa.us> <1509743223.13050.10.camel@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox