I'm not familiar with postgresql script.
I already use this script in ms sql server :
SET IDENTITY_INSERT my_table ON
INSERT INTO my_table (
my_identity_field,
field1,
field2
)
SELECT
fieldA,
fieldB
FROM
my_other_table
WHERE
fieldC = some_value
SET IDENTITY_INSERT my_table OFF
Question :
What is the script 'SET IDENTIFY_INSERT [table_name] ON/OFF' in PostgreSQL ?
Thank you
SOLVED :
INSERT INTO my_table (
my_identity_field,
field1,
field2
)
SELECT
fieldA,
fieldB
FROM
my_other_table
WHERE
fieldC = some_value;
SELECT
setval(pg_get_serial_sequence('my_table', 'my_identity_field'),
(SELECT MAX(my_identity_field) FROM my_table));
Note:
'my_table' and 'my_identity_field' in lowercase
I'm getting error if they're not in lowercase (all letters)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…