SQL clause should persist adapted type
See original GitHub issueSee https://github.com/cashapp/sqldelight/issues/2056#issuecomment-713866907.
Currently, if we union two tables with each column having the same java type, the generated query interface will use the underlying java type, as it is possible that each column has a different ColumnAdapter
, so the query implementation wouldn’t be able to know which ColumnAdapter
to use when creating the adapted type when constructing the query interface. Ideally, what we would want is the union to produce the adapted type, iff the ColumnAdapter
for the column in each table are identical.
Example
Status Quo
People.sq
CREATE TABLE children(
birthday TEXT AS java.time.LocalDate
);
CREATE TABLE adults(
birthday TEXT AS java.time.LocalDate
);
birthdays:
SELECT birthday
FROM children
UNION
SELECT birthday
FROM adults;
Birthdays.kt
data class Birthdays(
val birthday: String?
) {
…
}
Database Initialization
test_database(
driver,
Adults.Adapter(birthdayAdapter = LocalDateColumnAdapter()),
Children.Adapter(birthdayAdapter = LocalDateColumnAdapter())
)
Proposal
People.sq
typealias Date = java.time.LocalDate -- Or some other syntax
CREATE TABLE children(
birthday TEXT AS Date
);
CREATE TABLE adults(
birthday TEXT AS Date
);
birthdays:
SELECT birthday
FROM children
UNION
SELECT birthday
FROM adults;
Birthdays.kt
data class Birthdays(
val birthday: java.time.LocalDate?
) {
…
}
Database Initialization
test_database(
driver,
dateAdapter = LocalDateColumnAdapter()
)
Issue Analytics
- State:
- Created 3 years ago
- Comments:8
Top Results From Across the Web
10 Best Practices to Write Readable and Maintainable SQL ...
6. Go for the ANSI-92 JOIN Syntax. …instead of the SQL WHERE Clause for Joining Tables. Even though you can use both a...
Read more >Query Hints (Transact-SQL) - SQL Server - Microsoft Learn
Specifies that aggregations that the query's GROUP BY or DISTINCT clause describes should use hashing or ordering.
Read more >Performance Tuning - Spark 3.3.1 Documentation
Adaptive Query Execution (AQE) is an optimization technique in Spark SQL that makes use of the runtime statistics to choose the most efficient...
Read more >Adaptation of the merge clauses in SQL Server 2005
I am afraid that you will need to re-write all of your MERGE clauses for SQL Server 2005. You can use the 2005...
Read more >Chapter 16 SQL Data Manipulation Language
The HAVING clause can be used to restrict rows. It is similar to the WHERE condition except HAVING can include the aggregate function;...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
yea sounds good. agreed compile time safety is good, i usually err on the side of not making our own sql dialect
Ah gotcha, thanks for the clarification! 😄