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

Detected enum order is inconsistent #31

Closed
Denhai opened this issue Oct 6, 2023 · 0 comments · Fixed by #32
Closed

Detected enum order is inconsistent #31

Denhai opened this issue Oct 6, 2023 · 0 comments · Fixed by #32

Comments

@Denhai
Copy link
Contributor

Denhai commented Oct 6, 2023

In the database I'm working with, this part is unstable because it doesn't define ORDER BY:

ARRAY(SELECT enumlabel FROM pg_catalog.pg_enum WHERE enumtypid = t.oid)

sql = """
SELECT
pg_catalog.format_type(t.oid, NULL),
ARRAY(SELECT enumlabel
FROM pg_catalog.pg_enum
WHERE enumtypid = t.oid)
FROM pg_catalog.pg_type t
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace
WHERE
t.typtype = 'e'
AND n.nspname = :schema
"""

Examples

SELECT
    enumlabel
FROM
    pg_catalog.pg_enum
WHERE
    enumtypid = 8175864;
         enumlabel
----------------------------
 comment
 findings
 history
 impression_recommendations
 technique

If I include the enumsortorder, it gives a different result:

SELECT
    enumlabel,
    enumsortorder
FROM
    pg_catalog.pg_enum
WHERE
    enumtypid = 8175864
ORDER BY
    enumsortorder;
         enumlabel          | enumsortorder
----------------------------+---------------
 history                    |             1
 technique                  |             2
 findings                   |             3
 comment                    |             4
 impression_recommendations |             5

Performing VACUUM FULL does fix this. I assume that's because it reorganises the underlying postgres structures (ctid)?

Denhai added a commit to Denhai/alembic-postgresql-enum that referenced this issue Oct 6, 2023
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

Successfully merging a pull request may close this issue.

1 participant