Skip to content

Best practice of using pgtype package #1853

Answered by jackc
hnsiri asked this question in Q&A
Discussion options

You must be logged in to vote

In general, you should only use pgtype directly when you need to. For example, if you have a NOT NULL integer in PostgreSQL then scan it directly to a Go int32. But if it is nullable then scan it into a pgtype.Int4.

You can also have your types implement pgtype interfaces like DateScanner and DateValuer. That allows you to directly use your application types.

So in short, try to use native Go types or your application types and only use pgtype types directly when necessary.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@hnsiri
Comment options

Answer selected by hnsiri
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants