func (t *SubQuery) TableString(c *Context) string {
	alias := c.Alias(t)
	if len(alias) > 0 {
		alias = ` ` + alias
	}
	sql, v := t.query.getSQL(SQLBuilder{Context: c.clone(AliasGenerator())}, true)
	c.Add(v...)
	return getSubQuerySQL(sql) + alias
}
TableString implements Source
package qb
import (
	"strconv"
	"strings"
)
type Driver interface {
	ValueString(int) string
	BoolString(bool) string
	EscapeCharacter() string
	UpsertSQL(*Table, []Field, Query) (string, []interface{})
	IgnoreConflictSQL(*Table, []Field) (string, []interface{})
	LimitOffset(SQL, int, int)
	Returning(SQLBuilder, Query, []Field) (string, []interface{})
	TypeName(DataType) string
	Override() OverrideMap
}
type Query interface {
	SQL(b SQLBuilder) (string, []interface{})
}
type Alias interface {
	Get(Source) string
}
type Source interface {
	TableString(*Context) string
	aliasString() string
}
type Table struct {
	Name   string
	Alias  string
	Escape bool
}
func (t *Table) TableString(c *Context) string {
	alias := c.Alias(t)
	if len(alias) > 0 {
		alias = ` AS ` + alias
	}
	name := t.Name
	if t.Escape {
		ec := c.Driver.EscapeCharacter()
		name = ec + name + ec
	}
	return name + alias
}
func (t *Table) aliasString() string {
	if t.Alias != `` {
		return t.Alias
	}
	parts := strings.Split(t.Name, `.`)
	return strings.ToLower(parts[len(parts)-1][0:1])
}
func (t *Table) Select(f []Field) *SelectBuilder {
	return NewSelectBuilder(f, t)
}
func (t *Table) Delete(c1 Condition, c ...Condition) Query {
	return DeleteBuilder{t, append(c, c1)}
}
func (t *Table) Update() *UpdateBuilder {
	return &UpdateBuilder{t, nil, nil}
}
func (t *Table) Insert(f []Field) *InsertBuilder {
	q := InsertBuilder{table: t, fields: f}
	return &q
}
type CTE struct {
	query SelectQuery
	F     []Field
}
func newCTE(q SelectQuery, fields []*Field) *CTE {
	cte := &CTE{query: q}
	assignFields(&cte.F, cte, q, fields)
	return cte
}
func (cte *CTE) aliasString() string {
	return `ct`
}
func (cte *CTE) TableString(c *Context) string {
	alias := c.Alias(cte)
	if len(alias) > 0 {
		alias = ` ` + alias
	}
	return c.cteName(cte) + alias
}
func (cte *CTE) With(b SQLBuilder) string {
	s, _ := cte.query.getSQL(b, true)
	return b.Context.cteName(cte) + ` AS ` + getSubQuerySQL(s)
}
func (cte *CTE) Select(f ...Field) *SelectBuilder {
	return NewSelectBuilder(f, cte)
}
type SubQuery struct {
	query SelectQuery
	F     []Field
}
func newSubQuery(q SelectQuery, fields []*Field) *SubQuery {
	sq := &SubQuery{query: q}
	assignFields(&sq.F, sq, q, fields)
	return sq
}
func assignFields(dest *[]Field, parent Source, q SelectQuery, fields []*Field) {
	if fields != nil && len(q.Fields()) != len(fields) {
		panic(`Field count in CTE/SubQuery doesn't match`)
	}
	for k := range q.Fields() {
		f := &TableField{Name: `f` + strconv.Itoa(k), Parent: parent}
		*dest = append(*dest, f)
		if fields != nil {
			*fields[k] = f
		}
	}
}