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

Select with list of fields from an array doesn't work with fields including a dot #188

Closed
mohe2015 opened this issue Jun 10, 2021 · 7 comments

Comments

@mohe2015
Copy link

Code similar to the following doesn't work:

sql`SELECT ${sql(["projects.id"])} FROM projects`

because this generates:

SELECT "projects.id" FROM projects;

which is not valid for postgresql

@porsager
Copy link
Owner

Are you trying to select the key id from a json object in the projects column?

@mohe2015
Copy link
Author

mohe2015 commented Jun 17, 2021

No, I'm trying to select the id column from the projects table. So just using the explicit syntax where you specify the table name also.

@mohe2015
Copy link
Author

mohe2015 commented Jun 17, 2021

In theory useful for:
SELECT projects.id, users.id FROM projects, users;
although this doesn't create nice column names so probably not worth it.
Feel free to close.

@porsager
Copy link
Owner

porsager commented Jun 17, 2021

Ah right, of course 👍

There should definitely be a way to do that.. If we make it work as you tried there we'd break anyone with periods in their column names, but I kind of feel that's ok?

@mohe2015
Copy link
Author

I would assume the problem is sql injection but I don't know. The correct way to do this with arbitrary names (excluding ones containing a dot) is SELECT "projects"."id" FROM projects;

I would assume that a dot is such a strange thing in a column name that it should be fine. Should still be noted in the release notes of course.

@mohe2015
Copy link
Author

mohe2015 commented Jun 17, 2021

I don't need this feature currently so if nobody else needs it it may be worth to wait until the dynamic queries feature is more finished and maybe it's then built in there

@ersinakinci
Copy link

I would very much like to see this implemented, as would #731.

Is there a workaround?

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

3 participants