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

Beware with queries returning several __id__ #8

Open
theobat opened this issue Dec 2, 2016 · 0 comments
Open

Beware with queries returning several __id__ #8

theobat opened this issue Dec 2, 2016 · 0 comments

Comments

@theobat
Copy link

theobat commented Dec 2, 2016

So basically pg-live-query adds id and rev to all the tables (if not already present) and the watching logic relies on the idea that your custom query will only track one id field (if any, otherwise the one added is the one of the main from table).

Actually this query (the one in the readme) should not work (I tried with a very similar and indeed it did fail with a mesage like "column id is ambiguous"):

        SELECT
            *
        FROM
            users u JOIN
            logins l ON
                l.user_id = u.id
        WHERE
            l.date > '2016-01-01'

To get a slightly better understanding look at this part of the code:
https://github.com/nothingisdead/pg-live-query/blob/master/watcher.js#L271
Many subsequent call to alias q in this sql query use the id field which does not mean anything if there are multiple of them. And there are multiple of them if your query results in multiple of them.

@nothingisdead, how do you think this could be solved ? I can think of two main solutions, either meta columns are prefixed with their table names (but that would require a bunch of changes in many places in the code) or the meta olumns are aliased in the "magic" query in the watcher but I can't see how that would be possible given an arbitrary sql command (some kind of filter ?).

As long as this remains that way, beware of queries with multiple id columns beeing returned

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant