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:"activity"`
    Payload Payload `json:"payload"`

type Payload  struct {
    UserID   string `json:"userId"`
    Duration int    `json:"duration"`
    Type     string `json:"type"`
    Date     int    `json:"date"`

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 (
    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;

1 Answer 1


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.