FORMAT()

Documentation

VoltDB Home » Documentation » Using VoltDB

FORMAT()

FORMAT() — Returns a formatted text string with values inserted as defined by placeholders in the template.

Synopsis

FORMAT( format-string [, expression...] )

Description

The FORMAT() function returns a formatted text string based on the template in the first argument, where placeholders in the template are replaced with values from the subsequent arguments. This function is equivalent to the format function found in Java or the sprintf function in C.

Placeholders in the format string consist of a percent sign (%) followed by a single character, such as %s for a string value or %d for a numeric value. These placeholders can be further modified by additional syntactic expressions. See the Boost documentation for a complete description of the format string syntax.

Note that, because the intended datatype of the inserted value is not known at compile time, there is no datatype conversion performed on the arguments to the FORMAT() function. Therefore it is important you use CAST() or other techniques to convert datatypes as necessary. For example, you must explicitly cast DECIMAL datatypes to FLOAT when providing values for a floating point placeholder such as %f .

Example

The following example uses the FORMAT() function to return the query results as a meaningful sentence.

SELECT FORMAT('%d people voted during the contest.',COUNT(phone_number)) 
  AS summary 
    FROM votes;