Applies to VAST Cluster 5.5.
Functions › Date and time functions › Weeks and days of the week. Returns the ISO 8601 day of the week of a date or timestamp, from 1 for Monday to 7 for Sunday.
Syntax
isodow(value)
| Argument | Type | Description |
|---|---|---|
value |
DATE or TIMESTAMP (also TIMESTAMP_NS, TIMESTAMP_MS, TIMESTAMP_S) |
The value to take the day of the week of. |
Returns: BIGINT.
Same as: date_part('isodow', value); see date_part.
Set up the examples
The examples connect with the ADBC driver, as in VAST Query Engine (ADBC), and work in a schema called docs_sql_fn_date_time_isodow. Set QE_ENDPOINT, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and VASTDB_BUCKET (SQL reference), and run the blocks in order in one Python session. Below each block is the output you should see.
This block connects, defines the run() and plan() helpers, and creates a table of seven events. Each has a date (d), a timestamp (ts), a time of day (t) and a timestamp with nanoseconds (tns). Row 4 has no values, row 6 is the last moment of 1969, and row 7 is a Sunday early in January 2027:
import os
import re
import adbc_driver_manager
import adbc_driver_manager.dbapi as dbapi
import adbc_driver_vastdb
BUCKET = os.environ["VASTDB_BUCKET"]
SCHEMA = f'"{BUCKET}/docs_sql_fn_date_time_isodow"'
conn = dbapi.connect(
driver=adbc_driver_vastdb.get_driver_path(),
db_kwargs={
"vast.db.endpoint": os.environ["QE_ENDPOINT"],
"vast.db.access_key": os.environ["AWS_ACCESS_KEY_ID"],
"vast.db.secret_key": os.environ["AWS_SECRET_ACCESS_KEY"],
},
autocommit=True,
)
def server_message(e):
"""The server's message in a driver error, without the request ID or the echoed statement."""
text = re.sub(r"\[req=0x[0-9a-f]+\]: ", "", str(e))
found = (re.search(r'message: "(.*?)", request_id', text, re.S)
or re.search(r"description: (.*)\)", text, re.S))
message = found.group(1) if found else text.strip().splitlines()[-1]
message = re.sub(r"^Plan query: '.*?' failed with: ", "", message, flags=re.S)
message = re.split(r"\\n|\n", message)[0].replace('\\"', '"')
return message.replace(BUCKET, "<bucket>")
def run(sql):
"""Run one statement. Print the rows it returns, or the error."""
try:
with conn.cursor() as cur:
cur.execute(sql)
rows = cur.fetchall() if cur.description else []
except (adbc_driver_manager.Error, OSError) as e:
print(f"{type(e).__name__}: {server_message(e)}")
else:
print(rows)
def plan(sql):
"""Print the plan without its ~N Rows lines: the table's row count, which can still be 0 just after an insert."""
with conn.cursor() as cur:
cur.execute("EXPLAIN " + sql)
steps = cur.fetchall()[0][1]
print("\n".join(line for line in steps.splitlines() if "Rows" not in line))
TABLE = f"{SCHEMA}.events"
run(f"CREATE SCHEMA IF NOT EXISTS {SCHEMA}")
run(f"CREATE TABLE IF NOT EXISTS {TABLE} (id BIGINT, d DATE, ts TIMESTAMP, t TIME, tns TIMESTAMP_NS)")
run(f"INSERT INTO {TABLE} VALUES "
"(1, DATE '2026-02-28', TIMESTAMP '2026-02-28 23:15:00', TIME '23:15:00', "
"CAST('2026-02-28 23:15:00.123456789' AS TIMESTAMP_NS)), "
"(2, DATE '2026-03-01', TIMESTAMP '2026-03-01 08:30:45.123456', TIME '08:30:45.123456', "
"CAST('2026-03-01 08:30:45.123456' AS TIMESTAMP_NS)), "
"(3, DATE '2024-12-30', TIMESTAMP '2024-12-30 12:00:00', TIME '12:00:00', "
"CAST('2024-12-30 12:00:00' AS TIMESTAMP_NS)), "
"(4, NULL, NULL, NULL, NULL), "
"(5, DATE '2024-02-29', TIMESTAMP '2024-02-29 00:00:00', TIME '00:00:00', "
"CAST('2024-02-29 00:00:00' AS TIMESTAMP_NS)), "
"(6, DATE '1969-12-31', TIMESTAMP '1969-12-31 23:59:59.999999', TIME '23:59:59.999999', "
"CAST('1969-12-31 23:59:59.999999999' AS TIMESTAMP_NS)), "
"(7, DATE '2027-01-03', TIMESTAMP '2027-01-03 00:00:00.5', TIME '00:00:00.000001', "
"CAST('2027-01-03 00:00:00.5' AS TIMESTAMP_NS))")
[]
[]
[(7,)]
What it does
isodow numbers the days of the week from Monday, as ISO 8601 does:
| Day | isodow |
Example | Result |
|---|---|---|---|
| Monday | 1 | isodow(DATE '2026-03-02') |
1 |
| Tuesday to Friday | 2 to 5 | ||
| Saturday | 6 | isodow(DATE '2026-02-28') |
6 |
| Sunday | 7 | isodow(DATE '2026-03-01') |
7 |
It differs from dayofweek only on Sunday, which is 7 here and 0 there. Because the weekend comes last, isodow(d) >= 6 selects Saturdays and Sundays.
NULLs and edge cases
| Input | Result |
|---|---|
| A NULL value (row 4) | NULL |
DATE 'infinity', TIMESTAMP '-infinity' |
NULL |
DATE '0001-01-01' |
1 (a Monday) |
DATE '9999-12-31' |
5 (a Friday) |
TIMESTAMP '1969-12-31 23:59:59.999999' |
3 (a Wednesday) |
An untyped NULL: isodow(NULL) |
Error: Could not choose a best candidate function for the function call "isodow("NULL")" |
An INTERVAL |
Error: interval units "isodow" not recognized |
A TIME |
Error: No function matches the given name and argument types 'isodow(TIME)' |
| A string | Error: Could not choose a best candidate function; cast it to DATE first |
A number, boolean, BLOB or list |
Error: No function matches the given name and argument types, for example 'isodow(INTEGER_LITERAL)' |
The same cases, as the cluster returns them. They use the table and helpers from Set up the examples:
run(f"SELECT id, isodow(ts) FROM {TABLE} WHERE id = 4")
run("SELECT isodow(DATE '2026-03-02'), isodow(DATE '2026-02-28'), isodow(DATE '2026-03-01')")
run("SELECT isodow(DATE 'infinity'), isodow(TIMESTAMP '-infinity'), isodow(DATE '0001-01-01'), "
"isodow(DATE '9999-12-31'), isodow(TIMESTAMP '1969-12-31 23:59:59.999999')")
run("SELECT isodow(NULL)")
run("SELECT isodow(INTERVAL '1 year 2 months 3 days')")
run("SELECT isodow(TIME '13:45:30')")
run("SELECT isodow('2026-03-01')")
run("SELECT isodow(123)")
[(4, None)]
[(1, 6, 7)]
[(None, None, 1, 5, 3)]
InternalError: Binder Error: Could not choose a best candidate function for the function call "isodow("NULL")". In order to select one, please add explicit type casts.
OSError: interval units "isodow" not recognized
InternalError: Binder Error: No function matches the given name and argument types 'isodow(TIME)'. You might need to add explicit type casts.
InternalError: Binder Error: Could not choose a best candidate function for the function call "isodow(STRING_LITERAL)". In order to select one, please add explicit type casts.
InternalError: Binder Error: No function matches the given name and argument types 'isodow(INTEGER_LITERAL)'. You might need to add explicit type casts.
Examples
The ISO day of the week of each event, next to dayofweek and the day's name:
run(f"SELECT id, d, isodow(d), dayofweek(d), dayname(d) FROM {TABLE} ORDER BY id LIMIT 10")
[(1, datetime.date(2026, 2, 28), 6, 6, 'Saturday'), (2, datetime.date(2026, 3, 1), 7, 0, 'Sunday'), (3, datetime.date(2024, 12, 30), 1, 1, 'Monday'), (4, None, None, None, None), (5, datetime.date(2024, 2, 29), 4, 4, 'Thursday'), (6, datetime.date(1969, 12, 31), 3, 3, 'Wednesday'), (7, datetime.date(2027, 1, 3), 7, 0, 'Sunday')]
Keep only the events on a weekend:
run(f"SELECT id FROM {TABLE} WHERE isodow(d) >= 6 ORDER BY id LIMIT 10")
[(1,), (2,), (7,)]
The Monday that starts each event's ISO week. Subtracting isodow(d) - 1 from the date fails (see Limitations and errors); date_trunc('week', d) returns the Monday directly:
run(f"SELECT id, d, isodow(d), date_trunc('week', d) FROM {TABLE} ORDER BY id LIMIT 10")
[(1, datetime.date(2026, 2, 28), 6, datetime.date(2026, 2, 23)), (2, datetime.date(2026, 3, 1), 7, datetime.date(2026, 2, 23)), (3, datetime.date(2024, 12, 30), 1, datetime.date(2024, 12, 30)), (4, None, None, None), (5, datetime.date(2024, 2, 29), 4, datetime.date(2024, 2, 26)), (6, datetime.date(1969, 12, 31), 3, datetime.date(1969, 12, 29)), (7, datetime.date(2027, 1, 3), 7, datetime.date(2026, 12, 28))]
How it runs in VAST
The Query Engine runs on the cluster's CNodes, and a query on a table starts with a scan in VAST DataBase (VAST_SCAN). VAST DataBase can evaluate a comparison of a column with a constant, but not a function of a column, so isodow() is always computed by the Query Engine:
- In the
SELECTlist, the scan reads the column and the Query Engine computesisodow()for each row it returns. - In
WHERE, the scan sends the column for every row, and aFILTERstep in the Query Engine computesisodow()and keeps the rows that match. No rows are skipped in storage.
The plan of the weekend example shows the FILTER step above the scan:
plan(f"SELECT id FROM {TABLE} WHERE isodow(d) >= 6")
┌───────────────────────────┐
│ PROJECTION │
│ ──────────────────── │
│ #1 │
│ │
└─────────────┬─────────────┘
┌─────────────┴─────────────┐
│ FILTER │
│ ──────────────────── │
│ (isodow(d) >= 6) │
│ │
└─────────────┬─────────────┘
┌─────────────┴─────────────┐
│ VAST_SCAN │
│ ──────────────────── │
│ Function: VAST_SCAN │
│ │
│ Projections: │
│ d │
│ id │
│ │
└───────────────────────────┘
Make it faster
- Store the day of the week if you filter on it often. Weekends recur every week, so no single range of dates selects them. Compute
isodowwhen you write the rows and keep it in its own column:iso_day >= 6is pushed down to VAST DataBase,isodow(d) >= 6isn't. - Narrow the dates first. In
d >= DATE '2026-01-01' AND isodow(d) >= 6, the range ondis still evaluated in VAST DataBase, soisodow()runs only on the rows that pass it.
Limitations and errors
- No time-zone support. On a
TIMESTAMP WITH TIME ZONEvalue, such asnow(),isodowfails with anExtension Autoloading Error. Cast the value toTIMESTAMPfirst; see time zones. - Not for
TIMEorINTERVAL. The error for anINTERVALlistsisodow(INTERVAL)among the candidates, but running it fails withinterval units "isodow" not recognized. TIMESTAMP_NSbefore 1970. Row 6'sTIMESTAMP_NSvalue1969-12-31 23:59:59.999999999gives4(Thursday), while theTIMESTAMPvalue1969-12-31 23:59:59.999999gives3(Wednesday). If you need the day of nanosecond values before 1970 that are close to midnight, check the result or store the value asTIMESTAMP.- A date minus
isodowfails.isodowreturns aBIGINT, andDATE - BIGINTfails withNo function matches the given name and argument types '-(DATE, BIGINT)'. Usedate_trunc('week', d)for the Monday of the week.
run(f"SELECT id, isodow(tns), isodow(ts) FROM {TABLE} WHERE id = 6")
run("SELECT DATE '2026-03-01' - (isodow(DATE '2026-03-01') - 1)")
[(6, 4, 3)]
InternalError: Binder Error: No function matches the given name and argument types '-(DATE, BIGINT)'. You might need to add explicit type casts.
Similar functions
| Function | Returns | Result for DATE '2026-03-01', a Sunday (isodow gives 7) |
|---|---|---|
| dayofweek | The day of the week, 0 (Sunday) to 6 (Saturday) | 0 |
| dayname | The day's name | 'Sunday' |
strftime with '%u' |
The same number as isodow, as text |
'7' |
date_part with 'isodow' |
The same as isodow |
7 |
run("SELECT isodow(DATE '2026-03-01'), dayofweek(DATE '2026-03-01'), dayname(DATE '2026-03-01'), "
"strftime(DATE '2026-03-01', '%u'), date_part('isodow', DATE '2026-03-01')")
[(7, 0, 'Sunday', '7', 7)]
Clean up:
run(f"DROP TABLE IF EXISTS {TABLE}")
run(f"DROP SCHEMA IF EXISTS {SCHEMA}")
conn.close()
[]
[]
See also
- dayofweek and dayname: other ways to get the day of the week.
- date_trunc: the start of the week.
- Date and time functions: all the date and time functions.
- Where filters run and pushdowns.
- EXPLAIN: how to read a plan.