in internal/database/postgres/postgres.go [397:423]
func (h postgresHandler) GetColumnComment(ctx context.Context, db *database.DB, tableName string, columnName string) (string, error) {
query := `
SELECT description
FROM pg_catalog.pg_description
JOIN pg_catalog.pg_class c ON pg_description.objoid = c.oid
JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
JOIN pg_catalog.pg_attribute a ON pg_description.objoid = a.attrelid AND pg_description.objsubid = a.attnum
WHERE n.nspname = 'public' -- Assuming public schema
AND c.relname = $1
AND a.attname = $2;
`
var comment sql.NullString // Use sql.NullString to handle NULL values
err := db.QueryRowContext(ctx, query, tableName, columnName).Scan(&comment)
if err != nil {
if err == sql.ErrNoRows {
return "", nil // No comment found, return empty string
}
return "", fmt.Errorf("failed to retrieve column comment: %w", err)
}
if comment.Valid {
return comment.String, nil
}
return "", nil // Comment is NULL in DB, return empty string
}