Types
The type system is the product. Columns are strictly, statically typed — a value is never silently reinterpreted at runtime. Where the SQL raises a question of semantics, jed follows PostgreSQL closely.
Every example below is a live database in your browser. Edit the SQL and run it.
Exact decimals
numeric / decimal is exact base-10, not binary floating point. So 0.1 + 0.2 is exactly 0.3, 1.50 equals 1.5 by value, and a value keeps its display scale.
No results yet. Run a query to see output.
Declaring a precision makes a column smaller and faster to scan. A numeric(p,s) column with p of 18 or less is stored as a fixed-width integer — 2 bytes for p ≤ 4, 4 for p ≤ 9, 8 for p ≤ 18 — while a wider or unconstrained numeric column uses a variable-length form. The values
and their behavior are the same either way.
Numeric width_bucket(value, low, high, count) also works at the numeric digit limit:
intermediate calculations can exceed that limit when the final bucket index fits i32.
An integer argument takes a function’s numeric overload when it has one: power(2.0, 3), log(2, 8.0), round(5), sqrt(2) and power(2, 3) all return numeric. This is a deliberate
difference from PostgreSQL, which resolves an integer through double precision: sqrt(2) is 1.414213562373095 in jed and 1.4142135623730951 in PostgreSQL. Write sqrt(x::f64) for the
float version. A float-only function takes a number literal, so sin(1) works and power(x, 3) on
an f64 column returns f64, but an integer or numeric column next to a float still needs a cast
(42883).
double precision is an alias for f64 in column declarations, casts, arrays, and typed
string literals such as DOUBLE PRECISION '1.5'. Both words are bare SQL keywords.
An f32 next to an f64 widens exactly to f64 first, as PostgreSQL widens real to double precision, so the comparison or arithmetic runs at f64. The widened f32 keeps its
binary value: 0.1::f32 = 0.1::f64 is false, because the f32 nearest 0.1 is 0.100000001490116….
The widening is an implicit cast (cast(a as f64) in EXPLAIN (VERBOSE)), so a comparison of an f32 column with an f64 value scans rather than using an index on that column.
round(float, places) rounds half away from zero, with negative places rounding to the left
of the decimal point. A large finite value stays finite when its rounded result fits, and a
rounding unit larger than any finite float produces zero:
No results yet. Run a query to see output.
Integers with defined overflow
Integers are fixed-width (i16, i32, i64) and trap on overflow — there is no silent
wraparound. Adding 1 to the largest i16 raises error 22003:
No results yet. Run a query to see output.
Boolean ⇄ integer casts
Following PostgreSQL, boolean casts to and from int (i32) only, and always with an explicit CAST / :: — never implicitly. true becomes 1 and false becomes 0; an integer becomes false when it is 0 and true for any nonzero value (including negatives):
No results yet. Run a query to see output.
Only i32 is involved: a boolean ⇄ i16 or boolean ⇄ i64 cast is rejected (42804), matching
PostgreSQL’s choice of int4 as the sole boolean-integer cast.
Parsing text into numbers and booleans
An explicit CAST / :: parses a text value into a number or boolean at runtime — i16 / i32 / i64, decimal (with a numeric(p,s) re-scale), f32 / f64, and boolean. The string
is trimmed, a leading sign is accepted, and a boolean follows PostgreSQL’s spellings
(t/true/yes/on/1 …). A malformed string raises 22P02 and an out-of-range integer raises 22003:
No results yet. Run a query to see output.
The type must be named — a bare string never silently becomes a number, so int_col = '42' stays
a type error (42804). Integer and numeric input reads PostgreSQL 16+‘s forms — '0x1F'::int is 31, '1_000'::int is 1000 — but numeric rejects NaN (22P02), since it is always finite.
One exception, as in PostgreSQL: a bare string literal stored into an f32 / f64 column — an INSERT … VALUES cell or an UPDATE … SET value — is read with the float’s input rules, so INSERT INTO t (f) VALUES ('NaN'), ('-Infinity'), (1.5) works. It is how to write NaN and ±Infinity without a cast. A text expression (a text column, 'Inf' || 'inity') is still a type
error (42804).
Float input also accepts signed NaN (+NaN and -NaN); each renders as NaN. Conversion
from text or an exact number to f32 rounds directly to binary32. An explicit intermediate f64 cast can change the answer near a rounding boundary:
No results yet. Run a query to see output.
Parsing text into dates, times, intervals, and bytea
A runtime text value also casts to date, timestamp, timestamptz, interval,
and bytea, using the same input rules as that type’s literal. A malformed date or time raises 22007 and an out-of-range field 22008; a malformed bytea (hex or escape format, see Binary strings) raises 22P02:
No results yet. Run a query to see output.
A timestamp ignores a trailing UTC offset. A timestamptz with an offset is that instant; one without an offset is read in the session time zone, as in PostgreSQL (the panel runs in UTC). Because the result can depend on the session or the current day ('today'::date), an index
expression containing a text cast to date, timestamp, timestamptz, or interval is rejected
(42P17), exactly as in PostgreSQL; text → bytea is fine in an index.
A timestamptz literal such as '2024-01-15 10:30'::timestamptz reads an offset-less string the
same way, in the session time zone (see Time zones), so the literal and the text column cast agree.
jed’s timestamp input is stricter than PostgreSQL’s, the same as for literals: the 'now', 'today', and 'epoch' words are rejected. Interval input reads everything PostgreSQL’s does — units
('1 day 2 hours'), the SQL-standard forms ('1-2' is 1 year 2 mons, '1 1:00' is 1 day 01:00:00), and ISO 8601 ('P1Y2M3DT4H5M6S', 'P2W', 'P0001-02-03T04:05:06'). A
unit-less number takes its unit from its place: seconds at the end ('1 day 2'), days before an
hour or a time. As in PostgreSQL, an interval may name each field only once: '1 day 1 day' and '1 hour 1:00' raise 22007, while '1 week 1 day' (week and day are different fields) is 8 days. jed rejects the ambiguous unit m (spell out min or mon) and 'infinity', since it
has no infinite interval.
No results yet. Run a query to see output.
Casting to text
Every built-in scalar casts to text with an explicit CAST / :: (or ::varchar(n), which
truncates the result). The text is the type’s own output form — exactly what a result cell of that
type shows: numbers in base 10 (a numeric keeps its scale), true / false, bytea as \x hex, uuid in lowercase, dates, timestamps, and intervals in PostgreSQL’s ISO / postgres styles, json verbatim and jsonb canonical:
No results yet. Run a query to see output.
A timestamptz renders in the session time zone, with PostgreSQL’s offset spelling (-05, +05:30); the panel runs in the default UTC session. Because the result depends on the session,
an index expression containing timestamptz::text is rejected (42P17), as in PostgreSQL; every
other cast to text is fine in an index. An array → text[] cast renders each element the same way,
and so does array → text for a timestamptz anywhere inside the array — an element, a composite
field, or a range bound (see Time zones).
A float renders exactly as PostgreSQL renders it, in every engine: the shortest digits that read
back to the same float, in exponent form when the number is very large or very small (1e+21, 1e-07). So f::text is a stable value, and an index on it works.
Unlike PostgreSQL, the cast is explicit only: INSERT INTO t (name) VALUES (42) and name = 42 stay type errors (42804). A composite value casts to its row text ((Main,90210));
a range value does not cast to text yet.
Concatenating text
|| joins two strings. As in PostgreSQL, one side may be any other non-array type, which is first
converted with its text cast above — so 'row ' || 42 is 'row 42' and a numeric keeps its scale.
A NULL on either side makes the result NULL:
No results yet. Run a query to see output.
At least one side must be text, a quoted literal, or NULL: 1 || 2 is an error (42883). When
one side is an array, || appends to the array instead; beside a jsonb or bytea value, a quoted
literal is read as that type (jsonb merge, bytea concatenation), while a text-typed value makes
it text concatenation. Like the cast, || timestamptz renders in the session time zone, so it cannot
appear in an index expression.
concat(…) and concat_ws(separator, …) join any number of values of any type and skip NULLs, so they never turn a whole result NULL (unless the separator is). format(template, …) is PostgreSQL’s printf: %s inserts a value, %I quotes it as an identifier, %L as a literal
(NULL unquoted), %% is a percent sign, %2$s picks an argument by position, and a width such as %10s or %-10s pads it. All three render a value with its type’s output text (a boolean is t/f)
and pass an array’s elements with VARIADIC, as in concat(VARIADIC ARRAY[1, 2]):
No results yet. Run a query to see output.
varchar(n) length limits
varchar(n) (also spelled character varying(n), and the jed alias string(n)) is text with a maximum length, counted in Unicode code points — so 'café' (4 code points) fits varchar(4). An explicit CAST / :: silently truncates to n, exactly like PostgreSQL, so 'hello world'::varchar(5) is 'hello':
No results yet. Run a query to see output.
Storing into a varchar(n) column is stricter: an over-length value raises 22001 (string_data_right_truncation), unless the excess characters are all spaces — then it is
truncated to n (the SQL-standard trailing-space rule). UPDATE re-checks the length the same way.
The limit lives on the value, not the type: a varchar(4) and an unbounded text are the same type
underneath, with the same collation, comparison, and key encoding.
Timestamp precision and interval fields
Interval addition and subtraction operate on the month, day, and microsecond fields separately.
Subtraction succeeds whenever each resulting field fits, including subtracting interval '-2147483648 months' from itself to produce 00:00:00.
A timestamp or timestamptz may declare a precision, the number of fractional-second digits
it keeps: timestamp(3), timestamptz(0) (0 through 6; a larger precision means 6). A value stored
in such a column or cast to such a type is rounded, not truncated, exactly as in PostgreSQL —
including PostgreSQL’s quirk that a half second rounds up after 2000-01-01 and down before it.
The SQL-standard spellings timestamp with time zone (= timestamptz) and timestamp without time zone (= timestamp) work in every type position, with the precision before the zone words: timestamp(3) with time zone.
An interval may declare fields — YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, or a range
such as YEAR TO MONTH, DAY TO SECOND, MINUTE TO SECOND — and a precision, interval(3) or interval DAY TO SECOND(3). The fields steer how text is read (a bare '5' under DAY is five
days; '2:03' under MINUTE TO SECOND is two minutes three seconds) and cut everything below the
last field (HOUR drops minutes and seconds but keeps days and months). They also work on a literal: INTERVAL '1' DAY.
No results yet. Run a query to see output.
The modifier is part of the column’s type in jed_columns (timestamp(3), interval day to second(3)), and CREATE TABLE … AS keeps it from a column or a cast.
UUID ⇄ text and bytea casts
A uuid casts to and from text and bytea, always with an explicit CAST / ::. text → uuid parses PostgreSQL-flexibly (braces, hyphens after any byte pair, a bare 32-hex run, any case), and uuid → text always renders the canonical lowercase 8-4-4-4-12 form. Because a UUID is exactly
16 bytes, it also casts to and from bytea (those 16 raw bytes); bytea → uuid requires exactly 16
bytes and raises 22P02 otherwise:
No results yet. Run a query to see output.
text → uuid matches PostgreSQL. The other three are deliberately stricter or additional: jed makes uuid → text explicit-only (PostgreSQL assignment-casts any type to text), and the bytea ↔ uuid casts are a jed convenience PostgreSQL does not offer at all.
Binary strings (bytea)
A bytea value is written as a string, read the way PostgreSQL reads it. A string that starts with \x is hex: two hex digits per byte, either case, with spaces, tabs, or newlines allowed
between (not inside) the pairs. Any other string is the traditional escape format: each
character is its own UTF-8 bytes, \\ is one backslash, and \nnn (three octal digits, \000 to \377) is one byte. Any other backslash raises 22P02. Output is always hex, as
in PostgreSQL by default:
No results yet. Run a query to see output.
bytea has PostgreSQL’s binary-string functions, all counting and indexing bytes (the text versions count characters). length and octet_length return the byte count and bit_length eight
times that; || concatenates two bytea values; substr / substring take a 1-based window, also
spelled SUBSTRING(b FROM start FOR count); and get_byte reads one 0-based byte as an integer
0–255, raising 2202E for an index outside the value:
No results yet. Run a query to see output.
position(sub IN b) finds a byte string (1-based, 0 when absent), overlay(b PLACING new FROM start [FOR count]) splices one in, set_byte / set_bit return a copy with one byte or bit
changed (bits count from the least-significant bit of each byte, so bit 9 is bit 1 of byte 1), and btrim / ltrim / rtrim(b, bytes) strip any of a set of bytes from the ends. position and overlay work the same way on text, counting characters:
No results yet. Run a query to see output.
The digest functions hash a value. md5 takes text or bytea and returns 32 lowercase hex
digits as text, hashing a text argument as its UTF-8 bytes. sha224, sha256, sha384, and sha512 take bytea and return the raw digest as bytea (28, 32, 48, or 64 bytes); wrap them in encode(…, 'hex') for hex text. A bare string literal in a bytea-only argument is read as bytea input, as in PostgreSQL: sha256('abc') hashes the three bytes abc, and get_byte('\x0102', 1) is 2. Where a text version exists the literal stays text, so md5('abc') hashes the
string:
No results yet. Run a query to see output.
Array casts
An array casts three ways, all with an explicit CAST / ::. array → text renders the {…} form
(array_out); text → T[] parses the {…} form per row (array_in); and an array → array of a
different element type casts each element through the scalar cast, preserving the array’s shape
(its dimensions, lengths, and lower bounds):
No results yet. Run a query to see output.
The element cast follows the scalar matrix exactly — so widening (i32[] → i64[]), numeric[] → i32[] (rounding half away from zero), and text[] → i32[] all work, while an element pair with no scalar
cast is a type error (42804). Like every cast to text, array → text is explicit-only: an array
never silently lands in a text column.
Concatenation and the array builders and search functions (||, array_append, array_prepend, array_cat, array_remove, array_replace, array_position, array_positions) widen on their
own, as in PostgreSQL: the result’s element type is the common type of the arguments. So ARRAY[1::i32] || 9000000000::i64 is an i64[] and ARRAY[1, 2] || 2.5 a numeric[]. A float
never meets an integer or numeric implicitly, so mixing those is still an error (42883).
Beside an array, a bare string literal needs no cast, as in PostgreSQL: xs = '{1,2}', tags @> '{a}', and xs || '{3}' read the literal as the other operand’s array type, and id = ANY('{1,5}') reads it as an array of id’s type. A malformed literal raises 22P02.
To join an array’s elements with a separator, or split a string into a text[], use array_to_string(array, sep [, null_string]) and string_to_array(text, sep [, null_string]). array_to_string writes each element’s plain text (no {…} quoting) and skips NULL elements
unless you give a null_string to print instead; string_to_array turns pieces equal to null_string into NULL, and a NULL separator splits a string into its characters:
No results yet. Run a query to see output.
JSON assignment
json preserves its input spelling; jsonb stores a canonical document. Both can be updated from
literals, columns, or expressions. Assigning jsonb to json stores the canonical jsonb text,
while the reverse direction needs an explicit ::jsonb because it can discard whitespace, key
order, and duplicate keys. In a multi-column UPDATE, every right-hand side reads the old row, so raw = body below captures the pre-update canonical document:
No results yet. Run a query to see output.
jsonb_set(target, path, value) replaces the value at a text[] path, creating a missing final key
by default. Like PostgreSQL’s, it returns SQL NULL when value is NULL. jsonb_set_lax instead
applies its null_value_treatment: 'use_json_null' (the default) stores a JSON null, 'delete_key' removes the path, 'return_target' returns the document unchanged, and 'raise_exception' fails with 22004. A NULL element inside the path is an error (22004, “path
element at position N is null”) for jsonb_set, jsonb_set_lax, jsonb_insert, and #- when
the walk reaches it, while #> and #>> just return NULL. jsonb_set, jsonb_set_lax, and jsonb_insert accept PostgreSQL’s named arguments:
No results yet. Run a query to see output.
Reading a json value keeps its spelling too. -> and #> on json return the matched value’s
exact original text — whitespace, key order, duplicate keys, and number spelling intact — where jsonb returns the canonical value. With duplicate keys, json takes the last match in document
order. ->> and #>> de-escape a string and turn a JSON null into SQL NULL. The set-returning
functions json_array_elements[_text] and json_each[_text] work the same way, and json_each lists every member in input order, duplicates included:
No results yet. Run a query to see output.
JSON strings and keys preserve Unicode characters, including the invisible U+FEFF character. It counts as one character and remains distinct from an empty string:
No results yet. Run a query to see output.
Text cannot hold the escape \u0000 or a UTF-16 surrogate escape that is not half of a pair, so, as
in PostgreSQL, a function that decodes JSON strings rejects them: jsonb input, a cast to jsonb,
the json accessors and set-returning functions above, and the SQL/JSON query functions. A decoded \u0000 fails with 22P05, an unpaired surrogate with 22P02. These functions check the whole
document, not just the part they return. json input only checks syntax, so it stores either escape
unchanged, and json_typeof, json_array_length, json_array_elements, and IS JSON read such a
value without error. jsonpath string literals reject the same two escapes. A runtime text value casts to jsonpath the way the literal does: ('$' || '.a')::jsonpath compiles the text per
row and yields its canonical form ($."a"); a malformed path raises 42601, and a non-text
source is 42846.
A jsonpath (jsonb_path_query, @?, JSON_VALUE, and the rest) can end a step in an item method: .type(), .size(), .abs(), .floor(), .ceiling(), .double(), .bigint(), .integer(), .number(), .decimal(p, s), .boolean(), .string(), and .keyvalue(), as in PostgreSQL. In
the default lax mode a method other than .type() and .size() applies to each element of an
array. A value the method cannot convert fails with 22036 in either mode. .keyvalue() turns an
object into {"key", "value", "id"} objects. The datetime methods (.datetime(), .date(), …) are
not supported yet (0A000):
No results yet. Run a query to see output.
A jsonpath also does arithmetic: +, -, *, /, and %, and unary + and -, with the usual
precedence and parentheses, in a path, a filter, a comparison, or a subscript ($[last - 1]). The
math is exact numeric arithmetic, as in PostgreSQL. Each operand of a binary operator must be a
single number (in lax mode a one-element array counts), or the path fails with 22038; unary - negates every number of its operand and fails with 2203B on anything else. Dividing by zero fails
with 22012, but inside a filter it only makes that comparison unknown:
No results yet. Run a query to see output.
A jsonpath may name variables, $name or $"any name". The jsonb_path_* functions bind them
from their third argument, vars, a jsonb object, and their fourth, silent, stops at the first
JSON error instead of raising it: the functions then return what they found before it, and jsonb_path_exists returns NULL. Both may be passed by name (vars => …, silent => …). JSON_EXISTS, JSON_VALUE, JSON_QUERY, and JSON_TABLE bind variables with PASSING value AS name. A variable with no value fails with 42704, and vars must be an object
(22023). A float is passed as PostgreSQL passes it, as a number rounded to 15 significant digits
(6 for f32). PASSING value FORMAT JSON AS name parses a text value as JSON, and reads a bytea value as UTF-8 encoded JSON text (FORMAT JSON ENCODING UTF8 says so explicitly; bytes that
are not UTF-8 fail with 22021). Passing a date or timestamp value, or a NaN or infinite float, is not supported yet
(0A000). The _tz forms of the functions (jsonb_path_exists_tz, …) behave the same; as in PostgreSQL they are STABLE, so an index expression cannot use them. JSON_VALUE, JSON_QUERY, and a JSON_TABLE column also take ON EMPTY and ON ERROR clauses, as in PostgreSQL: NULL, ERROR, EMPTY ARRAY/EMPTY OBJECT, or DEFAULT expr, where the expression is a constant, a function call, or an
operator expression that names no column. It is converted to the RETURNING type and evaluated
only when its clause applies:
No results yet. Run a query to see output.
Besides comparisons, a jsonpath filter or top-level predicate may use PostgreSQL’s other
predicates: exists (path), starts with "prefix" (or a variable), like_regex "pattern" with an
optional flag string, and (predicate) is unknown. like_regex uses jed’s regular expressions (see pattern matching), with the flags i (ignore case), s (. matches a
newline), m (^ and $ also match at the start and end of each line), and q (the pattern is
literal text). Without s, . and [^…] do not match a newline. The x flag is not supported, as
in PostgreSQL. The .** accessor reaches every level below an item: $.** is the item and all its descendants, $.**{2} only level 2, and $.**{1 to last} everything below the item. As in PostgreSQL, a path
continuing after .** skips the items it does not apply to, even in strict mode. In lax mode it
also unwraps arrays as usual, so lax $.**.price finds a price inside an array twice, once through the
array and once through the object:
No results yet. Run a query to see output.
An unquoted member name in a jsonpath follows PostgreSQL’s lexing. It runs until whitespace, ",
or one of the path’s operator and punctuation characters (. [ ] ( ) $ @ ? , * + - / % ! = < > & | : # and braces), so it may hold any other character, non-ASCII included ($.é, $.a~b). It takes
the same backslash escapes as a string: $.a\u0041 reads the key aA. A keyword is a member key
too: $.type reads the key type, and $.type() calls the method.
A jsonpath may hold /* … */ comments between its parts, as in PostgreSQL: '$.a /* key */ + 1' is $."a" + 1, and the comment is dropped from the path’s text. Comments do not nest. As in
PostgreSQL, put whitespace between a member name and a comment: a name that runs straight into one
is dropped with it, so $.a/*c*/b reads the key b. A path with no parts at all ('', '/**/')
fails with 22P02.
A JSON document may nest at most 256 arrays/objects deep. Parsing a deeper document, or
building one with jsonb_build_array, jsonb_agg, ||, jsonb_set, and the like, fails with 54001. PostgreSQL’s limit depends on its stack size and is much higher (about 10 000 levels by
default). jed’s fixed limit is the same in every core.
Values as JSON
row_to_json(record [, pretty]) renders a composite value as a json object, as in PostgreSQL. A
named composite type keys the members by its field names, and an anonymous ROW(…) names them f1, f2, …. Each field takes its JSON form: numbers stay exact, a jsonb field embeds its
canonical text, arrays and nested composites nest, and dates and timestamps become ISO 8601 strings
(a timestamptz in the session time zone). With pretty set to true, each top-level member goes
on its own line:
No results yet. Run a query to see output.
A bare relation name is its whole row, as in PostgreSQL. row_to_json(t), to_json(t), and json_agg(t) over a table, view, derived table, or CTE key each member by its column name. A table
or view keeps its own column names even under an alias list (FROM item AS i(k)). On a row that an
outer join fills with NULLs, the whole row is NULL. Two limits: on the NULL side of an outer join,
the relation needs a NOT NULL column (a primary key does), and the whole row cannot be stored in a
table or used in an index expression:
No results yet. Run a query to see output.
Every other conversion to JSON uses the same rule: to_json, to_jsonb, array_to_json(array [, pretty]), JSON_SCALAR(value) (the same json result as to_json), json_build_array, json_build_object, and the json_agg and json_object_agg aggregates, each with its jsonb variant. A jsonb result keeps an object’s keys in canonical order.
An object key is always a string: a date or timestamp key takes the same ISO 8601 form, and an array,
composite, or JSON key is an error (22023). A float (f32/f64) is written exactly as
PostgreSQL writes it: the shortest digits that read back to the same float, in exponent form when
the number is very large or very small (1e+21, 1e-05). In json it is a number, in jsonb the
exact decimal of that text, and NaN and ±Infinity, which JSON numbers cannot express, become the
strings "NaN", "Infinity", and "-Infinity":
No results yet. Run a query to see output.
Three-valued NULL logic
Comparisons with NULL yield NULL (unknown), not false — three-valued logic, as in PostgreSQL.
Note that NULL = NULL is NULL, while NULL IS NULL is true:
No results yet. Run a query to see output.
Range types
A range is a structural type over a scalar element — PostgreSQL’s six built-in ranges
(int4range/int8range/numrange/tsrange/tstzrange/daterange; jed also spells the integer
ones i32range/i64range). A range carries inclusive/exclusive ([1,5)) and unbounded ((,5))
endpoints and a distinguished empty; discrete ranges are stored in the canonical [) form.
Construct one with a literal cast ('[1,5)'::int4range) or a constructor (int4range(1, 10)), test
it with the boolean operators (@> contains, && overlaps, <</>> strictly left/right, -|- adjacent), and combine ranges with the set operators — + (union), * (intersection), - (difference), and range_merge. A union of non-adjacent ranges raises 22000; range_merge spans
the gap instead:
No results yet. Run a query to see output.
Beside a range, a bare string literal is read as that range type, so during && '[2,6)' and r = '[1,3)' need no cast.
Time zones
timestamptz stores a UTC instant; a time zone is an I/O-time interpretation, never part of the
stored value or its order (PostgreSQL’s model). The AT TIME ZONE operator converts both ways — timestamptz AT TIME ZONE zone renders the instant as the local wall clock in zone, and timestamp AT TIME ZONE zone interprets a wall clock as being in zone and gives back the UTC
instant. UTC and fixed offsets like +05:30 are built in (note the POSIX sign: '+05:30' means UTC−5:30, matching PostgreSQL):
No results yet. Run a query to see output.
Named IANA zones (America/New_York, Europe/Paris, …) come from a time-zone database the host loads as bytes — the engine ships none by itself, so a query can only ever use an
already-loaded zone (an unknown zone raises 22023). This is the same host-loaded-data model jed
uses for Unicode collation; see the design notes for the JTZ bundle and the environment’s loadTimeZoneData host call.
Arithmetic follows PostgreSQL too: timestamptz + interval '1 day' (or '1 month') adds a
calendar day (month) on the session zone’s wall clock, so across a DST change the instant moves
by 23 or 25 hours and the wall-clock time is kept, while + interval '24 hours' moves the instant
by exactly 24 hours; a zoneless timestamp always adds 24-hour days. make_timestamptz(…, '+05:30') reads its explicit zone with the ISO sign (UTC+5:30), unlike AT TIME ZONE’s POSIX reading.
Rendering in the session time zone
A timestamptz is shown in the session time zone wherever it becomes text, as in PostgreSQL:
a result column, a timestamptz nested inside an array, composite, or range result, and the ::text and array → text casts. In a session set to America/New_York, timestamptz '2024-01-15 12:00:00+00' shows as 2024-01-15 07:00:00-05; in Asia/Kolkata it shows
as 2024-01-15 17:30:00+05:30. The offset is always written out, so the text names the same instant
whatever zone reads it back. The panels on this page run in the default UTC session.
The value itself carries no zone. The host chooses how to render a result: the session’s render method (Rust session.render(&value), Go session.Render(value), TypeScript session.render(value))
renders it in the session’s current zone, while a Value’s own canonical render is always UTC
(+00). EXPLAIN (VERBOSE) also prints a timestamptz constant in UTC, where PostgreSQL uses the
session zone.
Strings without an offset
Any timestamptz input written without an offset — a literal ('2024-01-15 10:30'::timestamptz, timestamptz '…', or a string compared against a timestamptz column), an INSERT/UPDATE value, a
column DEFAULT, a text value bound to a timestamptz parameter, or a timestamptz inside array,
range, or composite text — is a wall-clock time in the session time zone, as in PostgreSQL. An
explicit offset ('2024-01-15 10:30-05') or infinity names the instant directly. A constant DEFAULT is fixed when the table is created, in the creating session’s zone.
Two places differ from PostgreSQL. A prepared statement reads the session zone again on every
execution, where PostgreSQL keeps the zone in effect when it was prepared. And an index expression or
partial-index predicate cannot contain an offset-less timestamptz literal (42P17), because its
meaning would change with the session zone; write the offset, for example WHERE created_at > '2024-01-01 00:00+00'.
Truncating, extracting, and converting
date_trunc(unit, value) rounds a timestamp / timestamptz / interval down to a unit
(hour, day, week, month, quarter, year, …); EXTRACT(field FROM value) pulls a single
field out as exact numeric (year, dow, epoch, doy, ISO week, …); and the timestamp / timestamptz / date types cast across each other. For a timestamptz, both date_trunc and EXTRACT (and the casts) decompose the instant in the session time zone — the
panel below runs in the default UTC session, and date_trunc(unit, timestamptz, zone) takes an
explicit zone:
No results yet. Run a query to see output.
Finite timestamps use signed 64-bit microseconds since 1970, with the two endpoints reserved
for infinities. This range differs from PostgreSQL’s. Parsing and construction accept every
finite microsecond in that range; truncation outside it raises 22008.
Over an interval, EXTRACT reads its separate fields, each keeping its sign: year/month/quarter from the months, day/week from the days, hour/minute/second from the time, and epoch counts
a year as 365.25 days and a month as 30.
EXTRACT(julian FROM value) is the Julian Day: over a date the day number (2000-01-01 is 2451545), and over a timestamp / timestamptz the day number plus the exact fraction of the
(session-local) day, at PostgreSQL’s numeric scale — EXTRACT(julian FROM timestamp '2000-01-01 12:00') is 2451545.50000000000000000000.
date_part(field, source) is the double precision twin of EXTRACT — same fields, but the field
name is a runtime string, and over a date the timestamp fields exist (date_part('hour', d) is 0), exactly as in PostgreSQL. (A runtime text value casts to every datetime type, and every
datetime casts to text — a timestamptz in the session time zone.)
Over infinity or -infinity, a field that only grows with time — year, decade, century, millennium, julian, isoyear, epoch — is Infinity or -Infinity, and every other field
(month, day, hour, dow, …) is NULL: date_part('year', date 'infinity') is Infinity and date_part('month', date 'infinity') is NULL, as in PostgreSQL. EXTRACT returns the same NULLs,
but jed’s numeric has no infinity, so where PostgreSQL returns Infinity it raises 22003.
EXTRACT’s field is also checked against the type before the value is seen, so EXTRACT(timezone FROM timestamp 'infinity') is 0A000, as for any timestamp, where PostgreSQL
returns NULL.
Unit names are case-insensitive and accept PostgreSQL’s aliases: date_trunc('hrs', ts), EXTRACT(mons FROM ts), and date_part('msec', ts) work, as do y/yr/years, d/days, w/weeks, qtr, us/usec, c/cent, and the rest. EXTRACT and date_part also take jd/j for julian and mm for minute. EXTRACT’s field may be a bare word, a quoted identifier, or a
string: EXTRACT(hours FROM ts), EXTRACT("HOURS" FROM ts), and EXTRACT('Hours' FROM ts) are the
same.
An interval keeps its months, days, and time as separate fields, so interval '50 hours' stays 50:00:00. PostgreSQL’s justify_hours moves whole 24-hour chunks into days, justify_days moves
whole 30-day chunks into months, and justify_interval does both and gives every field the same
sign:
No results yet. Run a query to see output.
age(a, b) subtracts two timestamps (or two timestamptzs) field by field, so the answer
keeps calendar years and months where a - b counts days; a short day field borrows the length of
the earlier value’s month. A timestamptz pair is compared in the session time zone, and age(x) measures from midnight today. As in PostgreSQL; the one difference is an infinity argument, which
raises 22008 because jed has no infinite interval:
No results yet. Run a query to see output.
Date arithmetic
A date does calendar arithmetic, matching PostgreSQL. Adding or subtracting an integer shifts
the day count and stays a date; subtracting one date from another gives the number of days
between as an i32; and adding or subtracting an interval widens the date to midnight and
returns a timestamp (month steps clamp the day-of-month, so Jan 31 + 1 month is Feb 29 in a leap
year). The ±infinity dates absorb any shift, and an out-of-range result raises 22008:
No results yet. Run a query to see output.
Timestamp calendar-day shifts can span the full finite timestamp range. A large day count is accepted when the resulting timestamp is in range:
No results yet. Run a query to see output.
Interval arithmetic applies months, then days, then microseconds. Each completed calendar step
must stay within the finite timestamp range, as in PostgreSQL. A later field cannot rescue an
overflowing step; this example raises 22008 before applying the negative day count:
No results yet. Run a query to see output.
A date literal also accepts PostgreSQL’s special words: 'epoch' (1970-01-01) and the clock-relative 'today' / 'now' / 'tomorrow' / 'yesterday' — the current day in the
session time zone, also reachable as the SQL-standard current_date keyword. Unlike PostgreSQL,
jed never freezes a clock-relative word into a constant: DEFAULT 'today' re-evaluates on every INSERT (PostgreSQL locks in the table-creation day), a
prepared statement tracks the clock, and an index expression containing one is rejected rather
than silently frozen. make_date(year, month, day) builds a date from parts:
No results yet. Run a query to see output.
Formatting and parsing with templates
PostgreSQL’s template functions work as in PostgreSQL. to_char(value, template) renders a timestamp, timestamptz, interval, integer, decimal, or float through a template: YYYY, MM, DD, HH24, MI, SS, Month, Day, ISO IYYY/IW/ID, J, TZ/OF for
datetimes; 9, 0, ., ,, S, MI, PR, RN, V, and EEEE for numbers. FM drops the
padding, TH adds an ordinal suffix, and double-quoted text is copied through. A timestamptz is
shown in the session time zone, with its abbreviation under TZ:
No results yet. Run a query to see output.
Literal Unicode text is preserved even at the beginning of the output. For example, an invisible U+FEFF before a four-digit year makes a five-character result:
No results yet. Run a query to see output.
to_timestamp(text, template) and to_date(text, template) read text back with the same
patterns; a reading without a TZH/TZM/OF offset is a wall clock in the session time zone. to_number(text, template) reads a decimal, and to_timestamp(seconds) converts Unix-epoch
seconds:
No results yet. Run a query to see output.
jed has no locale, so it behaves as PostgreSQL does under the C locale: the TM prefix gives
the English month and day names (without padding), and D, G, L are ., ,, and a space.
A few things differ from PostgreSQL. A date is not implicitly cast, so write to_char(d::timestamp, …). A bare integer literal is i64 in jed, so to_char(125, '9.9EEEE') takes PostgreSQL’s bigint rounding (1.3e+02); write 125::i32 for the integer one
(1.2e+02). A time zone abbreviation in to_timestamp’s input ('… EST' under TZ) is not
supported yet (0A000); give the offset instead.
See the full type reference for every scalar type and its range.