-
Notifications
You must be signed in to change notification settings - Fork 4
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
Allow parsing from sql file #1
Comments
The script uses |
Thanks! May I ask what WSL is? |
Ah a google search shows pg_dump works on windows. Maybe it needs different params or something. I'll try to figure it out. |
Whoops, didn't see your edit questions. I'll respond to the ones in the history too:
It is designed to run on the same host as the database, so it doesn't really need to authenticate by default. I could work on making it a bit more flexible, but adding a
Yes, it takes the
Python version shouldn't matter as long as it's >3.6. You might need to install the Here's some info on WSL, it's a really great tool: https://docs.microsoft.com/en-us/windows/wsl/about Do you have postgres installed on windows? |
Thank you for your quick and thoughtful answers! |
I didn't share with you the run string I was using because it shows up in the error message. But if you need to see anything, say the word and I'll share here. Muchly appreciate your hard work!!! |
Oh and please don't bother to look at my edit questions because I edit every time I figure something out or eliminate a potential issue. |
Hope I don't side track you by asking what you think of this: https://stackoverflow.com/questions/60549576/set-environment-variable-pgpassword-before-executing-a-command-pg-dump-on-wi |
You can fill in the connection settings, they're on lines 16 and 108. Setting the The error looks like it's just failing to find the command. What does the console output when you enter |
Sorry for delay. Was eating. C:\Python\Python38>where pg_dump |
I just ran this: |
What are your thoughts on this: |
Oh and where in your code should I put this (and of course putting my "postgres" user's pw in there): |
Hey if you want, when I get this finished, happy to send to you so you have a "windows version"! |
Oh and I had filled in the database creds at 108 but on 16 I'm unsure how to do so. Seemed obvious at 108 but not on 16.
Since it is local maybe I should leave out "host=...."? |
Hmm I looked again at pgdumplib and now I"m thinking maybe this is a different, not as well supported pg_dump? Did you look at that page? |
It looks like they might already be included, they might be in the |
Thanks. Looking. I was just reading https://www.postgresql.org/docs/9.1/app-pgdump.html. |
Dangit. Both pages on pg_dump give command line examples but not Python examples. Will keep looking. |
As to the environment variable, unless you use some tool to set it you'll have to set every time you open a new command prompt. The |
Yep! pg_dump.exe is in my bin folder!
|
Ah that's helpful. I'll look at it with new eyes now :-) |
I didn't know about the |
Sadly now I'm getting errors that say
Appears that fcntl is a Unix thing, even though sh is in the windows version and imported fine with pip. |
Here's what a guy on stack overflow said: The fcntl module is just used for locking the pinning file, so assuming you don't try multiple access, this can be an acceptable workaround. Place this module in your sys.path, and it should just work as the official fcntl module. Place this module in your sys.path, and it should just work as the official fcntl module:
|
I think I'm going down the wrong path (rabbit hole) because now it's finding other stuff it wants, like "tty". |
I'll look for other solutions to the "change column order" thing, but focused on windows. |
Just thought of this: |
This looks do-able! Especially given the GUI I use for db management is dBeaver, which will give me SQL for re-creating any of my tables, including foreign keys. A bit more work than your automated tool but at least this will be simple for someone like me, heh!
|
Looks like the output of pg_dump, if I remember correctly DBeaver uses it behind the scenes. I could add a flag to take an input file instead of reading from the command line. |
Ah. Yeah in DBeaver it's called "generate SQL" and you can do it with any table, tables, or whole database. I would imagine a common feature of most modern UIs? I don't know because I haven't played with others except for pgAdmin and ... don't tell... Microsoft Access, heh. I never used one for SQL Server. |
I added a branch that has the option to read an sql file (either from the output of Edit: Oh neat, it looks like you can do this work in dbeaver (dbeaver/dbeaver#9720)! I'm doing it on a larger scale automatically, but for one-off tables it might not be necessary. |
First: THANK YOU for making this! It will save me a HUGE amount of time!
Question: Could my issue be that I'm using Python 3.8 with pip updated all libraries your code imports?
Should I use a specific version of Python?
ERROR REPORT:
C:\Python\Python38>reorder.py -d inventory -n public.tbl_items_to_items id id_session id_child t_part_no t_part_no_parent d_modified b_enabled -f c:\python\python38\logColReorder.txt -m
Traceback (most recent call last):
File "C:\Python\Python38\reorder.py", line 218, in
main()
File "C:\Python\Python38\lib\site-packages\click\core.py", line 829, in call
return self.main(*args, **kwargs)
File "C:\Python\Python38\lib\site-packages\click\core.py", line 782, in main
rv = self.invoke(ctx)
File "C:\Python\Python38\lib\site-packages\click\core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "C:\Python\Python38\lib\site-packages\click\core.py", line 610, in invoke
return callback(*args, **kwargs)
File "C:\Python\Python38\reorder.py", line 198, in main
cols, extras = get_columns(database, schema, table)
File "C:\Python\Python38\reorder.py", line 25, in get_columns
sql_text = get_dump_sql(database, schema, table)
File "C:\Python\Python38\reorder.py", line 15, in get_dump_sql
result = subprocess.run(
File "C:\Python\Python38\lib\subprocess.py", line 489, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\Python\Python38\lib\subprocess.py", line 854, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Python\Python38\lib\subprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
The text was updated successfully, but these errors were encountered: