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

No support for timestamp precision #1629

Open
Jiia opened this issue Nov 29, 2024 · 0 comments
Open

No support for timestamp precision #1629

Jiia opened this issue Nov 29, 2024 · 0 comments

Comments

@Jiia
Copy link

Jiia commented Nov 29, 2024

It seems that timestamp precision is completely unsupported. This would be a very important feature to support to ensure that the target database has timestamps in the same format and precision as the original database. For example, Mysql 5 has 0 precision timestamps.

Configuration

CAST
  type timestamp
  to timestamptz(0)

Error

KABOOM!
ESRAP-PARSE-ERROR: At
  type timestamp
  to timestamptz(0)
                ^

It's possible to work around, by first migrating with default precision and later manually altering each column:

ALTER TABLE tbl ALTER COLUMN ts TYPE timestamptz(0);

or as a loop:

do $$
declare
t record;
begin
    for t IN select column_name, table_name
            from information_schema.columns
            where data_type = 'timestamp with time zone'
                and table_schema = 'your_schema'
    loop
        execute 'alter table ' || t.table_name || ' alter column ' || t.column_name || ' type timestamptz(0)';
    end loop;
end$$;

do $$
declare
t record;
begin
    for t IN select column_name, table_name
            from information_schema.columns
            where data_type = 'timestamp without time zone'
                and table_schema = 'your_schema'
    loop
        execute 'alter table ' || t.table_name || ' alter column ' || t.column_name || ' type timestamp(0)';
    end loop;
end$$;

EDIT: This has been acknowledged as a missing feature #936 (comment) (back in 2019)

At the moment there's no support in pgloader for giving a typemod on the target data type, so that you. can't do that. So you have to migrate to text as done by default, and then see about using ALTER TABLE to get back to a varchar(2048), unless you want to add a CHECK constraint.

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

1 participant