Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render unique names for database tables #143

Open
jczuchnowski opened this issue Nov 11, 2020 · 2 comments
Open

Render unique names for database tables #143

jczuchnowski opened this issue Nov 11, 2020 · 2 comments

Comments

@jczuchnowski
Copy link
Member

jczuchnowski commented Nov 11, 2020

Consider a following self-referencing schema:

CREATE TABLE items (
    id INTEGER NOT NULL PRIMARY KEY, 
    name VARCHAR NOT NULL, 
    parent_id INTEGER, 
    CONSTRAINT fk_parent_id FOREIGN KEY (parent_id) REFERENCES items(id)
)

it's possible to create a query like this:

val table = columnSet.table("items")

val id :*: nm :*: parentId :*: _ = table.columns
val id2 :*: nm2 :*: _ :*: _ = table.columns

val selfJoined = select(id ++ nm ++ parentId ++ nm2) from(table join table).on(id2 === parentId)

that will render as:

select items.id, items.name, items.parent_id, items.name from items inner join items on items.id = items.parent_id 

This is incorrect. Instead the PostgresModule#renderRead should generate aliases for the tables so that the query would look something like this:

select i1.id, i1.name, i1.parent_id, i2.name from items as i1 inner join items as i2 on i2.id = i1.parent_id;
@maciejbak85
Copy link
Contributor

I can pick this one

@maciejbak85
Copy link
Contributor

@jczuchnowski while working on this ticket, I should support only postgresql ? and mysql/oracle later ?

maciejbak85 added a commit to maciejbak85/zio-sql that referenced this issue Jan 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants