escapeDataTypeName quotes a data type name appropriately. Handles array types and schema-qualified names. Uses case detection to determine if quoting is needed: - All lowercase names (built-in types or unquoted custom types) are not quoted - Names with uppercase letters (quoted custom types) are quo
(typeName string)
| 1080 | // - All lowercase names (built-in types or unquoted custom types) are not quoted |
| 1081 | // - Names with uppercase letters (quoted custom types) are quoted to preserve case |
| 1082 | func (d *PostgresDatabase) escapeDataTypeName(typeName string) string { |
| 1083 | // Handle array types: preserve the [] suffix |
| 1084 | arraySuffix := "" |
| 1085 | if strings.HasSuffix(typeName, "[]") { |
| 1086 | arraySuffix = "[]" |
| 1087 | typeName = strings.TrimSuffix(typeName, "[]") |
| 1088 | } |
| 1089 | |
| 1090 | // If already quoted (from format_type()), return as-is |
| 1091 | if strings.HasPrefix(typeName, "\"") && strings.HasSuffix(typeName, "\"") { |
| 1092 | return typeName + arraySuffix |
| 1093 | } |
| 1094 | |
| 1095 | // Handle schema-qualified types (e.g., "public.my_type") |
| 1096 | if idx := strings.Index(typeName, "."); idx > 0 { |
| 1097 | schema := typeName[:idx] |
| 1098 | baseType := typeName[idx+1:] |
| 1099 | // Quote each part only if it has uppercase letters |
| 1100 | escapedSchema := schema |
| 1101 | if strings.ToLower(schema) != schema { |
| 1102 | escapedSchema = d.quoteIdentifierIfNeeded(schema) |
| 1103 | } |
| 1104 | escapedType := baseType |
| 1105 | if strings.ToLower(baseType) != baseType { |
| 1106 | escapedType = d.quoteIdentifierIfNeeded(baseType) |
| 1107 | } |
| 1108 | return escapedSchema + "." + escapedType + arraySuffix |
| 1109 | } |
| 1110 | |
| 1111 | // For simple type names, use case detection: |
| 1112 | // - All lowercase: don't quote (built-in types like "integer", or custom types created without quotes) |
| 1113 | // - Has uppercase: quote to preserve case (custom types created with quotes like "UserStatus") |
| 1114 | if strings.ToLower(typeName) == typeName { |
| 1115 | return typeName + arraySuffix |
| 1116 | } |
| 1117 | |
| 1118 | return d.quoteIdentifierIfNeeded(typeName) + arraySuffix |
| 1119 | } |
| 1120 | |
| 1121 | func splitTableName(table string, defaultSchema string) (string, string) { |
| 1122 | schema := defaultSchema |
no test coverage detected