Return a default value for a PostgreSQL column based on its type. Returns nil if the type is unknown.
(col *plugin.Column)
| 182 | // Return a default value for a PostgreSQL column based on its type. Returns nil |
| 183 | // if the type is unknown. |
| 184 | func pgDefaultValue(col *plugin.Column) any { |
| 185 | if col == nil { |
| 186 | return nil |
| 187 | } |
| 188 | if col.Type == nil { |
| 189 | return nil |
| 190 | } |
| 191 | typname := strings.TrimPrefix(col.Type.Name, "pg_catalog.") |
| 192 | switch typname { |
| 193 | case "any", "void": |
| 194 | if col.IsArray { |
| 195 | return []any{} |
| 196 | } else { |
| 197 | return nil |
| 198 | } |
| 199 | case "anyarray": |
| 200 | return []any{} |
| 201 | case "bool", "boolean": |
| 202 | if col.IsArray { |
| 203 | return []bool{} |
| 204 | } else { |
| 205 | return false |
| 206 | } |
| 207 | case "double", "double precision", "real": |
| 208 | if col.IsArray { |
| 209 | return []float32{} |
| 210 | } else { |
| 211 | return 0.1 |
| 212 | } |
| 213 | case "json", "jsonb": |
| 214 | if col.IsArray { |
| 215 | return []string{} |
| 216 | } else { |
| 217 | return "{}" |
| 218 | } |
| 219 | case "citext", "string", "text", "varchar": |
| 220 | if col.IsArray { |
| 221 | return []string{} |
| 222 | } else { |
| 223 | return "" |
| 224 | } |
| 225 | case "bigint", "bigserial", "integer", "int", "int2", "int4", "int8", "serial": |
| 226 | if col.IsArray { |
| 227 | return []int{} |
| 228 | } else { |
| 229 | return 1 |
| 230 | } |
| 231 | case "date", "time", "timestamp", "timestamptz": |
| 232 | if col.IsArray { |
| 233 | return []time.Time{} |
| 234 | } else { |
| 235 | return time.Time{} |
| 236 | } |
| 237 | case "uuid": |
| 238 | if col.IsArray { |
| 239 | return []string{} |
| 240 | } else { |
| 241 | return "00000000-0000-0000-0000-000000000000" |