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

Flag to override DB schema per query #270

Closed
neilotoole opened this issue Jun 21, 2023 · 6 comments
Closed

Flag to override DB schema per query #270

neilotoole opened this issue Jun 21, 2023 · 6 comments

Comments

@neilotoole
Copy link
Owner

Is your feature request related to a problem? Please describe.

See this comment.

Given an existing source, it would be handy to be able to switch the schema on a per-query basis.

For example, given a source @db1:

$ sq add 'postgres://sakila:p_ssW0rd@localhost/sakila' --handle @db1

It should be possible to switch the schema for a single query, e.g.

$ sq --schema customer1 '.customers'

This would probably work by mutating the source location before execution, such that the effective location would be:

postgres://sakila:p_ssW0rd@localhost/sakila?search_path=customer1
@neilotoole
Copy link
Owner Author

This has been addressed in v0.43.0.

@c-nv-s: I think these changes should help with the friction described in this comment? I'd love some feedback.

@neilotoole neilotoole self-assigned this Nov 19, 2023
@c-nv-s
Copy link

c-nv-s commented Nov 19, 2023

thanks neil! so far this is just wonderful. can't see any bugs with the feature.
has made sq soo much more flexible

@neilotoole
Copy link
Owner Author

Thanks @c-nv-s, I much appreciate the feedback! Note as well that the --src.schema flag has got shell/tab completion, let me know if that works for you as expected.

You other feature request, #143 , is slowly bubbling toward the top of the list 😉

@c-nv-s
Copy link

c-nv-s commented Nov 19, 2023

the tab completion for --src.schema doesn't work for me likely because I have another script that takes over my shell autocomplete and git folder status reporting etc. I'll get around to checking it in a vanilla bash terminal another time to confirm.
for the meantime I just get a list of the available schemas with sq sql --exec 'select *from pg_namespace where nspowner = current_user::regrole;' then select from there as needed.

I am eternally grateful for this tool, and once ticket feature 143 is in it will literally be like a christmas gift for my workflow, I will likely abandon the psql cli completely.

@neilotoole
Copy link
Owner Author

neilotoole commented Nov 20, 2023

@c-nv-s Well... if you haven't experienced the shell completion yet, it truly will be like christmas. The completion is... extensive. I have a secret goal of making sq's shell completion the best of any CLI anywhere. I like to think it's already pretty close. Almost every command/flag has some form of completion. I implore you, give it a try! 🙏

src-schema-shell-completion

@neilotoole
Copy link
Owner Author

@c-nv-s: one more thing... The just-released v0.44.0 has got a new mode for sq inspect that lists schemas (and catalogs). It might be of use for your workflow. See the docs.

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

2 participants