// create alter sql string.
5522
func getColumnAddQuery(al *alias, fi *fieldInfo) string {
	Q := al.DbBaser.TableQuote()
	typ := getColumnTyp(al, fi)

	if fi.null == false {
		typ += " " + "NOT NULL"
	}

	return fmt.Sprintf("ALTER TABLE %s%s%s ADD COLUMN %s%s%s %s %s",
		Q, fi.mi.table, Q,
		Q, fi.column, Q,
		typ, getColumnDefault(fi),
	)
}
1167480
func (c *index) Create(ctx sessionctx.Context, rm kv.RetrieverMutator, indexedValues []types.Datum, h int64,
	opts ...*table.CreateIdxOpt) (int64, error) {
	writeBufs := ctx.GetSessionVars().GetWriteStmtBufs()
	skipCheck := ctx.GetSessionVars().LightningMode || ctx.GetSessionVars().StmtCtx.BatchCheck
	key, distinct, err := c.GenIndexKey(ctx.GetSessionVars().StmtCtx, indexedValues, h, writeBufs.IndexKeyBuf)
	if err != nil {
		return 0, err
	}
	// save the key buffer to reuse.
	writeBufs.IndexKeyBuf = key
	if !distinct {
		// non-unique index doesn't need store value, write a '0' to reduce space
		err = rm.Set(key, []byte{'0'})
		return 0, err
	}

	var value []byte
	if !skipCheck {
		value, err = rm.Get(key)
	}

	if skipCheck || kv.IsErrNotFound(err) {
		err = rm.Set(key, EncodeHandle(h))
		return 0, err
	}

	handle, err := DecodeHandle(value)
	if err != nil {
		return 0, err
	}
	return handle, kv.ErrKeyExists
}
1155381
func (l *Lambda) create(kind, name string, m map[string]interface{}) {
	l.log(kind, name, m, '+', green)
}
850857
func (idx *AddrIndex) Create(dbTx database.Tx) error {
	_, err := dbTx.Metadata().CreateBucket(addrIndexKey)
	return err
}
380505
func (lu *LookupUnique) Create(vcursor VCursor, rowsColValues [][]sqltypes.Value, ksids [][]byte, ignoreMode bool) error {
	return lu.lkp.Create(vcursor, rowsColValues, ksidsToValues(ksids), ignoreMode)
}
578762
func (idx *TxIndex) Create(dbTx database.Tx) error {
	meta := dbTx.Metadata()
	if _, err := meta.CreateBucket(idByHashIndexBucketName); err != nil {
		return err
	}
	if _, err := meta.CreateBucket(hashByIDIndexBucketName); err != nil {
		return err
	}
	_, err := meta.CreateBucket(txIndexKey)
	return err
}
1329151
func (fk ForeignKeyElem) Create(d Dialect) (string, error) {
	// Compile the type
	ct, err := fk.typ.Create(d)
	if err != nil {
		return "", err
	}
	compiled := fmt.Sprintf(
		`"%s" %s REFERENCES %s("%s")`,
		fk.name,
		ct,
		fk.col.table.Name(),
		fk.col.Name(),
	)
	if fk.onDelete != nil {
		compiled += fmt.Sprintf(" ON DELETE %s", *fk.onDelete)
	}
	if fk.onUpdate != nil {
		compiled += fmt.Sprintf(" ON UPDATE %s", *fk.onUpdate)
	}
	return compiled, nil
}
382700
func (db *Database) buildCreate() string {
	var query bytes.Buffer
	query.WriteString(db.buildCTE())
	query.WriteString("INSERT INTO ")

	// Model only
	if len(db.tables) != 1 {
		db.panicLog(fmt.Sprintf("Unable to infer table name for Create. Number of tables: %d", len(db.tables)))
	}
	// Table (
	query.WriteString(db.tables[0])
	query.WriteString("(")

	// field1,file2,...
	createSize := len(db.updateCreateFields)
	if createSize == 0 {
		db.panicLog("Unable to detect fields for Create")
	}

	query.WriteString(strings.Join(db.updateCreateFields, ","))
	// values($1,..$n) place holders
	query.WriteString(") VALUES (")
	for i := 0; i < createSize; i++ {
		query.WriteString("$")
		query.WriteString(strconv.Itoa(db.varCount))
		db.varCount++
		if i != createSize-1 {
			query.WriteString(",")
		}
	}

	query.WriteString(") ")
	query.WriteString(db.buildReturning())
	query.WriteString(";")

	qs := query.String()
	db.printLog(qs)
	return qs
}
247205
func createTable(db *sql.DB, tableName, stmt string) error {
	exists, err := TableExists(db, tableName)
	if err != nil {
		return err
	}

	if !exists {
		log.Infof(`Creating the "%s" table.`, tableName)
		_, err = db.Exec(stmt)
		if err != nil {
			return err
		}
	} else {
		log.Tracef(`Table "%s" exists.`, tableName)
	}

	return err
}
721056
func (db *Database) Create() error {
	resp := &struct {
		Error  string `json:"error"`
		Reason string `json:"reason"`
		Ok     bool   `json:"ok"`
	}{}

	body, err := db.Req.Put("")
	err = json.Unmarshal(body, resp)
	if err != nil {
		return err
	}

	if resp.Error != "" {
		return errors.New(resp.Error + " " + resp.Reason)
	}
	if !resp.Ok {
		return errors.New("Couch returned failure when creating [" + db.Name + "]")
	}

	return nil
}
637952
func (b *BaseBuilder) CreateIndex(table, name string, cols ...string) *Query {
	sql := fmt.Sprintf("CREATE INDEX %v ON %v (%v)",
		b.db.QuoteColumnName(name),
		b.db.QuoteTableName(table),
		b.quoteColumns(cols))
	return b.NewQuery(sql)
}
233587
func (c *fischers) Create(fischer *v1alpha1.Fischer) (result *v1alpha1.Fischer, err error) {
	result = &v1alpha1.Fischer{}
	err = c.client.Post().
		Resource("fischers").
		Body(fischer).
		Do().
		Into(result)
	return
}
842444
func (d *Dataset) sql(table, dbType string) *Exportable {
	b := newBuffer()

	tableSQL, columnTypes, columnValues := d.createTable(table, dbType)
	b.WriteString(tableSQL)

	reg, _ := regexp.Compile("[']")
	// inserts
	for i := range d.data {
		b.WriteString("INSERT INTO " + table + " VALUES(" + strconv.Itoa(i+1) + ", ")
		for j, col := range d.headers {
			asStr := d.asString(columnValues[col][i])
			if isStringColumn(columnTypes[col]) {
				b.WriteString("'" + reg.ReplaceAllString(asStr, "''") + "'")
			} else if strings.HasPrefix(columnTypes[col], "TIMESTAMP") {
				if dbType == typeMySQL {
					b.WriteString("CONVERT_TZ('" + asStr[:10] + " " + asStr[11:19] + "', '" + asStr[len(asStr)-6:] + "', 'SYSTEM')")
				} else {
					b.WriteString("'" + asStr + "'") // simpler with Postgres
				}
			} else {
				b.WriteString(asStr)
			}
			if j < len(d.headers)-1 {
				b.WriteString(", ")
			}
		}
		b.WriteString(");\n")
	}
	b.WriteString("\nCOMMIT;\n")

	return newExportable(b)
}
611163
func (c *ColumnMap) SetSqlCreate(s string) *ColumnMap {
	c.createSql = s
	return c
}
620474
func (d MySQLDialect) CreateTableSuffix() string {
	return fmt.Sprintf(" engine=%s charset=%s", d.Engine, d.Encoding)
}
644280
func (m *Sqlbridge) parseCreate() (*SqlCreate, error) {

	req := NewSqlCreate()
	m.Next() // Consume CREATE token
	req.Raw = m.l.RawInput()

	if m.Cur().T == lex.TokenOr {
		m.Next() // Consume OR
		if m.Next().T != lex.TokenReplace {
			return nil, m.ErrMsg("Expected CREATE OR REPLACE")
		}
		req.OrReplace = true
	}
	// CREATE {DATABASE|SCHEMA|TABLE|VIEW|SOURCE|CONTINUOUSVIEW} <identity>
	switch m.Cur().T {
	case lex.TokenTable, lex.TokenSource, lex.TokenDatabase, lex.TokenSchema:
		req.Tok = m.Next()
	case lex.TokenView, lex.TokenContinuousView:
		req.Tok = m.Next()
		if m.Cur().T != lex.TokenIdentity {
			return nil, m.ErrMsg("Expected CREATE [OR REPLACE] {VIEW|CONTINIOUSVIEW} <identity> AS <select_stmt>")
		}
		req.Identity = m.Next().V

		// Grab remainder which will be SELECT (we have already lexed AS)
		selSQL, _ := m.l.Remainder()

		if m.Next().T != lex.TokenAs {
			return nil, m.ErrMsg("Expected CREATE [OR REPLACE] {VIEW|CONTINIOUSVIEW} <identity> AS <select_stmt>")
		}
		if m.Cur().T != lex.TokenSelect {
			return nil, m.ErrMsg("Expected CREATE [OR REPLACE] {VIEW|CONTINIOUSVIEW} <identity> AS <select_stmt>")
		}

		sel, err := ParseSqlSelect(selSQL)
		if err != nil {
			return nil, err
		}
		req.Select = sel
		return req, nil
	default:
		return nil, m.ErrMsg("Expected view, table, source, schema, database, continuousview for CREATE got")
	}

	// [IF NOT EXISTS]
	if m.Cur().T == lex.TokenIf {
		m.Next() // Consume IF
		if m.Next().T != lex.TokenNegate {
			return nil, m.ErrMsg("Expected CREATE {TABLE|SCHEMA|DATABASE} IF NOT EXISTS <identity>")
		}
		if m.Next().T != lex.TokenExists {
			return nil, m.ErrMsg("Expected CREATE {TABLE|SCHEMA|DATABASE} IF NOT EXISTS <identity>")
		}
		req.IfNotExists = true
	}

	switch m.Cur().T {
	case lex.TokenTable, lex.TokenIdentity:
		req.Identity = m.Next().V
	default:
		return nil, m.ErrMsg("Expected identity after CREATE (TABLE|VIEW|SOURCE|SCHEMA|DATABASE) ")
	}

	switch req.Tok.T {
	case lex.TokenTable:
		discardComments(m)
		if m.Cur().T != lex.TokenLeftParenthesis {
			return nil, m.ErrMsg("Expected (cols) ")
		}
		m.Next() // consume paren

		// list of columns comma separated
		cols, err := m.parseCreateCols()
		if err != nil {
			u.Error(err)
			return nil, err
		}
		req.Cols = cols

		// ENGINE
		discardComments(m)
		if strings.ToLower(m.Cur().V) != "engine" {
			return nil, m.ErrMsg("Expected (cols) ENGINE ... ")
		}
		engine, err := ParseWith(m.SqlTokenPager)
		if err != nil {
			return nil, err
		}
		req.Engine = engine
	case lex.TokenSource:
		// just with
	case lex.TokenSchema:
		// just with for now
	default:
		return nil, fmt.Errorf("not implemented %v", req.Tok.V)
	}

	// WITH
	discardComments(m)
	with, err := ParseWith(m.SqlTokenPager)
	if err != nil {
		return nil, err
	}
	req.With = with

	return req, nil
}
300469
func CreateChangefeedTable(db gorm.DB) error {
	query := db.AutoMigrate(&SQLChange{})
	return query.Error
}