PGCommand.executeScalar

Executes query returning exactly one row and field. By default, returns Variant type.

class PGCommand
T
executeScalar
(
T = Variant
)
(
bool throwIfMoreRows = true
)

Parameters

throwIfMoreRows
Type: bool

If true, throws Exception when result contains more than one row.

Throws

Exception if result doesn't contain any rows or if it contains more than one field. Exception if result contains more than one row when throwIfMoreRows is true.

Examples

auto cmd = new PGCommand(conn, "SELECT 1");
auto i = cmd.executeScalar!int; // returns int
assert(is(typeof(i) == int));
auto v = cmd.executeScalar; // returns Variant

Meta