Re: Resetting identity columns

2019-04-23 Thread Ray O'Donnell
On 22/04/2019 18:49, Tom Lane wrote: "Ray O'Donnell" writes: In general, then, is it not possible to use an expression thus? - [...] ALTER COLUMN [...] RESTART WITH No. In general, PG's utility commands (everything except SELECT/ INSERT/UPDATE/DELETE) don't do expression evaluation

Re: Resetting identity columns

2019-04-22 Thread Thomas Kellerer
Ray O'Donnell schrieb am 22.04.2019 um 17:30: I'm probably doing something silly I'm migrating data from one database table to another, where the old table used a SERIAL primary key and the new one uses GENERATED BY DEFAULT AS IDENTITY. Having loaded the data into the new table, I need to res

Re: Resetting identity columns

2019-04-22 Thread Adrian Klaver
On 4/22/19 10:08 AM, Ray O'Donnell wrote: On 22/04/2019 17:02, Adrian Klaver wrote: do language plpgsql $$ declare m_max_id bigint; begin select max(id) + 1 from identity_test into m_max_id; EXECUTE 'alter table identity_test alter column id restart with ' || m_max_id; end; $$; Thanks a mil

Re: Resetting identity columns

2019-04-22 Thread Tom Lane
"Ray O'Donnell" writes: > In general, then, is it not possible to use an expression thus? - > [...] ALTER COLUMN [...] RESTART WITH No. In general, PG's utility commands (everything except SELECT/ INSERT/UPDATE/DELETE) don't do expression evaluation. Partly this is laziness or lack of ro

Re: Resetting identity columns

2019-04-22 Thread Ray O'Donnell
On 22/04/2019 17:02, Adrian Klaver wrote: do language plpgsql $$ declare m_max_id bigint; begin select max(id) + 1 from identity_test into m_max_id; EXECUTE 'alter table identity_test alter column id restart with ' || m_max_id; end; $$; Thanks a million Adrian - EXECUTE did the job, and I fi

Re: Resetting identity columns

2019-04-22 Thread Adrian Klaver
On 4/22/19 8:30 AM, Ray O'Donnell wrote: Hi all, I'm probably doing something silly I'm migrating data from one database table to another, where the old table used a SERIAL primary key and the new one uses GENERATED BY DEFAULT AS IDENTITY. Having loaded the data into the new table, I need

Re: Resetting identity columns

2019-04-22 Thread Adrian Klaver
On 4/22/19 8:45 AM, Adrian Klaver wrote: On 4/22/19 8:30 AM, Ray O'Donnell wrote: Hi all, I'm probably doing something silly I'm migrating data from one database table to another, where the old table used a SERIAL primary key and the new one uses GENERATED BY DEFAULT AS IDENTITY. Having

Re: Resetting identity columns

2019-04-22 Thread Adrian Klaver
On 4/22/19 8:30 AM, Ray O'Donnell wrote: Hi all, I'm probably doing something silly I'm migrating data from one database table to another, where the old table used a SERIAL primary key and the new one uses GENERATED BY DEFAULT AS IDENTITY. Having loaded the data into the new table, I need

Resetting identity columns

2019-04-22 Thread Ray O'Donnell
Hi all, I'm probably doing something silly I'm migrating data from one database table to another, where the old table used a SERIAL primary key and the new one uses GENERATED BY DEFAULT AS IDENTITY. Having loaded the data into the new table, I need to reset the underlying sequence so that