NewColumnTableDef constructs a column definition for a CreateTable statement.
( name Name, typRef ResolvableTypeReference, compression string, collation string, qualifications []NamedColumnQualification, )
| 332 | |
| 333 | // NewColumnTableDef constructs a column definition for a CreateTable statement. |
| 334 | func NewColumnTableDef( |
| 335 | name Name, |
| 336 | typRef ResolvableTypeReference, |
| 337 | compression string, |
| 338 | collation string, |
| 339 | qualifications []NamedColumnQualification, |
| 340 | ) (*ColumnTableDef, error) { |
| 341 | var isSerial bool |
| 342 | if typRef != nil { |
| 343 | isSerial = IsReferenceSerialType(typRef) |
| 344 | } |
| 345 | d := &ColumnTableDef{ |
| 346 | Name: name, |
| 347 | Type: typRef, |
| 348 | IsSerial: isSerial, |
| 349 | } |
| 350 | d.Nullable.Nullability = SilentNull |
| 351 | if collation != "" { |
| 352 | _, err := language.Parse(collation) |
| 353 | if err != nil { |
| 354 | return nil, pgerror.Wrapf(err, pgcode.Syntax, "invalid locale %s", collation) |
| 355 | } |
| 356 | collatedTyp, err := processCollationOnType(name, d.Type, collation) |
| 357 | if err != nil { |
| 358 | // TODO: currently ignore as the test used dummy value // return nil, err |
| 359 | } else { |
| 360 | d.Type = collatedTyp |
| 361 | } |
| 362 | } |
| 363 | for _, c := range qualifications { |
| 364 | switch t := c.Qualification.(type) { |
| 365 | case *ColumnDefault: |
| 366 | if d.HasDefaultExpr() { |
| 367 | return nil, pgerror.Newf(pgcode.Syntax, |
| 368 | "multiple default values specified for column %q", name) |
| 369 | } |
| 370 | d.DefaultExpr.Expr = t.Expr |
| 371 | d.DefaultExpr.ConstraintName = c.Name |
| 372 | case NotNullConstraint: |
| 373 | if d.Nullable.Nullability == Null { |
| 374 | return nil, pgerror.Newf(pgcode.Syntax, |
| 375 | "conflicting NULL/NOT NULL declarations for column %q", name) |
| 376 | } |
| 377 | d.Nullable.Nullability = NotNull |
| 378 | d.Nullable.ConstraintName = c.Name |
| 379 | case NullConstraint: |
| 380 | if d.Nullable.Nullability == NotNull { |
| 381 | return nil, pgerror.Newf(pgcode.Syntax, |
| 382 | "conflicting NULL/NOT NULL declarations for column %q", name) |
| 383 | } |
| 384 | d.Nullable.Nullability = Null |
| 385 | d.Nullable.ConstraintName = c.Name |
| 386 | case UniqueConstraint: |
| 387 | if t.IsPrimary { |
| 388 | d.PrimaryKey.IsPrimaryKey = true |
| 389 | } else { |
| 390 | d.Unique = true |
| 391 | } |
nothing calls this directly
no test coverage detected