So I have this table:
CREATE TABLE customer (
id SERIAL PRIMARY KEY,
name character varying(30) NOT NULL,
created_at timestamp with time zone NOT NULL DEFAULT NOW()
);
And I have github.com/jackc/pgx/v4
in my import statement.
My Go code looks like this:
conn, err := pgx.Connect(context.Background(), os.Getenv("postgres://user:@127.0.0.1:5432/dbname"))
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to connection to database: %v\n", err)
os.Exit(1)
}
defer conn.Close(context.Background())
_, err = conn.Exec(context.Background(), "INSERT INTO customer(name) values($1)", "something")
if err != nil {
log.Fatal(err)
}
Output:
2019/08/14 09:24:26 ERROR: null value in column "created_at" violates not-null constraint (SQLSTATE 23502)
exit status 1
How come when I have DEFAULT NOW()
? I tried creating a recored from my DB GUI client (Postico) and created_at
field got auto-populated.
What's wrong?