HTSQL Functions and Operators

Preliminaries

We need to decide on the names and signatures of the HTSQL functions. Here is the list of HTSQL functions and operators together with their SQL/PostgreSQL definitions. We will also give their counterparts in other languages, like Python and Javascript.

There are a number of requirements for HTSQL functions:

  • the name and the signature of a function should be plain and clear. SQL functions rarely possess these qualities, that's why we should also take a look to similar functions in Python and Javascript land.
  • a function or an operator must be implementable in SQL with all the function arguments being evaluated only once.

Domains

In HTSQL, types are called domains.

An HTSQL function accepts some (maybe none) arguments of specific domains and produces a value of another domain.

There is also another kind of functions, called macros, which transform the syntax tree. The difference between ordinary functions and macros is that a function evaluates the syntax nodes passed as arguments into code objects first, then processes the code objects. Each code object has a domain. A macro does not convert the arguments into code objects, it operates on the syntax tree directly. The effect of this is that it does not make sense to talk about an argument domain for a macro.

The following domains are defined in HTSQL:

domains.Boolean
represents SQL's BOOLEAN.
domains.Number
represents SQL's INTEGER, DECIMAL and FLOAT.
domains.String
represents SQL's CHAR, VARCHAR and TEXT.
domains.Binary
represents SQL's BLOB.
domains.BitString
represents SQL's BIT and VARBIT.
domains.Date
represents SQL's DATE.
domains.Time
represents SQL's TIME.
domains.DateTime
represents SQL's TIMESTAMP.
domains.TimeDelta
represents SQL's INTERVAL.
domains.Array
represents SQL's ARRAY.
domains.Composite
represents SQL composite data types.
domains.Unknown
represents any other SQL data type, which HTSQL does not support directly.
domains.Untyped
this domain is temporarily assigned to quoted HTSQL literals until their domain could be determined from the context. It is also the domain of the function null() value.
domains.Tuple
represents the type of multicolumn values, such as those produced by SELECT statements and by HTSQL's select() commands. It is also the domain of the codes.Table objects.

We will use a pseudo-domain Any to denote any domain from this list.

The names of the domains mostly borrowed from Python.

Operators

The following operators are defined in HTSQL:

    &           |           !
    =           ==          !=          !==
    <           <=          >           >=
    ~           ~~          !~          !~~
    +(unary)    -(unary)    +           -
    *           ^           div         mod
    []          [:]

In HTSQL, operators are functions defined in the htsql:operator namespace. For instance, 2+2 is equivalent to htsql:operator:"+"(2,2). Ordinary functions and macros are defined in the htsql namespace.

List of HTSQL Macros, Functions and Operators