Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Negative arguments to IDENTITY #112

Closed
potrusil opened this issue Sep 6, 2019 · 5 comments
Closed

Negative arguments to IDENTITY #112

potrusil opened this issue Sep 6, 2019 · 5 comments

Comments

@potrusil
Copy link

potrusil commented Sep 6, 2019

The script doesn't support negative arguments to IDENTITY

@madtibo
Copy link
Contributor

madtibo commented Sep 9, 2019

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,

@potrusil
Copy link
Author

potrusil commented Sep 9, 2019

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?

@madtibo
Copy link
Contributor

madtibo commented Sep 10, 2019

I am sure some people might need your changes :-)
Can you open a merge request so we can review them?

@potrusil-osi
Copy link
Contributor

Ok, I have just created this request: #114

madtibo added a commit that referenced this issue Apr 29, 2021
* support IDENTITY with negative arguments; detect end of table more generically
* Add tests
* rebase patch by potrusil-osi

Co-authored-by: Tomas Potrusil <[email protected]>
@madtibo
Copy link
Contributor

madtibo commented Apr 29, 2021

PR merged. Thanks for all.

@madtibo madtibo closed this as completed Apr 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants