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

Change PostGis Table name #890

Open
geoteixeira opened this issue Jul 18, 2023 · 5 comments
Open

Change PostGis Table name #890

geoteixeira opened this issue Jul 18, 2023 · 5 comments

Comments

@geoteixeira
Copy link

Hello
I have a project running on kart.
The data is in postgis, now i need to change the postgis table name. I have looked into kart and it shows me the path to the working copy location but i cannot edit it. Any help? Thanks

@geoteixeira
Copy link
Author

I mean i can change the postgis table name, however when i then try to pull/push changes from one repository to other it shows error. Writing the table name back to original sintax, it will work fine again.

@olsen232
Copy link
Collaborator

Can you share the error you are seeing?

@geoteixeira
Copy link
Author

Hi here it is:

127: Impossível localizar o procedimento especificado.
From X:/CMC/INFO_GEOREFERENCIADA/POLICIA MUNICIPAL/TOPONIMIA NUMEROS POLICIA/Versionamento_Numeros_Policia_OS/.kart

  • branch main -> FETCH_HEAD
    Traceback (most recent call last):
    File "sqlalchemy\engine\base.py", line 1900, in execute_context
    File "sqlalchemy\engine\default.py", line 736, in do_execute
    psycopg2.errors.UndefinedTable: relation "numeros_policia_landbase.numeracao_policia" does not exist
    LINE 1: SELECT obj_description(('numeros_policia_landbase.numeracao
    ...
    ^
    The above exception was the direct cause of the following exception:
    Traceback (most recent call last):
    File "kart_cli.py", line 4, in
    File "kart\cli.py", line 406, in entrypoint
    File "click\core.py", line 1130, in call
    File "click\core.py", line 1055, in main
    File "kart\cli_util.py", line 72, in invoke
    File "click\core.py", line 1657, in invoke
    File "click\core.py", line 1404, in invoke
    File "click\core.py", line 760, in invoke
    File "click\decorators.py", line 26, in new_func
    File "kart\pull.py", line 104, in pull
    File "click\core.py", line 760, in invoke
    File "click\decorators.py", line 26, in new_func
    File "kart\merge.py", line 361, in merge
    File "kart\context.py", line 101, in check_not_dirty
    File "kart\working_copy.py", line 87, in check_not_dirty
    File "kart\working_copy.py", line 381, in check_not_dirty
    File "kart\tabular\working_copy\base.py", line 428, in is_dirty
    File "kart\tabular\working_copy\base.py", line 449, in diff_repo_to_working_copy
    File "kart\tabular\working_copy\base.py", line 502, in diff_dataset_to_working_copy
    File "kart\tabular\working_copy\base.py", line 519, in diff_dataset_to_working_copy_meta
    File "kart\tabular\working_copy\base.py", line 640, in meta_items
    File "kart\sqlalchemy\adapter\base.py", line 148, in all_v2_meta_items
    File "kart\utils.py", line 25, in wrapper
    File "kart\sqlalchemy\adapter\postgis.py", line 137, in all_v2_meta_items_including_empty
    File "sqlalchemy\orm\session.py", line 1744, in scalar
    File "sqlalchemy\orm\session.py", line 1714, in execute
    File "sqlalchemy\engine\base.py", line 1705, in _execute_20
    File "sqlalchemy\sql\elements.py", line 334, in _execute_on_connection
    File "sqlalchemy\engine\base.py", line 1572, in _execute_clauseelement
    File "sqlalchemy\engine\base.py", line 1943, in _execute_context
    File "sqlalchemy\engine\base.py", line 2124, in handle_dbapi_exception
    File "sqlalchemy\util\compat.py", line 211, in raise

    File "sqlalchemy\engine\base.py", line 1900, in execute_context
    File "sqlalchemy\engine\default.py", line 736, in do_execute
    sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedTable) relation "numeros_policia_landbase.numeracao_policia" does not exist
    LINE 1: SELECT obj_description(('numeros_policia_landbase.numeracao
    ...
    ^
    [SQL: SELECT obj_description((%(table_identifier)s)::regclass, 'pg_class');]
    [parameters: {'table_identifier': 'numeros_policia_landbase.numeracao_policia'}]
    (Background on this error at: https://sqlalche.me/e/14/f405)
    [9116] Failed to execute script 'kart_cli' due to unhandled exception!

@geoteixeira
Copy link
Author

From what i can see it says "numeros_policia_landbase.numeracao_policia" does not exist".
What i did was just changing the name of the destination table, because i do not want to have two tables with same name on postgis database. If i change destination table to origin name it works fine.

@olsen232
Copy link
Collaborator

Ok, I found a bug or a regression - Kart should allow you to rename or delete a table without crashing. It should just detect that table as deleted, and you can commit that change if you want. This works with eg a GPKG working copy, but not with postgres - this is the bug / regression.

Kart does not detect table renames in the working copy - that is, it doesn't find try to detect that a new table with name X is the same as the old table with name Y, by comparing the contents of tables. This is less a bug, more a missing feature. For this reason, renaming any of the tables that Kart has already written the working copy won't work well in Kart: Kart will think you've deleted old table and added a new one, and the history of the old table won't be connected to the new table. This is probably not what you want.

Kart always checks out a table using the name of the Kart dataset - if Kart has stored a dataset numeracao_policia, it will try to create / update a table by that name in the working copy. This might be awkward for you if the working copy is in the same PG database as you originally updated the table from, so you can indeed end up with two tables of the same name. However, Kart has two features to mitigate this:

Firstly, you can configure the working copy schema. Every time you create a Kart repo, you can choose where to put the working copy. If you choose to put the working copy in a PG database, you can select a PG schema. You can choose any schema you like, but kart suggests one called <repository-name>_kart, which shouldn't collide with other tables. "Schema" here means one of the nested namespaces that PG allows you to create ie postgres:<hostname>/<database-name>/<schema>/<table-name>

Secondly, you can, if you so choose, rename the dataset as you import it. Eg
kart import <import-source> <name-of-existing-table-to-import>:<name-of-newly-imported-dataset>

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

2 participants