timeofday() must return PG-shaped text like "Tue Jun 09 13:17:57.627882 2026 America/Los_Angeles" — the old mapping to a nonexistent scalar "current_timestamp"() was a hard Catalog Error.
(t *testing.T)
| 122 | // "Tue Jun 09 13:17:57.627882 2026 America/Los_Angeles" — the old mapping to a |
| 123 | // nonexistent scalar "current_timestamp"() was a hard Catalog Error. |
| 124 | func TestCompatTransforms_Timeofday(t *testing.T) { |
| 125 | db, err := sql.Open("duckdb", ":memory:") |
| 126 | if err != nil { |
| 127 | t.Fatalf("open duckdb: %v", err) |
| 128 | } |
| 129 | defer func() { _ = db.Close() }() |
| 130 | if err := initPgCatalog(db, processStartTime, processStartTime, "dev", "dev"); err != nil { |
| 131 | t.Fatalf("initPgCatalog: %v", err) |
| 132 | } |
| 133 | tr := transpiler.New(transpiler.Config{}) |
| 134 | // PG abbreviates the zone; DuckDB %Z yields the zone name — accepted |
| 135 | // approximation, so the trailing zone field is just "non-empty". |
| 136 | shape := regexp.MustCompile(`^[A-Z][a-z]{2} [A-Z][a-z]{2} \d{2} \d{2}:\d{2}:\d{2}\.\d{6} \d{4} \S+`) |
| 137 | for _, q := range []string{`SELECT timeofday()`, `SELECT pg_catalog.timeofday()`} { |
| 138 | res, err := tr.Transpile(q) |
| 139 | if err != nil { |
| 140 | t.Fatalf("transpile %q: %v", q, err) |
| 141 | } |
| 142 | var got string |
| 143 | if err := db.QueryRow(res.SQL).Scan(&got); err != nil { |
| 144 | t.Fatalf("exec %q (transpiled %q): %v", q, res.SQL, err) |
| 145 | } |
| 146 | if !shape.MatchString(got) { |
| 147 | t.Errorf("%q = %q, want PG timeofday() shape", q, got) |
| 148 | } |
| 149 | } |
| 150 | // DuckLake mode: the macro lives in memory.main and must be qualified. |
| 151 | dlRes, err := transpiler.New(transpiler.Config{DuckLakeMode: true}).Transpile(`SELECT timeofday()`) |
| 152 | if err != nil { |
| 153 | t.Fatalf("transpile DuckLake timeofday: %v", err) |
| 154 | } |
| 155 | if !strings.Contains(dlRes.SQL, "memory.main.timeofday") { |
| 156 | t.Errorf("DuckLake transpile = %q, want memory.main.timeofday qualification", dlRes.SQL) |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | func TestCompatTransforms_JSONTypeofVocabulary(t *testing.T) { |
| 161 | runTransformCases(t, []transformCase{ |