protected function _postgresqlArrayEncode($value)
	{
		if (empty($value) || !is_array($value)) {
			return null;
		}

		$result = '{';
		$firstElem = true;

		foreach($value as $elem) {
			// add comma before element if it is not the first one
			if(!$firstElem){
				$result .= ',';
			}
			if(is_array($elem)){
				$result .= $this->_postgresqlArrayEncode($elem);
			}else if(is_string($elem)){
				if(strpos($elem, ',') !== false) {
					$result .= '"'.$elem.'"';
				}else{
					$result .= $elem;
				}
			}else if(is_numeric($elem)){
				$result .= $elem;
			}else{
				// we can only save strings and numeric
				throw new \Exception('Array contains other than string or numeric values, can\'t save to PostgreSQL array field');
			}
			$firstElem = false;
		}
		$result .= '}';
		return $result;
	}