Creating SQL Table from a Go Struct I have been building an API in Go, which I want to link to a Postgres SQL table. I have always used NoSQL previously but thought it would be good to try a SQL database.
Here are my structs
type Activity struct {
    Activity string `json:&quot;activity&quot;`
    Payload Payload `json:&quot;payload&quot;`
}

type Payload  struct {
    UserID   string `json:&quot;userId&quot;`
    Duration int    `json:&quot;duration&quot;`
    Type     string `json:&quot;type&quot;`
    Date     int    `json:&quot;date&quot;`
}

Based on the above I thought it would be good to have a table for payload which was made via the following query.
CREATE TABLE payload (
    userid SERIAL PRIMARY KEY,
    duration INT,
    type TEXT,
    date INT
);

and then created the activity table like the following:
CREATE TABLE activity (
    activity TEXT PRIMARY KEY
    SELECT userid, duration, type, date
    FROM payload;
);
None of your columns are marked non-nullable. This is important for data integrity.
duration and date both seem mis-represented as int. You're in PostgreSQL, so read https://www.postgresql.org/docs/current/datatype-datetime.html and then consider instead

interval for duration, and
date for date