Skip to content

Commit

Permalink
Add scalar type declarations for some unexposed Postgres types
Browse files Browse the repository at this point in the history
Add text `json` (counterpart to `jsonb`) and base variants of
date/time/interval types.
  • Loading branch information
elprans committed Nov 14, 2024
1 parent 87176c5 commit 02308c5
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 2 deletions.
6 changes: 6 additions & 0 deletions edb/api/types.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,9 @@
00000000-0000-0000-0000-000000000112 std::cal::date_duration

00000000-0000-0000-0000-000000000130 cfg::memory

00000000-0000-0000-0000-000001000001 std::pg::json
00000000-0000-0000-0000-000001000002 std::pg::timestamptz
00000000-0000-0000-0000-000001000003 std::pg::timestamp
00000000-0000-0000-0000-000001000004 std::pg::date
00000000-0000-0000-0000-000001000005 std::pg::interval
6 changes: 6 additions & 0 deletions edb/lib/pg.edgeql
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,9 @@ create index match for std::cal::local_date using std::pg::brin;
create index match for std::cal::local_time using std::pg::brin;
create index match for std::cal::relative_duration using std::pg::brin;
create index match for std::cal::date_duration using std::pg::brin;

create scalar type std::pg::json extending std::anyscalar;
create scalar type std::pg::timestamptz extending std::anycontiguous;
create scalar type std::pg::timestamp extending std::anycontiguous;
create scalar type std::pg::date extending std::anydiscrete;
create scalar type std::pg::interval extending std::anycontiguous;
11 changes: 11 additions & 0 deletions edb/pgsql/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@
('edgedbt', 'date_duration_t'),

s_obj.get_known_type_id('cfg::memory'): ('edgedbt', 'memory_t'),

s_obj.get_known_type_id('std::pg::json'): ('json',),
s_obj.get_known_type_id('std::pg::timestamptz'): ('timestamptz',),
s_obj.get_known_type_id('std::pg::timestamp'): ('timestamp',),
s_obj.get_known_type_id('std::pg::date'): ('date',),
s_obj.get_known_type_id('std::pg::interval'): ('interval',),
}

type_to_range_name_map = {
Expand All @@ -85,6 +91,9 @@
# custom range is a big hassle, and daterange already has the
# correct canonicalization function
('edgedbt', 'date_t'): ('daterange',),
('timestamptz',): ('tstzrange',),
('timestamp',): ('tsrange',),
('date',): ('daterange',),
}

# Construct a multirange map based on type_to_range_name_map by replacing
Expand Down Expand Up @@ -143,6 +152,8 @@

'edgedbt.memory_t': sn.QualName('cfg', 'memory'),
'memory_t': sn.QualName('cfg', 'memory'),

'json': sn.QualName('std::pg', 'json'),
}

pg_tsvector_typeref = irast.TypeRef(
Expand Down
10 changes: 10 additions & 0 deletions edb/schema/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,14 @@
UUID('00000000-0000-0000-0000-000000000112'),
sn.name_from_string('cfg::memory'):
UUID('00000000-0000-0000-0000-000000000130'),
sn.name_from_string('std::pg::json'):
UUID('00000000-0000-0000-0000-000001000001'),
sn.name_from_string('std::pg::timestamptz'):
UUID('00000000-0000-0000-0000-000001000002'),
sn.name_from_string('std::pg::timestamp'):
UUID('00000000-0000-0000-0000-000001000003'),
sn.name_from_string('std::pg::date'):
UUID('00000000-0000-0000-0000-000001000004'),
sn.name_from_string('std::pg::interval'):
UUID('00000000-0000-0000-0000-000001000005'),
}
2 changes: 1 addition & 1 deletion edb/server/dbview/dbview.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1442,7 +1442,7 @@ cdef class DatabaseConnectionView:
edb_type_expr = self._db.backend_id_to_name.get(toid)
if edb_type_expr is None:
raise errors.UnsupportedFeatureError(
f"unsupported SQL type in column \"{col}\""
f"unsupported SQL type in column \"{col}\" "
f"with type OID {toid}"
)

Expand Down
2 changes: 1 addition & 1 deletion edb/tools/gen_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def main(*, stdout: bool):
f'\n\n\n'
f'from __future__ import annotations'
f'\n'
f'from typing import * # NoQA'
f'from typing import Type'
f'\n\n\n'
f'import uuid'
f'\n\n'
Expand Down

0 comments on commit 02308c5

Please sign in to comment.