Created
March 17, 2021 11:38
-
-
Save MbuguaCaleb/77ae0fbf49da131124882185f69b4504 to your computer and use it in GitHub Desktop.
um_permissions.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT id, name, display_name, description, created_at, updated_at | |
FROM unittrust.um_permissions; | |
SELECT Max(id)FROM unittrust.um_permissions; | |
SELECT *FROM unittrust.um_permissions | |
WHERE name LIKE '%system-modules%'; | |
ALTER SEQUENCE um_mod_permissions_id_seq RESTART WITH 1; | |
ALTER SEQUENCE um_permissions_id_seq RESTART WITH 1; | |
SET search_path TO unittrust; | |
ALTER SEQUENCE um_roles_id_seq RESTART WITH 1; | |
-- create sequence
- For an existing column that got no values in the table
CREATE SEQUENCE public_products_id_seq OWNED BY public.products.id;
-- use sequence for the target column
ALTER TABLE public.products ALTER COLUMN id SET DEFAULT nextval('public_products_id_seq');
- For an existing column that already got some values in the table
-- create sequence
CREATE SEQUENCE public_products_id_seq OWNED BY public.products.id;
-- set the current value of the sequence to the max value from that column
-- (id column in this scenario)
SELECT SETVAL('public_products_id_seq', (select max(id) from public.products), false)
-- use sequence for the target column
ALTER TABLE public.products ALTER COLUMN id SET DEFAULT nextval('public_products_id_seq');
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-- auto-increment constraint for a new column
ALTER TABLE public.products
ADD COLUMN id SERIAL PRIMARY KEY;