question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SQL clause should persist adapted type

See original GitHub issue

See 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:closed
  • Created 3 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
AlecStrongcommented, Nov 11, 2020

yea sounds good. agreed compile time safety is good, i usually err on the side of not making our own sql dialect

0reactions
veyndancommented, Nov 13, 2020

Ah gotcha, thanks for the clarification! 😄

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found