mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
PostgreSQL jsonb support #5112
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @tasselchof on GitHub (Apr 23, 2016).
I am trying to set options to create jsonb field:
But generated SQL is still JSON:
ALTER TABLE reports_reports ALTER settings TYPE JSON;
@dunglas commented on GitHub (Apr 27, 2016):
What version of ORM and DBAL do you use?
JSONB support is only available for DBAL 5.6 (
dev-master).@Armenian commented on GitHub (May 2, 2016):
Hi,
I have this problem too. We have PG v9.5.
dbal version - 2.5.1
orm version - 2.5.1
We use doctrine 2 with ZF2.
@dunglas commented on GitHub (May 2, 2016):
@Armenian see my previous comment. You need versions 2.6 (not tagged yet).
@Armenian commented on GitHub (May 2, 2016):
I have updated dbal and orm to dev-master but this does not helped.
@tasselchof commented on GitHub (May 2, 2016):
I also updated:
doctrine/dbal dev-master 3df22cc Database Abstraction Layer
doctrine/orm dev-master
59a0410Object-Relational-Mapper for PHPColumn is annotated like this:
But no effect.
@Armenian we are also using ZF2 + Doctrine 2.
@dunglas commented on GitHub (May 2, 2016):
Weird, it works fo me (I used the lib trough the Symfony bundle).
@tasselchof commented on GitHub (May 2, 2016):
@dunglas how you annotated this fields?
@dunglas commented on GitHub (May 2, 2016):
@tasselchof https://github.com/dunglas/doctrine-json-odm/blob/master/tests/Fixtures/TestBundle/Entity/Foo.php#L33-L36
json_documentis a type provided by my lib but it extendsjson_array.@tasselchof commented on GitHub (May 2, 2016):
I'll check zf2 module that is used and after will write here.
@tasselchof commented on GitHub (May 2, 2016):
@dunglas What versions of other components are you using?
My are:
doctrine/annotations dev-master 2e1b1f7 Docblock Annotations Parser
doctrine/cache v1.6.0 Caching library offering an object-oriented API for many cache back...
doctrine/collections v1.3.0 Collections Abstraction library
doctrine/common v2.6.1 Common Library for Doctrine projects
doctrine/dbal dev-master 3df22cc Database Abstraction Layer
doctrine/doctrine-module 1.0.1 Zend Framework 2 Module that provides Doctrine basic functionality ...
doctrine/doctrine-orm-module 0.10.0 Zend Framework 2 Module that provides Doctrine ORM functionality
doctrine/inflector v1.1.0 Common String Manipulations with regard to casing and singular/plur...
doctrine/instantiator 1.0.5 A small, lightweight utility to instantiate objects in PHP without ...
doctrine/lexer v1.0.1 Base library for a lexer that can be used in Top-Down, Recursive De...
doctrine/orm dev-master
59a0410Object-Relational-Mapper for PHP@tasselchof commented on GitHub (May 2, 2016):
Found a problem, i think it's a bug.
If you already created you column as JSON type on automatically columns update via:
/opt/alt/php70/usr/bin/php ./vendor/bin/doctrine-module orm:schema-tool:update --dump-sql
It's not trying to switch it to JSONB, but if you are creating new column this annotation will work:
Will generate this code:
ALTER TABLE reports_reports ALTER result TYPE JSONB;
ALTER TABLE reports_reports ALTER result DROP DEFAULT;
I changed column type manually to JSONB and update is not trying to switch it back to JSON is options={"jsonb": true} is set.
@michalwiking commented on GitHub (Oct 22, 2016):
I traced it and it's DBAL issue, in: https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php#L521 there is no if for checking jsonb option. Changed column is passed to getAlterTableSQL in changedColumns array but no SQL is generated.
And i think its both ways from jsonb true to false and from false to true.
@miholeus commented on GitHub (Oct 13, 2017):
Are there any plans on
jsonbsupport?@Ocramius commented on GitHub (Oct 13, 2017):
@miholeus already supported in DBAL
@miholeus commented on GitHub (Oct 13, 2017):
Oh, I see it appeared in version 2.6. Thanks!
@leberknecht commented on GitHub (Apr 4, 2018):
Does DQL support
LIKEqueries on json-array fields on postgres? When fired likeI'm getting
@Ocramius commented on GitHub (Apr 4, 2018):
Bound parameter likely needs to be cast to string
@leberknecht commented on GitHub (Apr 4, 2018):
Hm, the parameter is a string, according to the logs, the resulting query looks like this:
With params:
["test"]Its from this small sample application: https://github.com/leberknecht/easy-admin-postgres-json-search which is basically SF4 + easy admin + postgres and one entity.
valuesis ajson_array, and as the driver is postgres, i would think the resulting query should look something likeno? (...except for the
? ?which probably is wrong anyways as the first?is the operator for jsonb, not a placeholder)From the DQL generated by easy-admin bundles
createSearchQueryBuilder:Is there a test somewhere that illustrates how to use DQL to search in json-arrays in postgres?
Edit:
forgot to mention, to avoid confusion: i have modified Easy-admin bundle here, as i am looking at https://github.com/EasyCorp/EasyAdminBundle/issues/2184
@Aerendir commented on GitHub (Feb 21, 2020):
I confirm the bug is already present.
First field creation:
Updating to
jsonbThis doesn't transform the field into a
jsonbone but leaves it asjson.This causes errors like this:
Spent last two hours to understand why the query didn't worked! 😤
The solution was as simple as dropping the field and run again
@kconde2 commented on GitHub (Feb 23, 2020):
Hello, I'm getting this error on
PostgreSQLetEasyAdminby doing this :dql_filter: "entity.roles LIKE '%%ROLE_USER%%'"Do you have solution for this ?
It doesn't still work, something I'm doing wrong 🤔
@simPod commented on GitHub (Jun 28, 2021):
The jsonb support is added already so this issue might get closed, right?
@back-2-95 commented on GitHub (Jan 11, 2022):
Related to this, how to configure this with attributes (PHP 8.1)?
Background: Symfony 6, PostgreSQL 13, dbal 3.2.1, orm 2.10.4
I cannot get anything accepted, eg this:
optionsmust be an array there, but it cannot be associative.Code also suggests you could set type to "jsonb" but then
bin/console doctrine:schema:update --forcewill give (as there really is no Type[jsonb] => Doctrine\DBAL\Types\JsonbType:Doctrine documentation just refers to the option "jsonb":true but nothing more.
What am I missing here?
@beberlei commented on GitHub (Jan 11, 2022):
Inside array the syntax requires => not :
@back-2-95 commented on GitHub (Jan 11, 2022):
Thanks @beberlei - this works:
@b1rdex commented on GitHub (Nov 21, 2023):
The issue is still there. Enabling
jsonbfor an already presentjsonfield doesn't produce a migration diff.@Allisone commented on GitHub (Mar 20, 2025):
how to write a dql to filter for tags ?
have tried many things.
this does not work:
[Syntax Error] line 0, col 513: Error: Expected =, <, <=, <>, >, >=, !=, got '@'",
this does work but is not correct:
this does not work:
this does not work:
*Edit: *
I had to create a FunctionNode. I thought there would be something by default.
My solution:
and