MCPcopy Create free account
hub / github.com/auxten/postgresql-parser / NewColumnTableDef

Function NewColumnTableDef

pkg/sql/sem/tree/create.go:280–365  ·  view source on GitHub ↗

NewColumnTableDef constructs a column definition for a CreateTable statement.

(
	name Name, typ *types.T, isSerial bool, qualifications []NamedColumnQualification,
)

Source from the content-addressed store, hash-verified

278
279// NewColumnTableDef constructs a column definition for a CreateTable statement.
280func NewColumnTableDef(
281 name Name, typ *types.T, isSerial bool, qualifications []NamedColumnQualification,
282) (*ColumnTableDef, error) {
283 d := &ColumnTableDef{
284 Name: name,
285 Type: typ,
286 IsSerial: isSerial,
287 }
288 d.Nullable.Nullability = SilentNull
289 for _, c := range qualifications {
290 switch t := c.Qualification.(type) {
291 case ColumnCollation:
292 locale := string(t)
293 _, err := language.Parse(locale)
294 if err != nil {
295 return nil, pgerror.Wrapf(err, pgcode.Syntax, "invalid locale %s", locale)
296 }
297 d.Type, err = processCollationOnType(name, d.Type, t)
298 if err != nil {
299 return nil, err
300 }
301 case *ColumnDefault:
302 if d.HasDefaultExpr() {
303 return nil, pgerror.Newf(pgcode.Syntax,
304 "multiple default values specified for column %q", name)
305 }
306 d.DefaultExpr.Expr = t.Expr
307 d.DefaultExpr.ConstraintName = c.Name
308 case NotNullConstraint:
309 if d.Nullable.Nullability == Null {
310 return nil, pgerror.Newf(pgcode.Syntax,
311 "conflicting NULL/NOT NULL declarations for column %q", name)
312 }
313 d.Nullable.Nullability = NotNull
314 d.Nullable.ConstraintName = c.Name
315 case NullConstraint:
316 if d.Nullable.Nullability == NotNull {
317 return nil, pgerror.Newf(pgcode.Syntax,
318 "conflicting NULL/NOT NULL declarations for column %q", name)
319 }
320 d.Nullable.Nullability = Null
321 d.Nullable.ConstraintName = c.Name
322 case PrimaryKeyConstraint:
323 d.PrimaryKey.IsPrimaryKey = true
324 d.UniqueConstraintName = c.Name
325 case ShardedPrimaryKeyConstraint:
326 d.PrimaryKey.IsPrimaryKey = true
327 constraint := c.Qualification.(ShardedPrimaryKeyConstraint)
328 d.PrimaryKey.Sharded = true
329 d.PrimaryKey.ShardBuckets = constraint.ShardBuckets
330 d.UniqueConstraintName = c.Name
331 case UniqueConstraint:
332 d.Unique = true
333 d.UniqueConstraintName = c.Name
334 case *ColumnCheckConstraint:
335 d.CheckExprs = append(d.CheckExprs, ColumnTableDefCheckExpr{
336 Expr: t.Expr,
337 ConstraintName: c.Name,

Callers 1

ParseMethod · 0.92

Calls 7

HasDefaultExprMethod · 0.95
HasFKConstraintMethod · 0.95
HasColumnFamilyMethod · 0.95
WrapfFunction · 0.92
NewfFunction · 0.92
processCollationOnTypeFunction · 0.85
ParseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…