File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed
Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -612,6 +612,7 @@ var (
612612 copyWithCSVRegex = regexp .MustCompile (`(?i)\bCSV\b` )
613613 copyWithHeaderRegex = regexp .MustCompile (`(?i)\bHEADER\b` )
614614 copyDelimiterRegex = regexp .MustCompile (`(?i)\bDELIMITER\s+['"](.)['"]\b` )
615+ copyNullRegex = regexp .MustCompile (`(?i)\bNULL\s+'([^']*)'` )
615616)
616617
617618// handleCopy handles COPY TO STDOUT and COPY FROM STDIN commands
@@ -768,6 +769,12 @@ func (c *clientConn) handleCopyIn(query, upperQuery string) error {
768769 }
769770 hasHeader := copyWithCSVRegex .MatchString (upperQuery ) && copyWithHeaderRegex .MatchString (upperQuery )
770771
772+ // Parse NULL string option (e.g., NULL 'custom-null-value')
773+ nullString := "\\ N" // Default PostgreSQL null representation
774+ if m := copyNullRegex .FindStringSubmatch (query ); len (m ) > 1 {
775+ nullString = m [1 ]
776+ }
777+
771778 // Get column count for the table
772779 colQuery := fmt .Sprintf ("SELECT * FROM %s LIMIT 0" , tableName )
773780 testRows , err := c .db .Query (colQuery )
@@ -828,7 +835,7 @@ func (c *clientConn) handleCopyIn(query, upperQuery string) error {
828835 args := make ([]interface {}, len (values ))
829836 for i , v := range values {
830837 placeholders [i ] = "?"
831- if v == "\\ N" || v == "" {
838+ if v == nullString || v == "\\ N" || v == "" {
832839 args [i ] = nil
833840 } else {
834841 args [i ] = v
You can’t perform that action at this time.
0 commit comments