{"id":34331156,"url":"https://github.com/gpc/grails-postgresql-extensions","last_synced_at":"2025-12-17T18:05:24.490Z","repository":{"id":9400350,"uuid":"11265385","full_name":"gpc/grails-postgresql-extensions","owner":"gpc","description":"Grails plugin to use postgresql native elements such as arrays, hstores,...","archived":false,"fork":false,"pushed_at":"2025-10-17T12:49:04.000Z","size":2077,"stargazers_count":80,"open_issues_count":31,"forks_count":62,"subscribers_count":18,"default_branch":"8.x","last_synced_at":"2025-10-18T12:27:27.829Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Groovy","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gpc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2013-07-08T21:02:12.000Z","updated_at":"2025-10-17T09:07:50.000Z","dependencies_parsed_at":"2025-10-18T16:29:17.566Z","dependency_job_id":null,"html_url":"https://github.com/gpc/grails-postgresql-extensions","commit_stats":null,"previous_names":["gpc/grails-postgresql-extensions"],"tags_count":54,"template":false,"template_full_name":null,"purl":"pkg:github/gpc/grails-postgresql-extensions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpc%2Fgrails-postgresql-extensions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpc%2Fgrails-postgresql-extensions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpc%2Fgrails-postgresql-extensions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpc%2Fgrails-postgresql-extensions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gpc","download_url":"https://codeload.github.com/gpc/grails-postgresql-extensions/tar.gz/refs/heads/8.x","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpc%2Fgrails-postgresql-extensions/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27785333,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-17T02:00:08.291Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-12-17T18:05:13.384Z","updated_at":"2025-12-17T18:05:24.483Z","avatar_url":"https://github.com/gpc.png","language":"Groovy","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Grails PostgreSQL Extensions\n\nThis is a Grails plugin that provides Hibernate user types to use PostgreSQL native types such as Array, Hstore, Json,\nJsonb, ..., from a Grails application. It also provides new criteria to query these new native types.\n\nCurrently, the plugin supports array, hstore, json and jsonb fields as well as some query methods.\nMore native types and query methods will be added in the future.\n\n* [Installation](#installation)\n  * [PostgreSQL driver](#postgresql-driver)\n  * [Hibernate plugin](#hibernate-plugin)\n* [Configuration](#configuration)\n* [Native Types](#native-types)\n  * [Arrays](#arrays)\n    * [Example](#example)\n    * [Criterias](#criterias)\n        * [Contains](#contains)\n        * [Is contained](#is-contained)\n        * [Overlaps](#overlaps)\n        * [Is Empty](#is-empty)\n        * [Is Not Empty](#is-not-empty)\n        * [Is Empty or Contains](#is-empty-or-contains)\n        * [Equals](#equals)\n        * [Not Equals](#not-equals)\n        * [Ilike](#ilike)\n  * [Hstore](#hstore)\n    * [Using Hstore](#using-hstore)\n    * [Criterias](#hstore-criterias)\n        * [Contains Key](#contains-key)\n        * [Contains](#contains)\n        * [Is Contained](#is-contained)\n        * [ILike Value](#ilike-value)\n  * [JSON](#json)\n    * [Using json](#using-json)\n    * [Criterias](#json-criterias)\n        * [Has field value](#has-field-value)\n        * [Generic criterion](#generic-criterion)\n  * [JSONB](#jsonb)\n    * [Criterias](#jsonb-criterias)\n        * [Contains](#contains)\n        * [Is contained](#is-contained)\n  * [Order](#order)\n    * [Random order](#random-order)\n    * [Sql formula](#sql-formula)\n* [Release Notes](#release-notes)\n\n\n## Installation\n\nThe Grails 7 version of this plugin supports Hibernate 5.\nIn `build.gradle` add the following dependencies to install the plugin:\n\n```groovy\ndependencies {\n    //...\n    implementation 'io.github.gpc:grails-postgresql-extensions:\u003cversion\u003e'\n    implementation 'org.apache.grails:grails-data-hibernate5'\n    //...\n}\n```\n\n## Configuration\n\nAfter installing the plugin you have to use a new PostgreSQL Hibernate Dialect in your application. Add it to the\n`grails-app/conf/application.yml` file:\n\n```yaml\n---\ndataSource:\n    pooled: true\n    jmxExport: true\n    driverClassName: org.postgresql.Driver\n    username: user\n    password: password\n    url: jdbc:postgresql://localhost:5432/db_name\n    dbCreate: update\n\nhibernate:\n    dialect: gpc.pgext.hibernate.PostgresqlExtensionsDialect\n```\n\nIf you just add the dialect, hibernate will create a new sequence for every table to generate the sequential ids\nused for the primary keys instead of a global sequence for all your tables.\n\nYou can also deactivate this behavior and create only one unique sequence for all the tables with the following\nproperty in your datasource definition:\n\nAdd the following to `grails-app/conf/application.groovy`:\n\n```groovy\ngrails.gorm.default.mapping = {\n    id generator: 'org.hibernate.id.enhanced.SequenceStyleGenerator', params: [prefer_sequence_per_entity: true]\n}\n```\n\nPlease be aware that Hibernate 5 has changed the default name of the sequences so for a domain class `TestMapJson` the\ntable name is `test_map_json` and the sequence name is `seq_test_map_json` in Hibernate 4 and `testmapjson_seq` in\nHibernate 5.\n\n\n## Native Types\n\n### Arrays\n\nThe plugin supports the definition of `Integer`, `Long`, `Float`, `Double`, `String`, and `Enum` arrays in your domain\nclasses.\n\nThe `Enum` arrays behaves almost identical to `Integer` arrays in that they store and retrieve an array of ints. The\ndifference, however, is that this is used with an Array of Enums, rather than ints. The Enums are serialized to their\nordinal value before persisted to the database. On retrieval, they are then converted back into their original `Enum`\ntype.\n\n#### Example\n\n```groovy\nimport gpc.pgext.hibernate.usertype.ArrayType\n\nclass Like {\n    Integer[] favoriteNumbers = []\n    Long[] favoriteLongNumbers = []\n    Float[] favoriteFloatNumbers = []\n    Double[] favoriteDoubleNumbers = []\n    String[] favoriteMovies = []\n    Juice[] favoriteJuices = []\n    UUID[] favoriteMovieUUIDs = []\n\n    static enum Juice {\n        ORANGE(0),\n        APPLE(1),\n        GRAPE(2)\n\n        private final int value\n        Juice(int value)  { this.value = value }\n    }\n\n    static mapping = {\n        favoriteNumbers type:ArrayType, params: [type: Integer]\n        favoriteLongNumbers type:ArrayType, params: [type: Long]\n        favoriteFloatNumbers type:ArrayType, params: [type: Float]\n        favoriteDoubleNumbers type:ArrayType, params: [type: Double]\n        favoriteMovies type:ArrayType, params: [type: String]\n        favoriteJuices type:ArrayType, params: [type: Juice]\n        favoriteMovieUUIDs type:ArrayType, params: [type: UUID]\n    }\n}\n```\n\nNow you can create domain objects using lists (or arrays) of integers, longs and strings and when you save the object\nit will be stored as an postgresql array:\n\n```groovy\ndef myLikes = new Like(favoriteNumbers: [5, 17, 9, 6],\n                     favoriteLongNumbers: [123, 239, 3498239, 2344235],\n                     favoriteFloatNumbers: [0.3f, 0.1f],\n                     favoriteDoubleNumbers: [100.33d, 44.11d],\n                     favoriteMovies: [\"Spiderman\", \"Blade Runner\", \"Starwars\"],\n                     favoriteJuices: [Like.Juice.ORANGE, Like.Juice.GRAPE])\nmyLikes.save()\n```\n\nAnd now, with `psql`:\n\n```\n=# select * from like;\n\n id |  favorite_long_numbers    |  favorite_float_numbers   |  favorite_double_numbers  |        favorite_movies                 | favorite_numbers | favorite_juices\n----+---------------------------+---------------------------+---------------------------+----------------------------------------+------------------+----------------\n  1 | {123,239,3498239,2344235} | {0.3,0.1}                 | {100.33,44.11}            | {Spiderman,\"Blade Runner\",Starwars}    | {5,17,9,6}       | {0,2}\n```\n\n#### Criteria\n\nThe plugin also includes some Hibernate criteria to use in your queries. Please check the\n[services](https://github.com/gpc/grails-postgresql-extensions/tree/master/test-apps/app1/grails-app/services/app/criteria/array)\nand the [tests](https://github.com/gpc/grails-postgresql-extensions/tree/master/test-apps/app1/src/integration-test/groovy/array)\ncreated to see all usage examples.\n\nYou can also check the official [Postgresql Array operators](http://www.postgresql.org/docs/9.4/static/functions-array.html#ARRAY-OPERATORS-TABLE).\n\n##### Contains\n\nWith this criteria you can get all the rows that contain all the values in the array field. To use it just use the new\ncriteria `pgArrayContains`:\n\n```groovy\n// number can be just a value...\ndef number = 3\ndef result = Like.withCriteria {\n    pgArrayContains 'favoriteNumbers', number\n}\n\n// ...or a list\ndef numbers = [5, 17]\ndef result = Like.withCriteria {\n    pgArrayContains 'favoriteNumbers', numbers\n}\n\n// If using enums, pass the enum right through\ndef juices = Like.Juice.ORANGE\ndef result = Like.withCriteria {\n    pgArrayContains 'favoriteJuices', juices\n}\n\n```\n\n#### Is contained\n\nWith this criteria you can get all the rows that are contained by the values. To use it just use the new criteria\n`pgArrayIsContainedBy`:\n\n```groovy\n// movie can be just a string or a list\ndef movie = \"Starwars\" // or movie = [\"Starwars\"]\ndef result = Like.withCriteria {\n    pgArrayIsContainedBy 'favoriteMovies', movie\n}\n\n// The plugin also support joins\ndef movies = [\"Starwars\", \"Matrix\"]\ndef results = User.withCriteria {\n    like {\n        pgArrayIsContainedBy 'favoriteMovies', movies\n    }\n}\n```\n\n#### Overlaps\n\nWith this criteria you can get all the rows that contains any of the values. To use it just use the new criteria\n`pgArrayOverlaps`:\n\n```groovy\ndef result = Like.withCriteria {\n    pgArrayOverlaps 'favoriteNumbers', numbers\n}\n```\n\n#### Is Empty\n\nWith this criteria you can get all the rows that contains an-empty array in the selected field. To use it just use the\nnew criteria `pgArrayIsEmpty`:\n\n```groovy\ndef result = Like.withCriteria {\n    pgArrayIsEmpty 'favoriteMovies'\n}\n```\n\n#### Is Not Empty\n\nWith this criteria you can get all the rows that contains a not empty array in the selected field. To use it just use\nthe new criteria `pgArrayIsNotEmpty`:\n\n```groovy\ndef result = Like.withCriteria {\n    pgArrayIsNotEmpty 'favoriteMovies'\n}\n```\n\n#### Is Empty or Contains\n\nThis criteria is a mix of the `pgContains` and `pgIsEmpty`. Sometimes you have to execute 'pgContains' criteria if the\nlist has elements or a 'pgIsEmpty' if the list is empty. It could be something like this:\n\n```groovy\ndef numbers = ... // A list with zero or more elements\ndef result = Like.withCriteria {\n    if (numbers) {\n        pgArrayContains 'favoriteNumbers', numbers\n    } else {\n        pgArrayIsEmpty 'favoriteMovies'\n    }\n}\n```\n\nWith `pgIsEmptyOrContains` you can write the previous code as follows:\n\n```groovy\ndef numbers = ... // A list with zero or more elements\ndef result = Like.withCriteria {\n    pgArrayIsEmptyOrContains 'favoriteNumbers', numbers\n}\n```\n\n#### Equals\n\nWith this criteria you can get all the rows that are equal to a value. To use it just use the new criteria `pgArrayEquals`:\n\n```groovy\ndef result = Like.withCriteria {\n    pgArrayEquals 'favoriteNumbers', numbers\n}\n```\n\n#### Not Equals\n\nWith this criteria you can get all the rows that are not equal to a value. To use it just use the new criteria\n`pgArrayNotEquals`:\n\n```groovy\ndef result = Like.withCriteria {\n    pgArrayNotEquals 'favoriteNumbers', numbers\n}\n```\n\n#### ILike\n\nWith this criteria you can get all the rows that are ilike to a value. To use it just use the new criteria `pgArrayILike`.\n\nIt only can be used on arrays of string.\n\nIt uses the ilike syntaxis, so you can do for example:\n\n```groovy\ndef result = Like.withCriteria {\n    pgArrayILike 'favoriteMovies', \"%tarwar%\"\n}\n```\n\n\n### Hstore\n\nThe first thing you need to do is install hstore support in Postgresql. In Debian/Ubuntu you have to install the\n`postgresql-contrib` package:\n\n```\nsudo apt-get install postgresql-contrib-9.4\n```\n\nOnce the package is installed in the system you have to create the extension in the database you want to use hstore into:\n\n```\nCREATE EXTENSION hstore;\n```\n\nYou can test that the hstore extension is correctly installed running:\n\n```\n=# SELECT 'foo=\u003ebar, xxx=\u003eyyy'::hstore;\n           hstore\n----------------------------\n \"foo\"=\u003e\"bar\", \"xxx\"=\u003e\"yyy\"\n(1 row)\n```\n\n#### Using Hstore\n\nYou only have to define the domain class with a `Map` attribute and use the Hibernate user type `HstoreMapType`.\n\n```groovy\nimport net.kaleidos.hibernate.usertype.HstoreMapType\n\nclass TestHstore {\n\n    Map testAttributes\n    String anotherProperty\n\n    static mapping = {\n        testAttributes type: HstoreMapType\n    }\n}\n```\n\nNow you can create and instance of the domain class. Due to a limitation of the Hstore Postgresql type you can only\nstore Strings as key and value.\n\n```groovy\ndef instance = new TestHstore(testAttributes: [foo: \"bar\"], anotherProperty: \"Groovy Rocks!\")\ninstance.save()\n\ndef instance2 = new TestHstore(testAttributes: [xxx: 1, zzz: 123], anotherProperty: \"\")\ninstance2.save()\n```\n\n\n```\n=# select * from test_hstore;\n id | version | another_property | test_attributes\n----+---------+------------------+-----------------\n  1 |       0 | Groovy Rocks!    | \"foo\"=\u003e\"bar\"\n  2 |       0 |                  | \"xxx\"=\u003e\"1\", \"zzz\"=\u003e\"123\"\n```\n\n\n#### Hstore Criterias\n\nThe following criteria operations are available to query rows using the Hstore custom type. You can\ncheck the [services](https://github.com/kaleidos/grails-postgresql-extensions/tree/master/grails-app/services/test/criteria/hstore)\nand the [tests](https://github.com/kaleidos/grails-postgresql-extensions/tree/master/src/integration-test/groovy/net/kaleidos/hibernate/hstore)\ncreated to see all usage examples.\n\nYou can also check the official [Postgresql Hstore operators](http://www.postgresql.org/docs/9.4/static/hstore.html).\n\n##### Contains Key\n\nWith this operation you can search for rows that contain an Hstore with the key passed as parameter.\n\n```groovy\ndef wantedKey = \"my-custom-key\"\ndef result = MyDomain.withCriteria {\n    pgHstoreContainsKey \"attributes\", wantedKey\n}\n```\n\n##### Contains\n\nYou can search for data that contains certain pairs of _key_ and _value_.\n\n```groovy\ndef result = Users.withCriteria {\n    pgHstoreContains 'configuration', [\"language\": \"es\"]\n}\n```\n\n##### Is Contained\n\nThe operation is contained can be used when looking for rows that has all the elements in the map\npassed as parameter.\n\n```groovy\ndef result = TestHstore.withCriteria {\n    pgHstoreIsContained 'testAttributes', [\"1\": \"a\", \"2\": \"b\"]\n}\n```\nThe example above returns the rows that contains elements like:\n\n```\ntestAttributes = [\"1\": \"a\"]\ntestAttributes = [\"2\": \"b\"]\ntestAttributes = [\"1\": \"a\", \"2\": \"b\"]\n```\nThis criteria can also be used to look for exact matches.\n\n##### ILike Value\n\nWith this operation you can search for rows that contain an Hstore in which any value matches (ilike) to the parameter.\nIt uses the ilike syntaxis, so you can do for example:\n\n```groovy\ndef wantedValue = \"%my-value%\"\ndef result = MyDomain.withCriteria {\n    pgHstoreILikeValue \"attributes\", wantedKey\n}\n```\n\n### JSON\n\nTo define a json field you only have to define a `Map` field and use the `JsonMapType` hibernate user type.\n\n```groovy\nimport net.kaleidos.hibernate.usertype.JsonMapType\n\nclass TestMapJson {\n    Map data\n\n    static constraints = {\n    }\n    static mapping = {\n        data type: JsonMapType\n    }\n}\n```\n\n#### Using Json\n\nNow you can create and instance of the domain class:\n\n```groovy\ndef instance = new TestMapJson(data: [name: \"Iván\", age: 35, hasChilds: true, childs: [[name: 'Judith', age: 8], [name: 'Adriana', age: 5]]])\ninstance.save()\n```\n\n\n```\n=# select * from test_map_json;\n\n id | version | data\n----+---------+-------------------------------------------------------------------------------------------------------------\n  1 |       0 | {\"hasChilds\":true,\"age\":35,\"name\":\"Iván\",\"childs\":[{\"name\":\"Judith\",\"age\":8},{\"name\":\"Adriana\",\"age\":5}]}\n```\n\nAs you can see the plugin converts to Json automatically the attributes and the lists in the map type.\n\n\n#### Json Criterias\n\nThe plugin provides some criterias to query json fields. You can check the official\n[Postgresql Json functions and operators](http://www.postgresql.org/docs/9.3/static/functions-json.html) in case you\nneed additional ones.\n\n##### Has field value\n\nWith this criteria you can check if a json field contains some _value_ in some _key_. To use it just use the criteria\n`pgJsonHasFieldValue`:\n\n\n```groovy\ndef obj1 = new TestMapJson(data: [name: 'Iván', lastName: 'López']).save(flush: true)\ndef obj2 = new TestMapJson(data: [name: 'Alonso', lastName: 'Torres']).save(flush: true)\ndef obj3 = new TestMapJson(data: [name: 'Iván', lastName: 'Pérez']).save(flush: true)\n\ndef result = TestMapJson.withCriteria {\n    pgJsonHasFieldValue 'data', 'name', 'Iván'\n}\n```\n\nThe previous criteria will return all the rows that have a `name` attribute in the json field `data` with the value\n`Iván`. In this example `obj1` and `obj3`.\n\n##### Generic criterion\n\nWith this criterion you can use more operators using a syntax close to the one described in Postgresql documentation.\nTo use it just use `pgJson`:\n\n\n```groovy\ndef obj1 = new TestMapJson(data: [name: 'Iván', lastName: 'López', other: [followersCount: 150]]).save(flush: true)\ndef obj2 = new TestMapJson(data: [name: 'Alonso', lastName: 'Torres', other: [followersCount: 148]]).save(flush: true)\ndef obj3 = new TestMapJson(data: [name: 'Iván', lastName: 'Pérez', other: [followersCount: 149]]).save(flush: true)\n\ndef result1 = TestMapJson.withCriteria {\n    pgJson 'data', '-\u003e\u003e', 'name', 'ilike', '%iv%'\n}\n```\n\nThe previous query will return all the rows that have a `name` attribute in the json field `data` containing `iv`\n(case insensitive). In this example `obj1` and `obj3`.\n\n\n```groovy\ndef result2 = TestMapJson.withCriteria {\n    pgJson 'data', '#\u003e\u003e', '{other, followersCount}', '\u003e', 149\n}\n```\n\nThe previous query will return all the rows that have an `other` value whose `followersCount` value is greater than\n`149`. In this example `obj1`.\n\n### Jsonb\n\nSince postgresql-extensions version 4.4.0 it is possible to use [Postgresql Jsonb](http://www.postgresql.org/docs/9.4/static/datatype-json.html)\ninstead of just json. You need to use at least Postgresql 9.4.\n\nTo define a jsonb field you only have to define a `Map` field and use the `JsonbMapType` hibernate user type.\n\n```groovy\nimport net.kaleidos.hibernate.usertype.JsonbMapType\n\nclass TestMapJsonb {\n    Map data\n\n    static constraints = {\n    }\n    static mapping = {\n        data type: JsonbMapType\n    }\n}\n```\n\n#### Jsonb Criterias\n\nThe same criterias implemented for Json are valid for Jsonb. Besides that, there are some criterias that are only\nvalid for Jsonb. Check the [documentation](http://www.postgresql.org/docs/9.4/static/functions-json.html).\n\n\n##### Contains\n\nWith this criteria you can get all the rows that contain all the values in the map. To use it just use the criteria\n`pgJsonContains`:\n\n```groovy\ndef obj1 = new TestMapJsonb(data: [a: 'foo', b: '1']).save(flush: true)\ndef obj2 = new TestMapJsonb(data: [b: 1, d: '2']).save(flush: true)\ndef obj3 = new TestMapJsonb(data: [a: 'foo', b: '1', c: 'test',]).save(flush: true)\n\ndef result = TestMapJsonb.withCriteria {\n    pgJsonbContains data, [a: 'foo', b: '1']\n}\n```\n\nThe previous criteria will return all the rows that contains all the keys/values (`[a: 'foo', b: '1']` in the example)\nin the `data` field. In this example will return `obj1` and `obj3`.\n\n\n#### Is contained\n\nWith this criteria you can get all the rows that are contained by the values. To use it just use the criteria\n`pgArrayIsContainedBy`:\n\n```groovy\ndef obj1 = new TestMapJsonb(data: [a: 'foo', b: '1']).save(flush: true)\ndef obj2 = new TestMapJsonb(data: [b: 1, d: '2']).save(flush: true)\ndef obj3 = new TestMapJsonb(data: [b: '1', a: 'foo', c: 'test',]).save(flush: true)\n\ndef result = TestMapJsonb.withCriteria {\n    pgJsonbIsContained data, [a: 'foo', b: '1', c: 'test']\n}\n```\n\nThe previous criteria will return all the rows that are contained in the map. In the example it will retun the objects\n `obj1` and `obj3`.\n\n\n### Order\n\n#### Random order\n\nSometimes you need to get some results ordered randomly from the database. Postgres provides a native function to do\nthat. So you can write something like this:\n\n```sql\nselect * from foo order by random();\n```\n\nThe plugin now offers a new order method to do this random sorting:\n\n```groovy\nimport static net.kaleidos.hibernate.order.OrderByRandom.byRandom\n\nclass MyService {\n    List\u003cTestMapJsonb\u003e orderByRandom() {\n        return TestMapJsonb.withCriteria {\n            order byRandom()\n        }\n    }\n}\n```\n\n#### Sql formula\n\nYou may need to do a more complex sorting. Imagine that you have a table with a `jsonb` column and you want to order\nby a field in that json. Using sql you can write:\n\n```sql\nselect * from foo order by (data-\u003e'name') desc\n```\n\nWith the plugin you can do the same with a new order method called `sqlFormula`:\n\n```groovy\nimport static net.kaleidos.hibernate.order.OrderBySqlFormula.sqlFormula\n\nclass MyService {\n    List\u003cTestMapJsonb\u003e orderByJson() {\n        return TestMapJsonb.withCriteria {\n            order sqlFormula(\"(data-\u003e'name') desc\")\n        }\n    }\n}\n```\n\nIt's important to note that the \"raw\" sql is appended to the criteria, so you need to be sure that it's valid because\nif not you'll get a sql error during runtime.\n\n\n## Release Notes\n\nVersion | Date        | Comments\n------- | ------------| ---------\n7.0.0   | 29/Jul/2019 | Grails 4 (Hibernate 5.4): Add support for Grails 4 and Hibernate 5.4. Thanks to [James Hardwick](https://github.com/jamesdh) and [Zhuravskiy Vitaliy](https://github.com/zhuravskiy).\n6.1.0   | 24/Sep/2018 | Grails 3 (Hibernate 5.2): Fix [#30](https://github.com/kaleidos/grails-postgresql-extensions/issues/30). Thanks to [John Keith](https://github.com/butters16) and [jglapa](https://github.com/jglapa).\n5.3.0   | 24/Sep/2018 | Grails 3 (Hibernate 5): Fix [#30](https://github.com/kaleidos/grails-postgresql-extensions/issues/30). Thanks to [John Keith](https://github.com/butters16) and [jglapa](https://github.com/jglapa).\n4.8.0   | 24/Sep/2018 | Grails 3 (Hibernate 4): Fix [#30](https://github.com/kaleidos/grails-postgresql-extensions/issues/30). Thanks to [John Keith](https://github.com/butters16) and [jglapa](https://github.com/jglapa).\n6.0.0   | 05/Jun/2018 | Grails 3: Add support for Hibernate 5.2. [#114](https://github.com/kaleidos/grails-postgresql-extensions/pull/114). Thanks to [Alexey Zhokhov](https://github.com/donbeave/) and [Feng Yu](https://github.com/abcfy2).\n5.2.0   | 03/Nov/2017 | Grails 3 (Hibernate 5): Merged [#107](https://github.com/kaleidos/grails-postgresql-extensions/pull/107) and [#109](https://github.com/kaleidos/grails-postgresql-extensions/pull/109).\n5.1.0   | 22/May/2017 | Grails 3 (Hibernate 5): Change db credentials to make it compatible with Postgresql 9.6.\n4.7.0   | 22/May/2017 | Grails 3 (Hibernate 4): Change db credentials to make it compatible with Postgresql 9.6.\n5.0.1   | 21/May/2017 | Grails 3 (Hibernate 5): Fix [#96](https://github.com/kaleidos/grails-postgresql-extensions/issues/96). Thanks to [jglapa](https://github.com/jglapa).\n4.6.9   | 21/May/2017 | Grails 3 (Hibernate 4): Fix [#96](https://github.com/kaleidos/grails-postgresql-extensions/issues/96). Thanks to [jglapa](https://github.com/jglapa).\n5.0.0   | 07/Nov/2016 | Grails 3: Add support for Hibernate 5.1. Upgrade dialect to Postgresql 9.4, Grails to 3.2.2 and GORM to 6.0.3.\n4.6.8   | 03/Nov/2016 | Grails 3: Add support for generic Json/Jsonb criteria [#95](https://github.com/kaleidos/grails-postgresql-extensions/pull/95). Thanks to Sabst.\n4.6.7   | 01/Nov/2016 | Grails 3: Add UUID arrays. Thanks to [Tom Potts](https://twitter.com/karaken12). Fix [#87](https://github.com/kaleidos/grails-postgresql-extensions/issues/87)\n5.0.0-RC1 | 28/Oct/2016 | Grails 3: Add support for Hibernate 5. Thanks to [Alexey Zhokhov](https://github.com/donbeave/) and [Eric Helgeson](https://github.com/erichelgeson/).\n4.6.6   | 24/Apr/2016 | Grails 3: Migrate (almost) all Java code to Groovy + @CompileStatic. No new features added.\n4.6.5   | 31/Dec/2015 | Grails 3: Fix [#84](https://github.com/kaleidos/grails-postgresql-extensions/issues/84). Starting Grails 3.0.10 the default `sequence_per_table` parameter was not working.\n4.6.4   | 29/Dec/2015 | Grails 3: Cleanup and new jar file with the same functionality as previous version. It seems that version 4.6.3 is corrupted.\n4.6.3   | 08/Dec/2015 | Grails 3: Add new criterias for Jsonb: contains and isContained.\n4.6.2   | 05/Dec/2015 | Grails 3: Cleanup old code for support Hstore in old Grails versions.\n4.6.1   | 02/0ct/2015 | Plugin migrated to Grails 3.\n4.6.1   | 21/Sep/2015 | Hibernate 4.x. Fix [#76](https://github.com/kaleidos/grails-postgresql-extensions/issues/76).\n4.6.0   | 08/Sep/2015 | Hibernate 4.x. Add support to order by a sql formula and by random. Fix [#72](https://github.com/kaleidos/grails-postgresql-extensions/issues/72).\n4.5.0   | 02/Jun/2015 | Hibernate 4.x. GR8Conf Hackergarten! Merge PRs: [#62](https://github.com/kaleidos/grails-postgresql-extensions/pull/62), [#66](https://github.com/kaleidos/grails-postgresql-extensions/pull/66), [#67](https://github.com/kaleidos/grails-postgresql-extensions/pull/67), [#68](https://github.com/kaleidos/grails-postgresql-extensions/pull/68), [#69](https://github.com/kaleidos/grails-postgresql-extensions/pull/69).\n3.4.0   | 02/Jun/2015 | Hibernate 3.x. GR8Conf Hackergarten! Add Jsonb support for Hibernate 3.x [#64](https://github.com/kaleidos/grails-postgresql-extensions/issues/64).\n4.4.0   | 15/Mar/2015 | Hibernate 4.x. Add support for Jsonb.\n3.3.0   | 18/Aug/2014 | Hibernate 3.x. Fix [#49](https://github.com/kaleidos/grails-postgresql-extensions/issues/49). Configure sequence per table or a global sequence for all tables.\n4.3.0   | 17/Aug/2014 | Hibernate 4.x. Fix [#49](https://github.com/kaleidos/grails-postgresql-extensions/issues/49). Configure sequence per table or a global sequence for all tables.\n3.2.0   | 02/Aug/2014 | Hibernate 3.x. pgJsonHasFieldValue criteria.\n4.2.0   | 28/Jul/2014 | Hibernate 4.x. pgJsonHasFieldValue criteria.\n3.1.0   | 25/Jul/2014 | Add JSON support for Hibernate 3.x. It's now possible to store and read domain classes with map types persisted to json.\n4.1.0   | 24/Jul/2014 | Add JSON support. It's now possible to store and read domain classes with map types persisted to json.\n4.0.0   | 18/Jul/2014 | Version compatible with Hibernate 4.x.\n3.0.0   | 18/Jul/2014 | Version compatible with Hibernate 3.x.\n[0.9](https://github.com/kaleidos/grails-postgresql-extensions/issues?milestone=1) | 16/Jun/2014 | Add new array criterias: pgArrayEquals, pgArrayNotEquals.\n0.8.1   | 24/Apr/2014 | Fix NPE when array is null.\n0.8     | 24/Apr/2014 | Added support for Double and Float arrays. Refactored the ArrayType to be used as a parametrized type.\n0.7     | Unreleased  | New HstoreMapType and update plugin to Grails 2.2.5.\n0.6.8   | 22/Apr/2014 | Fix NPE in HstoreType.\n0.6.7   | 14/Feb/2014 | Support Java Arrays in criterias.\n0.6.6   | 14/Feb/2014 | New criteria pgArrayIsEmptyOrContains.\n0.6.5   | 13/Feb/2014 | Fix bug deleting instances with Hstore type. Thanks to Manuel Unno Vio!\n0.6.4   | 30/Jan/2014 | Convert automatically the keys of Hstore to string.\n0.6.3   | 19/Jan/2014 | Display the class name during startup when detecting a hstore property.\n0.6.2   | Unreleased  | Refactor some tests.\n0.6.1   | 28/Nov/2013 | Update postgresql jdbc driver to version 9.2 and do not export hibernate plugin.\n0.6     | 21/Nov/2013 | Use a more complete Hstore parser. Thanks to Moritz Kobel!\n0.5.1   | 10/Nov/2013 | Change base directory to compile AST before the plugin classes. Thanks to Moritz Kobel!\n0.5     | 08/Nov/2013 | Add criteria operation for Hstore types.\n0.4.1   | Unreleased  | Compile AST before the project itself.\n0.4     | 28/Oct/2013 | Add support to Hstore. It's only possible to save and get, but no queries has been implemented.\n0.3     | 18/Sep/2013 | Add support to define the schema name for the sequences.\n0.2     | 25/Aug/2013 | Support for arrays of Enums with automatic serialization/deserialization to ordinal integer value. Thanks to Matt Feury!\n0.1.1   | 22/Jul/2013 | Some refactors of the code. No functionality added.\n0.1     | 16/Jul/2013 | Initial version of the plugin with support for integer, long and string array types and criterias pgArrayContains, pgArrayIsContainedBy, pgArrayOverlaps, pgArrayIsEmpty and pgArrayIsNotEmpty.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgpc%2Fgrails-postgresql-extensions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgpc%2Fgrails-postgresql-extensions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgpc%2Fgrails-postgresql-extensions/lists"}