Transpile Any SQL to PostgreSQL Dialect
gitlab.com
gitlab.com
Tried this tool: go run gitlab.com/dalibo/transqlate@v0.1-beta.2
select TRUNC(SYSDATE, 'month') from dual
-- TRANSLATION ERROR at +1:8: unsupported date format: "month" rule="replace trunc() by date_trunc()" select DATE_TRUNC('month', LOCALTIMESTAMP)exit status 1
Also, at least, it would set the latest git tag, currently command from Readme.md doesn't work:
go run gitlab.com/dalibo/transqlate@latest
go: gitlab.com/dalibo/transqlate@latest: module gitlab.com/dalibo/transqlate@latest found (v0.0.0), but does not contain package gitlab.com/dalibo/transqlate
latest should point to v0.1-beta.2
Prompt:
translate the SQL statement "select TRUNC(SYSDATE, 'month') from dual" to a PostgreSQL dialect
Response (formatting removed): Here is the equivalent SQL statement in PostgreSQL for "select TRUNC(SYSDATE, 'month') from dual" in Oracle:
SELECT DATE_TRUNC('month', CURRENT_DATE) AT TIME ZONE 'UTC'
Use code with caution.
In PostgreSQL:
DATE_TRUNC is the function used to truncate a date value to a specified unit.
CURRENT_DATE is a function that returns the current date.
AT TIME ZONE 'UTC' is used to specify that the truncation should be done in Coordinated Universal Time (UTC). This is optional, but it's a good practice to be explicit about the time zone to avoid any ambiguity.
The dual table is a dummy table specific to Oracle that is used in simple SQL statements.
PostgreSQL doesn't require a table reference in this case.Hell: a friend of mine claims he asked Claude (using some plug-in in his IDE) to port his app from Firebase all the way to PostgreSQL and it just did it... and it mostly worked well enough to save him a ton of time typing and looking up syntax for stuff, and I think it is now in production?
I do agree, though--and maybe this was your core point--that maybe this "let's ask Gemini" comment should be left by someone who would also know if the answer was correct rather than just saying "no clue but". Although, honestly, even having the output seems useful here (and again: I am someone constantly unhappy about people asking questions they can Google and other such filler content).
In now interested in your friends setup. Do you have more details?
An LLM based solution can be correct but won’t be consistent.
I would much rather a tool be consistent and always incorrect in the same way than inconsistent and sometimes correct. I can create test cases and correct the underlying code. I can’t do that with an LLM
No disagreement. My point is that it's impractically hard to build especially given the scope and complexity of the SQL dialects of major databases.
https://www.postgresql.org/docs/current/datatype-datetime.ht...
> PostgreSQL endeavors to be compatible with the SQL standard definitions for typical usage. However, the SQL standard has an odd mix of date and time types and capabilities...
> Although the date type cannot have an associated time zone, the time type can.
(emphasis mine)
> To address these difficulties, we recommend using date/time types that contain both date and time when using time zones.
turbot compiles their steampipe plugins in this way. Example: https://github.com/turbot/steampipe-plugin-net
https://docs.evidence.dev/core-concepts/data-sources
https://news.ycombinator.com/item?id=35645464
I whish the implied ETL step was even clearer from the homepage - it's not really feasible for us to dump entire tables to the dev machines for working with production data - but it is an interesting concept.
JOOQ also do that, but it is in JAVA.
We're studying JOOQ from afar, with the ambition of getting closer to its functional coverage.
Tools like this are helpful for:
- Rendering SQL in a consistent way, eg for snapshot testing
- Testing SQL business logic in CI against a dialect with less heavyweight dependencies
- Applying AST transformations to take advantage of dialect-specific optimizations
Substrait comes close, but I haven't found a Postgres Substrait producer. Are there any projects working on this?
> more source dialects : mysql, mssql, sybase, etc.
[1] https://babelfishpg.org/ [2] https://github.com/babelfish-for-postgresql/babelfish_extens...
One company, CompilerWorks actually had tools that transpiled many SQL dialects. They were bought by Google https://www.crunchbase.com/acquisition/google-acquires-compi...
PRQL (higher-level abstraction language for SQL)
HN Article, PRQL:
https://news.ycombinator.com/item?id=36866861
Google search, site: GitHub, "SQL Transpiler":
https://www.google.com/search?q=site%3Agithub.com+%22SQL+Tra...
GitHub general list of open-source Transpilers:
I wound up writing a very ad-hoc C++ program that would parse a base SQL file and generate the appropriate DB2 and MariaDB dialect versions. Not flexible enough for reuse but it got the job done.
Is there any standardized AST for SQL?