MCPcopy Create free account
hub / github.com/PostHog/duckgres / TestCompatTransforms_Timeofday

Function TestCompatTransforms_Timeofday

server/pg_compat_transforms2_test.go:124–158  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
124func 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
160func TestCompatTransforms_JSONTypeofVocabulary(t *testing.T) {
161 runTransformCases(t, []transformCase{

Callers

nothing calls this directly

Calls 6

NewFunction · 0.92
initPgCatalogFunction · 0.85
TranspileMethod · 0.80
CloseMethod · 0.65
ScanMethod · 0.65
OpenMethod · 0.45

Tested by

no test coverage detected