final public function insert($table, $args=[], $pk=null) {

		$keys = $vals = [];
		$keys = array_keys($args);
		$vals = array_fill(0, count($args), '?');

		$columns = implode(',', $keys);
		$placeholders = implode(',', $vals);

		$stmt = "INSERT INTO $table ($columns) VALUES ($placeholders)";
		if ($this->dbtype == 'pgsql')
			$stmt .= " RETURNING " . ($pk ? $pk : '*');

		$pstmt = $this->prepare_statement($stmt, $args);

		if ($this->dbtype == 'pgsql') {
			$last = $pstmt->fetch(\PDO::FETCH_ASSOC);
			$ret = $pk ? $last[$pk] : $last;
		} else {
			$ret = $this->connection->lastInsertId();
		}

		self::$logger->info(sprintf(
			"SQL: insert ok: %s <- '%s'.",
			$stmt, json_encode($args)));
		return $ret;
	}