Help needed in adding the "timestampz" alias for "timestamp with time zone"
See original GitHub issueHey @oguimbal š Thanks for making this and the pg-mem repos- theyāre awesome!
Iām working on adding pg-mem to a personal project and had a few migrations that used timestampz rather than the more verbose timestamp with time zone. I figured this was a good opportunity to give back to the project and add support for timestampz, but Iām afraid Iām a bit lost while trying to implement the type alias.
Iām not sure if Iām going in the right direction, but these are changes Iāve got so far
diff --git a/src/syntax/base.ne b/src/syntax/base.ne
index 486eb66..e504c04 100644
--- a/src/syntax/base.ne
+++ b/src/syntax/base.ne
@@ -147,6 +147,7 @@ kw_cache -> %word {% notReservedKw('cache') %}
kw_cascade -> %word {% notReservedKw('cascade') %}
kw_no -> %word {% notReservedKw('no') %}
kw_timestamp -> %word {% notReservedKw('timestamp') %}
+kw_timestampz -> %word {% notReservedKw('timestampz') %}
kw_cycle -> %word {% notReservedKw('cycle') %}
kw_function -> %word {% notReservedKw('function') %}
kw_returns -> %word {% notReservedKw('returns') %}
diff --git a/src/syntax/create-table.spec.ts b/src/syntax/create-table.spec.ts
index 9b28fe5..ad50d5c 100644
--- a/src/syntax/create-table.spec.ts
+++ b/src/syntax/create-table.spec.ts
@@ -165,6 +165,16 @@ describe('Create table', () => {
}],
});
+ checkCreateTable(['create table "test" (value timestampz)'], {
+ type: 'create table',
+ name: 'test',
+ columns: [{
+ kind: 'column',
+ name: 'value',
+ dataType: { name: 'timestamp with time zone' },
+ }],
+ });
+
checkInvalid('create table"test"(value "timestamp" with time zone)');
checkInvalid('create table"test"(value timestamp with "time" zone)');
With the keyword added, Iām seeing my new test failing, which makes sense considering some form of alias hasnāt been defined:
1) Create table
parses create table "test" (value timestampz):
Parser has not returned the expected AST
+ expected - actual
{
"columns": [
{
"dataType": {
- "name": "timestampz"
+ "name": "timestamp with time zone"
}
"kind": "column"
"name": "value"
}
at Context.<anonymous> (src/syntax/spec-utils.ts:76:26)
at processImmediate (internal/timers.js:461:21)
However I am admittedly lost now š I took a wild guess and added the word to the data_type_date definition, but this clearly isnāt quite right, since it results in the āAmbiguous matchesā test failing, saying there are 2 available options.
diff --git a/src/syntax/base.ne b/src/syntax/base.ne
index 486eb66..e504c04 100644
--- a/src/syntax/base.ne
+++ b/src/syntax/base.ne
@@ -247,6 +248,7 @@ data_type_text
#https://www.postgresql.org/docs/9.5/datatype-datetime.html
data_type_date
-> (%word {% anyKw('timestamp', 'time') %}) (%kw_with | %word {% kw('without') %}) (%word {% kw('time') %}) (%word {% kw('zone') %})
+ | (%word {% kw('timestampz') %})
# | word {% kw('date') %}
# | word {% kw('interval') %}
# | word {% kw('timestamp') %}
I donāt have much experience with ASTs or with moo/nearley, but I think I can get this implemented with a little nudge in the right direction, so any help or info would be much appreciated. Thanks! š
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)

Top Related StackOverflow Question
Fixed with
pg-mem@1.7.7Oh right! I completely lost track of that part.
timestampandtimestamptzworking the same is totally fine for my use case, but I could see that being an issue for other prospective users š¤Iāll keep playing with the repo locally here- Iāll remove the type synonym and see how far I get in implementing support for time zones. Iām sure Iāll have more questions about all that, but I can ask those in another issue to avoid cluttering this one.