question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Postgres: support for timestamp precision

See original GitHub issue

DBeaver currently does not support setting precision for timestamp columns. Additionally, it creates incorrect DDL code for tables that contain timestamp columns with precision other than default.

For example, I have a table like this:

CREATE TABLE public.dates
(
    id integer NOT NULL,
    ts timestamp without time zone,
    ts0 timestamp(0) without time zone,
    ts1 timestamp(1) without time zone,
    ts6 timestamp(6) without time zone,
    CONSTRAINT dates_pk PRIMARY KEY (id)
)

DBeaver creates this DDL for the table:

CREATE TABLE public.dates (
	id int4 NOT NULL,
	ts timestamp NULL,
	ts0 timestamp NULL,
	ts1 timestamp NULL,
	ts6 timestamp NULL,
	CONSTRAINT dates_pk PRIMARY KEY (id)
);

As you can see the precision definitions are lost. Precision can be seen in the Columns tab of a table in the Scale column - it can even be edited but DBeaver fails to create correct DDL when trying to persist the changes, it always lacks any precision definition:

ALTER TABLE public.dates ALTER COLUMN ts6 TYPE timestamp USING ts6::timestamp;

I think we would need support for precision in timestamp columns. As far as I can see there is no practical difference between timestamp and timestamp(6) columns but Postgres keeps the distinction in the table definition nevertheless and it would be good if DBeaver also did that.

I think the same issue applies to time and interval data types since they also accept precision parameter - but I haven’t done any tests on them.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:17 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
LonwoLonwocommented, Sep 16, 2020

DDL changed for data types timestamp… and for time. 6 set as default (not shown)

0reactions
lvanderlaatcommented, Apr 12, 2021

@lvanderlaat you can create another enhancement ticket for this. as I can see in documentation, time and timestamp data types have precision, not scale as parameters.

@LonwoLonwo that’s is exactly my point. Somehow, the precision parameter for timestamp ended up in “Scale”. I will create the new ticket.

Thanks again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation: 15: 8.5. Date/Time Types - PostgreSQL
Precision can be specified for time , timestamp , and interval types, and can range from 0 to 6. If no precision is...
Read more >
Timestamp resolution - postgresql - Stack Overflow
By default, PostgreSQL stores timestamps at the maximum possible precision. If I were in your shoes, I might use a different default for...
Read more >
Time, TIMETZ, Timestamp and TimestampTZ in PostgreSQL
TIMESTAMP and TIMESTAMPTZ supports microsecond precision. However, there is an option for “rounding” of fractional digits for the seconds ...
Read more >
What value should I choose as length for timestamp without ...
It's not the "length", it's the precision of the timestamp, so it controls the fractional seconds (milliseconds, microseconds) you can store ...
Read more >
Understanding PostgreSQL Timestamp Data Types
Understanding PostgreSQL Timestamp Data Types · SELECT typname, typlen FROM pg_type WHERE typname ~ '^timestamp'; · typname | typlen -------------+-------- ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found