parseShowCreateRef splits a possibly catalog- and schema-qualified, possibly double-quoted table reference into (catalog, schema, table). Defaults: catalog="" (omitted from filter), schema="main".
(ref string)
| 137 | // double-quoted table reference into (catalog, schema, table). |
| 138 | // Defaults: catalog="" (omitted from filter), schema="main". |
| 139 | func parseShowCreateRef(ref string) (catalog, schema, table string) { |
| 140 | ref = strings.TrimSpace(ref) |
| 141 | dots := findAllUnquotedDots(ref) |
| 142 | |
| 143 | switch len(dots) { |
| 144 | case 0: |
| 145 | // table |
| 146 | schema = "main" |
| 147 | table = unquoteIdent(ref) |
| 148 | case 1: |
| 149 | // schema.table |
| 150 | schema = unquoteIdent(ref[:dots[0]]) |
| 151 | table = unquoteIdent(ref[dots[0]+1:]) |
| 152 | case 2: |
| 153 | // catalog.schema.table |
| 154 | catalog = unquoteIdent(ref[:dots[0]]) |
| 155 | schema = unquoteIdent(ref[dots[0]+1 : dots[1]]) |
| 156 | table = unquoteIdent(ref[dots[1]+1:]) |
| 157 | default: |
| 158 | // Too many parts — treat as plain table name (will likely not match anything) |
| 159 | schema = "main" |
| 160 | table = unquoteIdent(ref) |
| 161 | } |
| 162 | |
| 163 | // Map PostgreSQL "public" schema to DuckDB "main" |
| 164 | if schema == "public" { |
| 165 | schema = "main" |
| 166 | } |
| 167 | return |
| 168 | } |
| 169 | |
| 170 | // stripLeadingSQL strips leading whitespace, line comments (--), and block |
| 171 | // comments (/* ... */) from SQL. Mirrors the logic in hasAnyPrefix. |
no test coverage detected