Re: [GENERAL] Adding 'serial' to existing column - Mailing list pgsql-general

From Tom Lane
Subject Re: [GENERAL] Adding 'serial' to existing column
Date
Msg-id 5077.1509742072@sss.pgh.pa.us
Whole thread Raw
In response to [GENERAL] Adding 'serial' to existing column  (Robert Lakes <robertl@propaas.com>)
Responses Re: [GENERAL] Adding 'serial' to existing column
List pgsql-general
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


-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

pgsql-general by date:

Previous
From: Robert Lakes
Date:
Subject: [GENERAL] Adding 'serial' to existing column
Next
From: Rhhh Lin
Date:
Subject: Re: [GENERAL] EXPLAIN command just hangs...