SimplePg
The SimplePg module provides access to some functions from the PostgreSQL codebase, at the same time the input and output arguments are adapted to primitive types.
By default you need to specify the module name as SimplePg::foo to call these functions. But if you add the PRAGMA SimplePg, you can use them in the global visibility scope as foo (it is guaranteed that they will override the built-in YQL function, if any exists).
Many functions in this module have analogues among other YQL functions with better performance.
now
Signature
SimplePg::now() -> Timestamp?
Available since version 2025.04.
Takes no arguments.
Returns the current time.
Original documentation.
Analogue β CurrentUtcTimestamp.
Examples
PRAGMA SimplePg;
SELECT now();
to_date
Signature
SimplePg::to_date(Utf8?, Utf8?) -> Date32?
Available since version 2025.04.
Arguments:
- a string with the date value;
- format string.
Parses the date according to the format string.
Original documentation.
Analogue β DateTime::Parse64.
Examples
PRAGMA SimplePg;
SELECT to_date('05 Dec 2000', 'DD Mon YYYY'); -- 2000-12-05
to_char
Signature
SimplePg::to_char(AnyPrimitiveType?, Utf8?) -> Utf8?
Available since version 2025.04.
Arguments:
- primitive type value;
- format string.
Formats the value according to the format string.
Original documentation.
Analogue β DateTime::Format.
Examples
PRAGMA SimplePg;
SELECT to_char(125.8, '999D9'); -- " 125.8"
SELECT to_char(Timestamp('2002-04-20T17:31:12.66Z'), 'HH12:MI:SS'); -- 05:31:12
date_part
Signature
SimplePg::date_part(Utf8?, Timestamp64?) -> Double?
SimplePg::date_part(Utf8?, Interval64?) -> Double?
Available since version 2025.04.
Arguments:
- component, possible values;
- timestamp.
Extracts the specified component from the timestamp or interval.
Original documentation.
Analogue β DateTime::Get.
Examples
PRAGMA SimplePg;
SELECT date_part('hour', Timestamp('2001-02-16T20:38:40Z')); -- 20
SELECT date_part('minute', Interval('PT01H02M03S')); -- 2
date_trunc
Signature
SimplePg::date_trunc(Utf8?, Timestamp64?) -> Timestamp64?
Available since version 2025.04.
Arguments:
- scale, possible values;
- timestamp.
Rounds the timestamp to the beginning of the specified scale.
Original documentation.
Analogue β DateTime::StartOf, etc.
Examples
PRAGMA SimplePg;
SELECT date_trunc('hour', Timestamp('2001-02-16T20:38:40Z')); -- 2001-02-16 20:00:00
SELECT date_trunc('year', Timestamp('2001-02-16T20:38:40Z')); -- 2001-01-01 00:00:00
floor
Signature
SimplePg::floor(Double?) -> Double?
Available since version 2025.04.
Arguments:
- floating-point value.
Rounds the value down to the nearest integer.
Original documentation.
Analogue β Math::Floor.
Examples
PRAGMA SimplePg;
SELECT floor(42.8); -- 42
SELECT floor(-42.8); -- -43
ceil
Signature
SimplePg::ceil(Double?) -> Double?
Available since version 2025.04.
Arguments:
- floating-point value.
Rounds the value up to the nearest integer.
Original documentation.
Analogue β Math::Ceil.
Examples
PRAGMA SimplePg;
SELECT ceil(42.2); -- 43
SELECT ceil(-42.8); -- -42
round
Signature
SimplePg::round(Double?, [Int32?]) -> Double?
Available since version 2025.04.
Arguments:
- floating-point value;
- optional number of decimal places (default is 0).
Rounds the value to the specified number of decimal places. Rounds away from zero.
Original documentation.
Analogue β Math::Round.
Examples
PRAGMA SimplePg;
SELECT round(42.4382, 2); -- 42.44
SELECT round(1234.56, -1); -- 1230