bcgov / bcgov/bcdata_py

bc2pg - use generated identity column for pk instead of serial

Open
#225 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
32
Forks
7
Avg merge
21h 3m
Merged PRs (30d)
15

Description

sqlalchemy creates a sequence for the pk by default. Preferred behaviour for pg 10 and up is to use a generated identity column and implicit sequence.

https://www.postgresql.org/docs/current/ddl-identity-columns.html
https://docs.sqlalchemy.org/en/20/core/defaults.html#identity-ddl

something like this (presuming that translating to `GENERATED BY DEFAULT` is the default, because we are loading data with existing values, it cannot not be `GENERATED ALWAYS`):
```
from sqlalchemy import Identity

...
columns.append(
Column(
column_name,
column_type,
primary_key=True,
Identity(),
comment=column_comments,
)
)
```

Obv, will only work for columns of type integer/bigint.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.