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

Mapping Identity column to Serial instead of using Sequences #102

Closed
issafram opened this issue Apr 1, 2019 · 7 comments
Closed

Mapping Identity column to Serial instead of using Sequences #102

issafram opened this issue Apr 1, 2019 · 7 comments

Comments

@issafram
Copy link

issafram commented Apr 1, 2019

Is there a reason that the script creates sequences instead of marking a column as SERIAL?
I'm not a Postgres expert but I think it might be easier to use Serial.

Please let me know if there is an option for that

@madtibo
Copy link
Contributor

madtibo commented Apr 2, 2019

Hello @issafram

The PostgreSQL implementation makes it the same: https://www.postgresql.org/docs/11/datatype-numeric.html#DATATYPE-SERIAL

If I manually create a table using a serial, I will get a sequence:

thibaut=# CREATE TABLE testtable ( value serial PRIMARY KEY);
CREATE TABLE
thibaut=# \d testtable
                                 Table « public.testtable »
 Colonne |  Type   | Collationnement | NULL-able |                Par défaut                
---------+---------+-----------------+-----------+------------------------------------------
 value   | integer |                 | not null  | nextval('testtable_value_seq'::regclass)
Index :
    "testtable_pkey" PRIMARY KEY, btree (value)

thibaut=# \ds testtable_value_seq
                  Liste des relations
 Schéma |         Nom         |   Type   | Propriétaire 
--------+---------------------+----------+--------------
 public | testtable_value_seq | séquence | thibaut
(1 line)

The script does not create some real identity columns as we can use since PostgreSQL version 10:

thibaut=# CREATE TABLE testtable2 ( value int PRIMARY KEY GENERATED ALWAYS AS IDENTITY);
CREATE TABLE
thibaut=# \d testtable2
                          Table « public.testtable2 »
 Colonne |  Type   | Collationnement | NULL-able |          Par défaut          
---------+---------+-----------------+-----------+------------------------------
 value   | integer |                 | not null  | generated always as identity
Index :
    "testtable2_pkey" PRIMARY KEY, btree (value)

thibaut=# \ds testtable2_*
                   Liste des relations
 Schéma |         Nom          |   Type   | Propriétaire 
--------+----------------------+----------+--------------
 public | testtable2_value_seq | séquence | thibaut
(1 ligne)

Maybe we should now use IDENTITY columns.

@issafram
Copy link
Author

issafram commented Apr 3, 2019

Maybe we should now use IDENTITY columns.

I think you are right. Maybe default to IDENTITY and put an option flag of sorts to use sequences (in case of older Postgres versions).

What do you think?

@madtibo
Copy link
Contributor

madtibo commented Jun 14, 2019

Very good idea!

Can you propose a PR with this evolution?

Cordialement,

@issafram
Copy link
Author

@madtibo Sorry I haven't had a chance to work on this yet. It looks like maybe #112 might be working on that. If not, I'll try to get around to it when I can

@madtibo
Copy link
Contributor

madtibo commented Sep 11, 2019

@issafram #112 is a special case for sequences values. It is not very clear how the OP solved its problem. We will see that if we get a PR...

@madtibo
Copy link
Contributor

madtibo commented Oct 16, 2020

There is now the #118 that should do the trick.

If you are still using it, could you test it on your data?

@madtibo
Copy link
Contributor

madtibo commented May 4, 2021

#150 merged

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

No branches or pull requests

2 participants