Comments (4)
I attempted to customize a function, but couldn't figure out how to handle the ? since doctrine uses ? for placeholders.
What about creating a custom function that "wraps" the ? and ?| operators, then creating a custom doctrine function that calls those custom functions? It's hackish, but the ? and ?| operators are the one I think I need for my data.
There is also a json_exists function in postgres 15 (https://www.depesz.com/2022/04/01/waiting-for-postgresql-15-sql-json-query-functions/) maybe simply writing a function what calls it would be easier.
from postgresql-for-doctrine.
I thought the solution was going to be to use json_exists, but it appears that the functions don't use the GIN indexes, only the operators. That seems crazy, and I hope I'm wrong on that. Details at https://dba.stackexchange.com/questions/90002/postgresql-operator-uses-index-but-underlying-function-does-not
If so, though, a solution is also offered there, to create a custom function that wraps the operator call:
CREATE OR REPLACE FUNCTION jb_contains(jsonb, text)
RETURNS bool AS
'SELECT $1 ? $2' LANGUAGE sql IMMUTABLE;
Then I guess add a doctrine function using this library that calls jb_contains. It feels hackish, I'll do some testing to see if this is even necessary and if the solution proposed here works.
from postgresql-for-doctrine.
Hey,
I was having the same problem with "?|".
Just found out, you can escape a question mark by adding another one "??|".
My class "JsonAnyOf" is working great now :
<?php
declare(strict_types=1);
namespace App\ORM;
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction;
class JsonAnyOf extends BaseFunction
{
protected function customiseFunction(): void
{
$this->setFunctionPrototype('(%s ??| %s)');
$this->addNodeMapping('StringPrimary');
$this->addNodeMapping('StringPrimary');
}
}
from postgresql-for-doctrine.
Support for ?
, ?|
and some other operators got added with #170
from postgresql-for-doctrine.
Related Issues (20)
- jsonb_build_object support? HOT 1
- Postgres 14-specific JSON syntax HOT 1
- array_agg doesn't support ORDER BY HOT 1
- float[] type
- Jsonb::convertToPHPValue(): Return value must be of type array|string|int|float|null, bool returned HOT 2
- symfony / doctrine configuration help HOT 1
- getResults() returns arrays instead of objects HOT 1
- `ANY` should accept `text[]` field, currently throw a `Expected Doctrine\ORM\Query\Lexer::T_SELECT` HOT 2
- Dependency Dashboard
- Cant install 2.1.1 version HOT 1
- Error with symfony and dql ilke function HOT 1
- Error with UNACCENT HOT 2
- Jsonb type limited convert HOT 4
- Cannot use object of type Doctrine\Common\Lexer\Token as array HOT 1
- Add support for DBAL v4 HOT 3
- InArray use ANY instead of ANY_OF HOT 2
- Add SPLIT_PART function
- Incorrect detection of text[] type when generating migrations
- Support || operator
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from postgresql-for-doctrine.