-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Support precision option in datetime types (PostgreSQL) #6742
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
base: 4.2.x
Are you sure you want to change the base?
Conversation
It adds to PostgreSQL platform support of microseconds for the next types: - DateTimeType - DateTimeImmutableType - DateTimeTzType - DateTimeImmutableTzType Additionally, respects precision in schema introspection.
Why is this distinction necessary? Not only that the type always has precision (whether it's specified explicitly or not), it makes it possible to specify both When the column definition defined by the application and containing |
Because PostgreSQL does it. Column type can be altered from So the mapping here:
Maybe that awkwardness was the reason why in #5961 used a |
In my understanding, the difference between CREATE TABLE test_timestamps (
ts1 TIMESTAMP,
ts2 TIMESTAMP(6)
);
SELECT
column_name,
datetime_precision
FROM information_schema.columns
WHERE table_name = 'test_timestamps'; The above query will produce
They shouldn't be considered different. If they are, it's a bug. Or, more specifically, the default precision of timestamp columns in DBAL is undefined, that's why they may produce a diff. But the point is, this issue needs to be addressed by improving the type system and type comparison logic, not introducing extra type parameters. |
There's no difference between `timestamp` and `timestamp(6)` during introspection anymore.
There hasn't been any activity on this pull request in the past 90 days, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days. |
Despite the CS, the PR is green. What prevent this to be merged? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR seems overloaded: it attempts to address some performance issue, adds a new feature and deprecates the existing API (which isn't allowed in a patch release).
Would it make sense to tackle these issues one by one?
case 'timestamp': | ||
case 'timestamptz': | ||
if ( | ||
preg_match( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see if this could be replaced with $this->parseColumnTypeParameters($completeType)
(introduced in #6933). You will need to rebase on 4.3.x
and retarget the PR.
@@ -11,34 +11,10 @@ | |||
use Exception; | |||
|
|||
/** | |||
* Immutable type of {@see VarDateTimeType}. | |||
* @deprecated Use {@see DateTimeImmutableType} instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this relevant to introducing the support for precision?
@@ -649,6 +649,34 @@ public function testPartitionTable(): void | |||
)); | |||
self::assertSame(1, $partitionsCount); | |||
} | |||
|
|||
public function testTimestampPrecisionComparison(): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this to SchemaManagerTest
. It's fine if for now it will be skipped on all platforms except for Postgres, but we want to be able to reuse this test once the support for precision is added to more platforms.
$offlineTable->addColumn('t_u_tz', Types::DATETIMETZ_MUTABLE, ['precision' => 6]); | ||
|
||
$createTableSQL = <<<'SQL' | ||
CREATE TABLE timestamp_columns_test ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why create this table via SQL if the table is already defined above via the DBAL API?
Summary
The year was 2025... I made yet another try to add support of microseconds to date-time types.
Looks like a really big work on #5961 is abandoned. Sadly. I've reviewed this PR. I think it modifies too many things and attempts to add microseconds everywhere. It reminds me of PHP 6 in trying to add support for Unicode globally.
Let's make things easy!
What it does
It adds to PostgreSQL platform support of microseconds for the next types:
To configure precision (in PostgreSQL documentation it calls "precision," not "scale") of those types, the precision option is available. For backward compatibility, the default precision is zero.
Additionally, it respects precision in schema introspection (fix #6631). In order to distinguish
timestamp
(without precision) andtimestamp(6)
thewithout_precision
platform option was added.VarDateTimeType and VarDateTimeImmutableType
According to description of these types,
DateTime::__construct()
twice slower thenDateTime::createFromFormat()
. I cannot remember the times when it was true. In my tests on PHP 8.1 (which is a lower supported version for 4.x), the constructor is slightly faster.Script:
Result:
What's next