MCPcopy Create free account
hub / github.com/dolthub/doltgresql / nodeCopyFrom

Function nodeCopyFrom

server/ast/copy_from.go:28–79  ·  view source on GitHub ↗

nodeCopyFrom handles *tree.CopyFrom nodes.

(ctx *Context, node *tree.CopyFrom)

Source from the content-addressed store, hash-verified

26
27// nodeCopyFrom handles *tree.CopyFrom nodes.
28func nodeCopyFrom(ctx *Context, node *tree.CopyFrom) (vitess.Statement, error) {
29 if node == nil {
30 return nil, nil
31 }
32 if node.Options.CopyFormat == tree.CopyFormatBinary {
33 return nil, errors.Errorf("COPY FROM does not support format BINARY")
34 }
35
36 // We start by creating a stub insert statement for the COPY FROM statement, which we will use to build a basic
37 // INSERT plan for. At runtime we will swap out the bogus row values for our actual data read from STDIN.
38 var columns []vitess.ColIdent
39 if len(node.Columns) > 0 {
40 columns = make([]vitess.ColIdent, len(node.Columns))
41 for i := range node.Columns {
42 columns[i] = vitess.NewColIdent(string(node.Columns[i]))
43 }
44 }
45
46 tableName, err := nodeTableName(ctx, &node.Table)
47 if err != nil {
48 return nil, err
49 }
50
51 stubValues := make(vitess.Values, 1)
52 stubValues[0] = make(vitess.ValTuple, len(columns))
53 for i := range columns {
54 stubValues[0][i] = &vitess.NullVal{}
55 }
56
57 return vitess.InjectedStatement{
58 Statement: pgnodes.NewCopyFrom(
59 node.Table.Catalog(),
60 doltdb.TableName{
61 Name: node.Table.Object(),
62 Schema: node.Table.Schema(),
63 },
64 node.Options,
65 node.File,
66 node.Stdin,
67 node.Columns,
68 &vitess.Insert{
69 Action: vitess.InsertStr,
70 Table: tableName,
71 Columns: columns,
72 Rows: &vitess.AliasedValues{
73 Values: stubValues,
74 },
75 },
76 ),
77 Children: nil,
78 }, nil
79}

Callers 1

ConvertFunction · 0.85

Calls 5

nodeTableNameFunction · 0.85
ErrorfMethod · 0.65
CatalogMethod · 0.65
ObjectMethod · 0.65
SchemaMethod · 0.65

Tested by

no test coverage detected