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

[bug?] target table field order changed, not like original table #61

Open
roytan883 opened this issue Jun 13, 2019 · 6 comments
Open

[bug?] target table field order changed, not like original table #61

roytan883 opened this issue Jun 13, 2019 · 6 comments
Milestone

Comments

@roytan883
Copy link

My source DB has table like this:

create table share_media_v2.base(
  id                        VARCHAR(64) PRIMARY KEY NOT NULL,
  category                  VARCHAR(64) NOT NULL,
  ct                        TIMESTAMP(3) WITHOUT TIME ZONE NOT NULL DEFAULT LOCALTIMESTAMP(3),
  ut                        TIMESTAMP(3) WITHOUT TIME ZONE NOT NULL DEFAULT LOCALTIMESTAMP(3)
);

after run pgquarrel, I got diff.sql for target DB, but the table fields order has changed to :

CREATE TABLE share_media_v2.base (
category character varying(64) NOT NULL,
ct timestamp(3) without time zone DEFAULT LOCALTIMESTAMP(3) NOT NULL,
id character varying(64) NOT NULL,
ut timestamp(3) without time zone DEFAULT LOCALTIMESTAMP(3) NOT NULL
);

this will lead some code has bug like:

INSERT INTO share_media_v2.base VALUES ('id-1', 'type1');
@eulerto
Copy link
Owner

eulerto commented Jun 13, 2019

@roytan883 this is not a bug. The DDL is correct. You can claim it is a new feature. pgquarrel orders table columns by name to compare columns (of course in the case of new tables it does not need that order). Also, your INSERT should specify the columns to not depend of column order. What if you need to remove a column and add it again (say to change a datatype)? PostgreSQL does not have a command to shift column order.

@eulerto eulerto added this to the v1.0 milestone Jun 13, 2019
@roytan883
Copy link
Author

@eulerto I think at least if the source table is totally new, should keep the original fields order.

remove a column and add it again

I think it is another case.

@roytan883
Copy link
Author

The problem is that:pgquarrel works great, but it can't handle POLICY. So after use diff.sql, I must manually pg_dump source and target DB, and use other diff tools to find POLICY changes. In the case, the fields order is differ, so lots of unnecessary differ show.

@eulerto
Copy link
Owner

eulerto commented Jun 13, 2019

The problem is that:pgquarrel works great, but it can't handle POLICY. So after use diff.sql, I must manually pg_dump source and target DB, and use other diff tools to find POLICY changes. In the case, the fields order is differ, so lots of unnecessary differ show.

I added POLICY support a few days ago (commit ec06f49). This is a different issue.

@roytan883
Copy link
Author

@eulerto So it is a bug?I git clone the latest code, and set policy = true, but still can not get POLICY although it is totally new POLICY in source DB

@eulerto
Copy link
Owner

eulerto commented Jun 14, 2019

@roytan883 open another issue. It is a totally different problem. Please provide a small test case.

eulerto pushed a commit that referenced this issue Sep 6, 2019
ALTER commands have to deal with role names that have uppercase letters.
Those identifiers should be quoted if there is a upppercase letter. It
was pointed out by @rafaelsagastume at PR #61 although I don't use his
patch. I add a small test to exercise this code (indeed, I have to
overhaul tests to exercise more cases than it does nowadays; let's say
it is just a reminder to not forgot uppercase identifier case).
eulerto pushed a commit that referenced this issue Sep 9, 2019
There isn't a way to preserve the original order of attributes in a
CREATE TABLE. This is a feature asked in #61. Let's use alphabetical
order for attributes so tests won't fail.
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