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

for sequences, account for nulls and zero #112

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jhere1
Copy link
Contributor

@jhere1 jhere1 commented Aug 22, 2023

set sequence value to 1 if max(columnName) returns null or less than 1.

@@ -67,7 +67,10 @@ export const setSequenceValue = async (

const seqName: string = getSequenceName(tableName, columnName);
const sql = `SELECT SETVAL(\'"${conversion._schema}"."${seqName}"\',
(SELECT MAX("${columnName}") FROM "${conversion._schema}"."${tableName}"));`;
GREATEST(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jhere1
In general - good catch!
The question is, shouldn't we set sequence value to zero if table is empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the nextval would have been 2. Setting sequence value to 0 would involve changing the sequence definition min value. Take a look at my latest commit. Think this is cleaner. it does what we want (have nextval be 1) by saying the value of 1 is not used yet.

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

Successfully merging this pull request may close these issues.

2 participants