MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / SQL

Method SQL

pkg/sql/ast/sql.go:778–822  ·  view source on GitHub ↗

SQL returns the full SQL string for this CREATE TABLE statement including column definitions, table constraints, INHERITS, PARTITION BY, and table options.

()

Source from the content-addressed store, hash-verified

776// SQL returns the full SQL string for this CREATE TABLE statement including
777// column definitions, table constraints, INHERITS, PARTITION BY, and table options.
778func (c *CreateTableStatement) SQL() string {
779 if c == nil {
780 return ""
781 }
782 sb := getBuilder()
783 defer putBuilder(sb)
784 sb.WriteString("CREATE ")
785 if c.Temporary {
786 sb.WriteString("TEMPORARY ")
787 }
788 sb.WriteString("TABLE ")
789 if c.IfNotExists {
790 sb.WriteString("IF NOT EXISTS ")
791 }
792 sb.WriteString(c.Name)
793 sb.WriteString(" (")
794
795 parts := make([]string, 0, len(c.Columns)+len(c.Constraints))
796 for _, col := range c.Columns {
797 col := col // G601: Create local copy to avoid memory aliasing
798 parts = append(parts, columnDefSQL(&col))
799 }
800 for _, con := range c.Constraints {
801 con := con // G601: Create local copy to avoid memory aliasing
802 parts = append(parts, tableConstraintSQL(&con))
803 }
804 sb.WriteString(strings.Join(parts, ", "))
805 sb.WriteString(")")
806
807 if len(c.Inherits) > 0 {
808 sb.WriteString(" INHERITS (")
809 sb.WriteString(strings.Join(c.Inherits, ", "))
810 sb.WriteString(")")
811 }
812
813 if c.PartitionBy != nil {
814 fmt.Fprintf(sb, " PARTITION BY %s (%s)", c.PartitionBy.Type, strings.Join(c.PartitionBy.Columns, ", "))
815 }
816
817 for _, opt := range c.Options {
818 fmt.Fprintf(sb, " %s=%s", opt.Name, opt.Value)
819 }
820
821 return sb.String()
822}
823
824// SQL returns the full SQL string for this CREATE INDEX statement including
825// the UNIQUE modifier, IF NOT EXISTS, USING method, column list, and WHERE predicate.

Callers 5

TestTableConstraintSQLFunction · 0.95
TestNilSQLFunction · 0.95

Calls 5

getBuilderFunction · 0.85
putBuilderFunction · 0.85
columnDefSQLFunction · 0.70
tableConstraintSQLFunction · 0.70
StringMethod · 0.45

Tested by 5

TestTableConstraintSQLFunction · 0.76
TestNilSQLFunction · 0.76