Skip to content

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.

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