# String Functions in DQL

**URL:** <https://discuss.dgraph.io/t/string-functions-in-dql/9940>\
**Category:** Dgraph\
**Tags:** status:accepted, kind:feature, area:querylang:funct, ticket:created\
**Created:** [September 1, 2020, 12:10am UTC](https://discuss.dgraph.io/t/string-functions-in-dql/9940 "2020-09-01T00:10:32Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![amaster507](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/amaster507/32/4123_2.png) [@amaster507](https://discuss.dgraph.io/u/amaster507)\
**Post date:** [September 1, 2020, 12:10am UTC](https://discuss.dgraph.io/t/string-functions-in-dql/9940/1 "2020-09-01T00:10:32Z")

</div>

## Experience Report for Feature Request

### What you wanted to do

Use String Functions within DQL to do upserts and transform data on server side without client script.

### What you actually did

Started this Topic 😉 After I double checked and searched the docs again and searched this forum for “String Functions”

### Why that wasn’t great, with examples

Because there are not any string functions. I understand the GraphQL experience with Dgraph, but when I want to do data work behind the generated API, it becomes difficult. This makes me miss my relational database. Wish to not be reminded of that time in my life, lol.

I would like to not need an external script everytime I just want to do onetime actions. This causes much frustration for me.

Examples of string functions in neo4j:

- left()
- ltrim()
- replace()
- reverse()
- right()
- rTrim()
- split()
- substring()
- toLower()
- toString()
- toUpper()
- trim()
- `+` for concatenation

Examples of String Functions in MySQL:

- CONCAT()
- CONCAT\_WS()
- INSERT()
- LEFT()
- LCASE()
- LTRIM()
- MID()
- etc.

Example of String Functions supported by mongoDB:

- CONCAT()
- LCASE()
- LEFT()
- LTRIM()
- UCASE()
- etc.

### Any external references to support your case

> **[String functions - Cypher Manual](https://neo4j.com/docs/cypher-manual/current/functions/string/)**
>
> String functions all operate on string expressions only, and will return an error if used on any other values.

> **[MySQL :: MySQL 8.0 Reference Manual :: 14.8 String Functions and Operators](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html)**

> **[Supported SQL Functions and Operators - BI Connector - MongoDB Docs](https://www.mongodb.com/docs/bi-connector/current/supported-operations/)**
>
> Explore the supported SQL functions, operators, and statements in the MongoDB Connector for BI, including comparison, logical, and string functions.

---

<div class="post-metadata">

**Author:** ![chewxy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/chewxy/32/4339_2.png) [@chewxy](https://discuss.dgraph.io/u/chewxy)\
**Post date:** [September 1, 2020, 2:47am UTC](https://discuss.dgraph.io/t/string-functions-in-dql/9940/2 "2020-09-01T02:47:55Z")

</div>

Lots of new feature requests for DQL this week 🙂

I’m loving this one

---

<div class="post-metadata">

**Author:** ![amaster507](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/amaster507/32/4123_2.png) [@amaster507](https://discuss.dgraph.io/u/amaster507)\
**Post date:** [September 1, 2020, 4:54pm UTC](https://discuss.dgraph.io/t/string-functions-in-dql/9940/3 "2020-09-01T16:54:21Z")

</div>

I will add a use case while I am staring at a tough solution without String Functions.

I have a Contact type that stores the first name and last name as separate predicates. This is the standard for most CRMs. Now trying to find a contact given a full name, “Anthony Master”, becomes quite difficult.

I do not want all of the firstName Anthony’s with a different last name, and I don’t want all of the Master family who isn’t Anthony. So I have to separate the text on the client side and apply two different filters: firstName=Antony & lastName=Master.

This issue amplifies as more UIs are built around the same db. (That is the future of our this db serving many different UIs) Now every UI has to have the equivalence of taking the full name and dividing it up and sending it to the db.

This _can_ be solved with upcoming hooks, but I would really like it in the lower level of the db itself and not rely on a custom built hook. Although I see many hooks in my future. Maybe I should buy a tackle box to keep up with all of them.

I know the dilemma seems smaller than what I am making it, but I am just used to being able to do database side concatenation and comparison. It makes the UI footprint smaller and transfers the workload to the database. With modern computing and advances in client side tech, this problem is diminished, until we look at the rise of chromebooks and other streamlined clients that don’t offer much processing at all. We have the strongest man in the world, and we are making the 10 year old boy have to carry his backpack? I want to let the stronger device to the heavy lifting.

---

<div class="post-metadata">

**Author:** ![amaster507](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/amaster507/32/4123_2.png) [@amaster507](https://discuss.dgraph.io/u/amaster507)\
**Post date:** [September 22, 2020, 4:07pm UTC](https://discuss.dgraph.io/t/string-functions-in-dql/9940/4 "2020-09-22T16:07:00Z")

</div>

For back link reference:

> [@Can I get a substring in a query?](http://discuss.hypermode.com/t/can-i-get-a-substring-in-a-query/10522/3):
>
> I know this is DQL specific and not GQL, but if these functions get added into DQL, then we _could_ make another feature request about getting these functions supported as directives on string fields. That might look something like:
> 
> ```auto
> # directive defined
> directive @function(func: Function! props: [String]) on FIELD_DEFINITION
> enum Function {
> left
> lTrim
> replace
> reverse
> right
> rTrim
> split
> substring
> toLower
> toUpper
> trim
> }
> 
> # example use
> {
> message (func: uid(0x4e22)) {
> message @function(func: left, props: ["23"])
> }
> }
> 
> ```
> 
> Some good references:
> 
> [https://www.apollographql.com/docs/apollo-server/schema/creating-directives/](https://www.apollographql.com/docs/apollo-server/schema/creating-directives/)
> 
> [GraphQL directives are underrated - LogRocket Blog](https://blog.logrocket.com/graphql-directives-are-underrated/)

---

<div class="post-metadata">

**Author:** ![Kuririn](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/kuririn/32/8416_2.png) [@Kuririn](https://discuss.dgraph.io/u/Kuririn)\
**Post date:** [June 26, 2021, 5:46pm UTC](https://discuss.dgraph.io/t/string-functions-in-dql/9940/7 "2021-06-26T17:46:32Z")

</div>

I want that too. 🙂 Would be awesome.

---

<div class="post-metadata">

**Author:** ![miko](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/miko/32/2493_2.png) [@miko](https://discuss.dgraph.io/u/miko)\
**Post date:** [July 1, 2021, 7:18am UTC](https://discuss.dgraph.io/t/string-functions-in-dql/9940/8 "2021-07-01T07:18:08Z")

</div>

I would like that too. Please add “concat” function as well.

---

<div class="post-metadata">

**Author:** ![iyinoluwaayoola](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/iyinoluwaayoola/32/4282_2.png) [@iyinoluwaayoola](https://discuss.dgraph.io/u/iyinoluwaayoola)\
**Post date:** [July 17, 2021, 7:09am UTC](https://discuss.dgraph.io/t/string-functions-in-dql/9940/9 "2021-07-17T07:09:48Z")

</div>

Any news on this ticket?

---

<div class="post-metadata">

**Author:** ![Dave\_Aitel](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/dave_aitel/32/8431_2.png) [@Dave\_Aitel](https://discuss.dgraph.io/u/Dave_Aitel)\
**Post date:** [November 8, 2021, 6:09pm UTC](https://discuss.dgraph.io/t/string-functions-in-dql/9940/10 "2021-11-08T18:09:34Z")

</div>

Did this get done? This is something I’m trying to use today 🙂

---

<div class="post-metadata">

**Author:** ![amaster507](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/amaster507/32/4123_2.png) [@amaster507](https://discuss.dgraph.io/u/amaster507)\
**Post date:** [November 9, 2021, 12:33am UTC](https://discuss.dgraph.io/t/string-functions-in-dql/9940/11 "2021-11-09T00:33:48Z")

</div>

No ☹

---

<div class="post-metadata">

**Author:** ![Ohm\_Patel](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/ohm_patel/32/9127_2.png) [@Ohm\_Patel](https://discuss.dgraph.io/u/Ohm_Patel)\
**Post date:** [March 6, 2023, 7:32pm UTC](https://discuss.dgraph.io/t/string-functions-in-dql/9940/12 "2023-03-06T19:32:33Z")

</div>

any update on this?
