diff --git a/README.md b/README.md index e9e87bfc..2e0e2be3 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ MySQL, Oracle, PostgreSQL and SQLite. | MySQL | `ACOS, ADDTIME, AES_DECRYPT, AES_ENCRYPT, ANY_VALUE, ASCII, ASIN, ATAN, ATAN2, BINARY, BIT_COUNT, BIT_XOR, CAST, CEIL, CHAR_LENGTH, COLLATE, CONCAT_WS, CONVERT_TZ, COS, COT, COUNTIF, CRC32, DATE, DATE_FORMAT, DATEADD, DATEDIFF, DATESUB, DAY, DAYNAME, DAYOFWEEK, DAYOFYEAR, DEGREES, DIV, EXP, EXTRACT, FIELD, FIND_IN_SET, FLOOR, FORMAT, FROM_BASE64, FROM_UNIXTIME, GREATEST, GROUP_CONCAT, HEX, HOUR, IFELSE, IFNULL, INET_ATON, INET_NTOA, INET6_ATON, INET6_NTOA, INSTR, IS_IPV4, IS_IPV4_COMPAT, IS_IPV4_MAPPED, IS_IPV6, JSON_CONTAINS, JSON_DEPTH, JSON_LENGTH, LAG, LAST_DAY, LEAD, LEAST, LOG, LOG10, LOG2, LPAD, MAKEDATE, MATCH, MD5, MINUTE, MONTH, MONTHNAME, NOW, NULLIF, OVER, PERIOD_DIFF, PI, POWER, QUARTER, RADIANS, RAND, REGEXP, REPLACE, ROUND, RPAD, SECOND, SECTOTIME, SHA1, SHA2, SIN, SOUNDEX, STD, STDDEV, STRTODATE, STR_TO_DATE, SUBSTRING_INDEX, TAN, TIME, TIMEDIFF, TIMESTAMPADD, TIMESTAMPDIFF, TIMETOSEC, TRUNCATE, UNHEX, UNIX_TIMESTAMP, UTC_TIMESTAMP, UUID_SHORT, VARIANCE, WEEK, WEEKDAY, WEEKOFYEAR, YEAR, YEARMONTH, YEARWEEK` | | Oracle | `CEIL, DAY, FLOOR, HOUR, LISTAGG, MINUTE, MONTH, NVL, SECOND, TO_CHAR, TO_DATE, TRUNC, YEAR` | | SQLite | `CASE WHEN THEN ELSE END, DATE, DATE_FORMAT*, DAY, HOUR, IFNULL, JULIANDAY, MINUTE, MONTH, REPLACE, ROUND, SECOND, STRFTIME, WEEK, WEEKDAY, YEAR` | -| PostgreSQL | `AT_TIME_ZONE, COUNT_FILTER, DATE, DATE_PART, DATE_TRUNC, DAY, EXTRACT, GREATEST, HOUR, LEAST, MINUTE, MONTH, REGEXP_REPLACE, SECOND, STRING_AGG, TO_CHAR, TO_DATE, YEAR` | +| PostgreSQL | `AT_TIME_ZONE, COUNT_FILTER, DATE, DATE_PART, DATE_TRUNC, DAY, EXTRACT, GREATEST, HOUR, LEAST, MINUTE, MONTH, REGEXP_REPLACE, SECOND, SIMILAR TO, STRING_AGG, TO_CHAR, TO_DATE, YEAR` | > Note: SQLite date functions are implemented as `strftime(format, value)`. SQLite only supports the [most common formats](https://www.sqlite.org/lang_datefunc.html), diff --git a/config/postgres.yml b/config/postgres.yml index 0a36cc64..7510f7bf 100644 --- a/config/postgres.yml +++ b/config/postgres.yml @@ -22,3 +22,4 @@ doctrine: greatest: DoctrineExtensions\Query\Postgresql\Greatest least: DoctrineExtensions\Query\Postgresql\Least regexp_replace: DoctrineExtensions\Query\Postgresql\RegexpReplace + similar_to: DoctrineExtensions\Query\Postgresql\SimilarTo diff --git a/src/Query/Postgresql/SimilarTo.php b/src/Query/Postgresql/SimilarTo.php new file mode 100644 index 00000000..613bebd5 --- /dev/null +++ b/src/Query/Postgresql/SimilarTo.php @@ -0,0 +1,30 @@ +match(TokenType::T_IDENTIFIER); + $parser->match(TokenType::T_OPEN_PARENTHESIS); + $this->value = $parser->StringPrimary(); + $parser->match(TokenType::T_COMMA); + $this->regexp = $parser->StringExpression(); + $parser->match(TokenType::T_CLOSE_PARENTHESIS); + } + + public function getSql(SqlWalker $sqlWalker): string + { + return '(' . $this->value->dispatch($sqlWalker) . ' SIMILAR TO ' . $this->regexp->dispatch($sqlWalker) . ')'; + } +} diff --git a/tests/Query/Postgresql/SimilarToTest.php b/tests/Query/Postgresql/SimilarToTest.php new file mode 100644 index 00000000..aa23f950 --- /dev/null +++ b/tests/Query/Postgresql/SimilarToTest.php @@ -0,0 +1,16 @@ +assertDqlProducesSql( + "SELECT SIMILAR_TO('a', '^\a\') from DoctrineExtensions\Tests\Entities\Blank b", + "SELECT 'a' SIMILAR TO '^\a\' AS sclr_0 FROM Blank b0_" + ); + } +}