Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Why is a column that can be null assigned sql.NullString? #1295

Answered by mwbidwell
mwbidwell asked this question in Q&A
Discussion options

CREATE TABLE users (
id bigserial PRIMARY KEY,
first_name VARCHAR(255),
last_name VARCHAR(255),
email VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL,
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
);

-- name: GetUserByID :one
SELECT * FROM users
WHERE id = 1ドル LIMIT 1;

Generates this:
type User struct {
ID int64
FirstName sql.NullString
LastName sql.NullString
Email string
Password string
CreatedAt sql.NullTime
UpdatedAt time.Time
}

You must be logged in to vote

Hmm... seems like I just misunderstood what sql.NullString is used for.

Please disregard.

Replies: 1 comment

Comment options

Hmm... seems like I just misunderstood what sql.NullString is used for.

Please disregard.

You must be logged in to vote
0 replies
Answer selected by mwbidwell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /