Negative arguments to IDENTITY
Closed this issue · 5 comments
The script doesn't support negative arguments to IDENTITY
Hello @potrusil
Currently, sqlserver2pgsql does not support IDENTITY columns and use sequences. There is an open issue about this (#102).
When a sequence is created in PostgreSQL, the default minvalue is 1. To be able to create a sequence holding negative values, you must update the sequence used in the table. For example:
=# CREATE TABLE table_negative_id (id serial PRIMARY KEY, value integer);
CREATE TABLE
=# \d table_negative_id
Table « public.table_negative_id »
Colonne | Type | Collationnement | NULL-able | Par défaut
---------+---------+-----------------+-----------+-----------------------------------------------
id | integer | | not null | nextval('table_negative_id_id_seq'::regclass)
value | integer | | |
Index :
"table_negative_id_pkey" PRIMARY KEY, btree (id)
=# ALTER SEQUENCE table_negative_id_id_seq MINVALUE -1000000001 START -1000000000 RESTART -1000000000;
ALTER SEQUENCE
=# INSERT INTO table_negative_id (value) VALUES (1), (2), (3);
INSERT 0 3
=# SELECT * FROM table_negative_id;
id | value
-------------+-------
-1000000000 | 1
-999999999 | 2
-999999998 | 3
(3 lignes)
Does this trick solve your problem?
Cordialement,
Hi @madtibo,
I have solved the problem by making changes to sqlserver2pgsql locally - it is not difficult to find those places where that is handled. It works fine now. I just wanted to point out to the problem by opening this issue.
Would anybody be interested in my changes?
I am sure some people might need your changes :-)
Can you open a merge request so we can review them?
Ok, I have just created this request: #114
PR merged. Thanks for all.