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

[Question] How to generate ALTER COLUMN instructions to set default values to sequences nextval? #1814

Open
samueldc opened this issue Sep 12, 2024 · 5 comments

Comments

@samueldc
Copy link

Hi everyone,
I'm taking my first steps with this amazing tool.
I'm trying to migrate an Oracle old database (of an old OTRS 5 instance). In this old database, that has almost 158 tables, most id fields (private keys) are autoincremented using sequences and triggers to insert a sequence nextval into the id field.
ora2pg is doing just fine generating the sequences and updating their current values. But I'm missing the alter column instructions to set default values to the sequences nextval in PostgreSQL (or, maybe, convert all this fields to type identity or serial).
Is that in the scope of ora2pg? Any thoughts on that?
Thanks in advance!
Samuel

@samueldc
Copy link
Author

Just to mention I've already looked for similar questions. The issues below seem to be related, but I don't think they address this question:

#1438

#1101

@darold
Copy link
Owner

darold commented Sep 12, 2024

Use -t SEQUENCE_VALUES to export the alter statements to set the latest value of each sequences

@samueldc
Copy link
Author

I'm using ora2pg v23.2. I'm afraid this export type is not available.

Does export type SEQUENCE_VALUES generate the ALTER TABLE ... ALTER COLUMN id SET DEFAULT nexval... instructions?

@darold
Copy link
Owner

darold commented Sep 12, 2024

It is available since version 24.0:

commit b711cc638f945e320237cf2457136021f08186a2
Author: Gilles Darold <[email protected]>
Date:   Thu Mar 16 22:51:31 2023 +0100

    Add SEQUENCE_VALUES export type to export DDL to set the last values of
    sequences like the folowing statements:

      ALTER SEQUENCE departments_seq START WITH 290;
      ALTER SEQUENCE employees_seq START WITH 207;
      ALTER SEQUENCE locations_seq START WITH 3300;

    Thanks to sergey grinko for the feature request.

@samueldc
Copy link
Author

Thank you very much. Since I'm looking for a way to generate the set default nextval instructions, I'll keep with version 23. I think I'll generate those instructions by hand.

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

2 participants