本文整理匯總了Golang中github.com/cockroachdb/cockroach/sql/parser.Parser.AggregateInExpr方法的典型用法代碼示例。如果您正苦於以下問題:Golang Parser.AggregateInExpr方法的具體用法?Golang Parser.AggregateInExpr怎麽用?Golang Parser.AggregateInExpr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cockroachdb/cockroach/sql/parser.Parser
的用法示例。
在下文中一共展示了Parser.AggregateInExpr方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: MakeColumnDefDescs
// MakeColumnDefDescs creates the column descriptor for a column, as well as the
// index descriptor if the column is a primary key or unique.
func MakeColumnDefDescs(d *parser.ColumnTableDef) (*ColumnDescriptor, *IndexDescriptor, error) {
col := &ColumnDescriptor{
Name: string(d.Name),
Nullable: d.Nullable.Nullability != parser.NotNull && !d.PrimaryKey,
}
if d.Nullable.ConstraintName != "" {
col.NullableConstraintName = string(d.Nullable.ConstraintName)
}
var colDatumType parser.Datum
switch t := d.Type.(type) {
case *parser.BoolColType:
col.Type.Kind = ColumnType_BOOL
colDatumType = parser.TypeBool
case *parser.IntColType:
col.Type.Kind = ColumnType_INT
col.Type.Width = int32(t.N)
colDatumType = parser.TypeInt
if t.IsSerial() {
if d.DefaultExpr.Expr != nil {
return nil, nil, fmt.Errorf("SERIAL column %q cannot have a default value", col.Name)
}
s := "unique_rowid()"
col.DefaultExpr = &s
}
case *parser.FloatColType:
col.Type.Kind = ColumnType_FLOAT
col.Type.Precision = int32(t.Prec)
colDatumType = parser.TypeFloat
case *parser.DecimalColType:
col.Type.Kind = ColumnType_DECIMAL
col.Type.Width = int32(t.Scale)
col.Type.Precision = int32(t.Prec)
colDatumType = parser.TypeDecimal
case *parser.DateColType:
col.Type.Kind = ColumnType_DATE
colDatumType = parser.TypeDate
case *parser.TimestampColType:
col.Type.Kind = ColumnType_TIMESTAMP
colDatumType = parser.TypeTimestamp
case *parser.TimestampTZColType:
col.Type.Kind = ColumnType_TIMESTAMPTZ
colDatumType = parser.TypeTimestampTZ
case *parser.IntervalColType:
col.Type.Kind = ColumnType_INTERVAL
colDatumType = parser.TypeInterval
case *parser.StringColType:
col.Type.Kind = ColumnType_STRING
col.Type.Width = int32(t.N)
colDatumType = parser.TypeString
case *parser.BytesColType:
col.Type.Kind = ColumnType_BYTES
colDatumType = parser.TypeBytes
default:
return nil, nil, errors.Errorf("unexpected type %T", t)
}
if col.Type.Kind == ColumnType_DECIMAL {
switch {
case col.Type.Precision == 0 && col.Type.Width > 0:
// TODO (seif): Find right range for error message.
return nil, nil, errors.New("invalid NUMERIC precision 0")
case col.Type.Precision < col.Type.Width:
return nil, nil, fmt.Errorf("NUMERIC scale %d must be between 0 and precision %d",
col.Type.Width, col.Type.Precision)
}
}
if d.DefaultExpr.Expr != nil {
// Verify the default expression type is compatible with the column type.
if err := SanitizeVarFreeExpr(d.DefaultExpr.Expr, colDatumType, "DEFAULT"); err != nil {
return nil, nil, err
}
var p parser.Parser
if p.AggregateInExpr(d.DefaultExpr.Expr) {
return nil, nil, fmt.Errorf("Aggregate functions are not allowed in DEFAULT expressions")
}
if d.DefaultExpr.ConstraintName != "" {
col.DefaultExprConstraintName = string(d.DefaultExpr.ConstraintName)
}
s := d.DefaultExpr.Expr.String()
col.DefaultExpr = &s
}
var idx *IndexDescriptor
if d.PrimaryKey || d.Unique {
idx = &IndexDescriptor{
Unique: true,
ColumnNames: []string{string(d.Name)},
ColumnDirections: []IndexDescriptor_Direction{IndexDescriptor_ASC},
}
if d.UniqueConstraintName != "" {
idx.Name = string(d.UniqueConstraintName)
}
}
return col, idx, nil
//.........這裏部分代碼省略.........