# Add a slug field

**URL:** <https://community.baserow.io/t/add-a-slug-field/345>\
**Category:** Feature Ideas\
**Created:** [March 29, 2022, 12:14pm UTC](https://community.baserow.io/t/add-a-slug-field/345 "2022-03-29T12:14:28Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![ozzz](https://community.baserow.io/letter_avatar_proxy/v4/letter/o/ecd19e/32.png) [@ozzz](https://community.baserow.io/u/ozzz)\
**Post date:** [March 29, 2022, 12:14pm UTC](https://community.baserow.io/t/add-a-slug-field/345/1 "2022-03-29T12:14:28Z")

</div>

Hello,

It would be very nice to have a slug field type that is a kind of formula link to a text and change it to a slug.

Thank you

---

<div class="post-metadata">

**Author:** ![Peter](https://community.baserow.io/user_avatar/community.baserow.io/peter/32/4551_2.png) [@Peter](https://community.baserow.io/u/Peter)\
**Post date:** [March 29, 2022, 1:12pm UTC](https://community.baserow.io/t/add-a-slug-field/345/2 "2022-03-29T13:12:28Z")

</div>

> [@ozzz](#):
>
> slug

A slug? 🤪

![image](https://community.baserow.io/uploads/default/original/1X/f101e9fcace826dfb3d896c971e0439d7c50c0ad.jpeg)

---

<div class="post-metadata">

**Author:** ![bram](https://community.baserow.io/letter_avatar_proxy/v4/letter/b/9d8465/32.png) [@bram](https://community.baserow.io/u/bram)\
**Post date:** [March 29, 2022, 3:54pm UTC](https://community.baserow.io/t/add-a-slug-field/345/3 "2022-03-29T15:54:45Z")

</div>

@Peter I think that @ozzz means a different type of slug 😛 😉.

@ozzz Would a formula function to convert a text value be an option for you? So if you have a formula function like `slugify(field("Name"))`. If the `Name` field then has the value “Test Name”, the `slugify` formula would then convert it to “test-name”.

---

<div class="post-metadata">

**Author:** ![mjadobson](https://community.baserow.io/user_avatar/community.baserow.io/mjadobson/32/71_2.png) [@mjadobson](https://community.baserow.io/u/mjadobson)\
**Post date:** [March 29, 2022, 11:04pm UTC](https://community.baserow.io/t/add-a-slug-field/345/4 "2022-03-29T23:04:05Z")

</div>

I was looking for this as well. Would it be possible to have access to `regexp_replace()` for this and similar string manipulation use cases?

It’s built into postgres ([regexp\_replace](https://www.postgresql.org/docs/12/functions-string.html#id-1.5.8.9.7.2.2.28.1.1)), and there is a [PR](https://github.com/django/django/pull/12438) to make this accessible in Django.

---

<div class="post-metadata">

**Author:** ![petrs](https://community.baserow.io/user_avatar/community.baserow.io/petrs/32/159_2.png) [@petrs](https://community.baserow.io/u/petrs)\
**Post date:** [March 30, 2022, 9:02am UTC](https://community.baserow.io/t/add-a-slug-field/345/5 "2022-03-30T09:02:24Z")

</div>

This indeed sounds like a useful idea to have a general function like regex, and as you say it is doable.

---

<div class="post-metadata">

**Author:** ![nigel](https://community.baserow.io/user_avatar/community.baserow.io/nigel/32/51_2.png) [@nigel](https://community.baserow.io/u/nigel)\
**Post date:** [March 30, 2022, 9:43am UTC](https://community.baserow.io/t/add-a-slug-field/345/6 "2022-03-30T09:43:11Z")

</div>

@mjadobson This function is already exposed in Baserow formulas:

 ![image](https://community.baserow.io/uploads/default/original/1X/022324d49cce14cbab7266eaa181dfa9aa1f6699.png)

Under the hood this is the `regexp_replace` postgres function with the `g` flag set.

---

<div class="post-metadata">

**Author:** ![mjadobson](https://community.baserow.io/user_avatar/community.baserow.io/mjadobson/32/71_2.png) [@mjadobson](https://community.baserow.io/u/mjadobson)\
**Post date:** [March 30, 2022, 9:49am UTC](https://community.baserow.io/t/add-a-slug-field/345/7 "2022-03-30T09:49:41Z")

</div>

Amazing, not sure how I missed this!

A user-created slugify function would look something like this then:

```auto
regex_replace(trim(regex_replace(lower(field('Name')), "\W", " ")), "\s+", "-")

```

---

<div class="post-metadata">

**Author:** ![ozzz](https://community.baserow.io/letter_avatar_proxy/v4/letter/o/ecd19e/32.png) [@ozzz](https://community.baserow.io/u/ozzz)\
**Post date:** [March 30, 2022, 12:12pm UTC](https://community.baserow.io/t/add-a-slug-field/345/8 "2022-03-30T12:12:26Z")

</div>

🧙‍♂️ I can also do snails 🙂

---

<div class="post-metadata">

**Author:** ![ozzz](https://community.baserow.io/letter_avatar_proxy/v4/letter/o/ecd19e/32.png) [@ozzz](https://community.baserow.io/u/ozzz)\
**Post date:** [March 30, 2022, 12:17pm UTC](https://community.baserow.io/t/add-a-slug-field/345/9 "2022-03-30T12:17:43Z")

</div>

> [@mjadobson](#):
>
> ```auto
> regex_replace(trim(regex_replace(lower(field('Name')), "\W", " ")), "\s+", "-")
> 
> ```

It will not works on accent and other latin characters…

---

<div class="post-metadata">

**Author:** ![nigel](https://community.baserow.io/user_avatar/community.baserow.io/nigel/32/51_2.png) [@nigel](https://community.baserow.io/u/nigel)\
**Post date:** [March 30, 2022, 12:25pm UTC](https://community.baserow.io/t/add-a-slug-field/345/10 "2022-03-30T12:25:52Z")

</div>

@ozzz can you give some examples and what it should be instead? Accents/unicode characters work for me:

 ![image](https://community.baserow.io/uploads/default/original/1X/2237dc1bf5272a611a51141897d7de2363aac348.png)

---

<div class="post-metadata">

**Author:** ![ozzz](https://community.baserow.io/letter_avatar_proxy/v4/letter/o/ecd19e/32.png) [@ozzz](https://community.baserow.io/u/ozzz)\
**Post date:** [March 30, 2022, 12:36pm UTC](https://community.baserow.io/t/add-a-slug-field/345/11 "2022-03-30T12:36:50Z")

</div>

Sorry I need to replace the accent by the same letter without accent

Tésla → tesla

same for ç or ’ and so on

---

<div class="post-metadata">

**Author:** ![mjadobson](https://community.baserow.io/user_avatar/community.baserow.io/mjadobson/32/71_2.png) [@mjadobson](https://community.baserow.io/u/mjadobson)\
**Post date:** [March 30, 2022, 1:17pm UTC](https://community.baserow.io/t/add-a-slug-field/345/12 "2022-03-30T13:17:13Z")

</div>

You can use regex to replace the diacritics, although it will take many regex functions to cover them all.

eg:

```auto
regex_replace("tésla", "[èéêëēėę]", "e") // tesla

```

Postgres has the [unaccent()](https://www.postgresql.org/docs/current/unaccent.html) module which would be preferable I think.

---

<div class="post-metadata">

**Author:** ![nigel](https://community.baserow.io/user_avatar/community.baserow.io/nigel/32/51_2.png) [@nigel](https://community.baserow.io/u/nigel)\
**Post date:** [March 30, 2022, 1:38pm UTC](https://community.baserow.io/t/add-a-slug-field/345/13 "2022-03-30T13:38:09Z")

</div>

Hm, unaccent looks nice. However right now we haven’t figured out a nice way of enabling postgres extensions like unaccent easily/automatically for self hosted users:

Running `CREATE EXTENSION unaccent` in a migration will fail unless the user running the migration is a superuser on the postgres server (which the baserow user is almost certainly not.)

In the future we hope to offer easy to install plugins, perhaps then we could offer optional plugins which require a manual step (like running `CREATE EXTENSION unaccent` as superuser on your DB).

Alternatively for our `docker` and `docker-compose` users using the bundled postgres we can probably do this automatically as I believe we have access to the superuser user. Then I guess for other self-hosting users we could only enable the formula function using `unaccent` if we detect the extension. if we don’t detect it then I guess we could show a pop-up asking the admin to run the SQL to fix it?

---

<div class="post-metadata">

**Author:** ![mjadobson](https://community.baserow.io/user_avatar/community.baserow.io/mjadobson/32/71_2.png) [@mjadobson](https://community.baserow.io/u/mjadobson)\
**Post date:** [April 3, 2022, 9:46am UTC](https://community.baserow.io/t/add-a-slug-field/345/14 "2022-04-03T09:46:05Z")

</div>

`unaccent()` and similar modules definitely seems like something that should be a plugin for those who need it, rather than built-in. It would be nice to have a plugin store to easily install these things.

It also occurs to me that url slugs are a significant use case for unique field constraints:

> **[Field value constraints (#647) · Issues · Bram Wiepjes / baserow](https://gitlab.com/bramw/baserow/-/issues/647)**
>
> Problem Statement An area that baserow currently lacks in is validating the values stored in fields beyond the restrictions imposed by...

Either by not allowing copies, or automatically appending “-2” to the end.

I suspect I will need to implement this with webhooks for now.

---

<div class="post-metadata">

**Author:** ![mjadobson](https://community.baserow.io/user_avatar/community.baserow.io/mjadobson/32/71_2.png) [@mjadobson](https://community.baserow.io/u/mjadobson)\
**Post date:** [April 3, 2022, 9:51am UTC](https://community.baserow.io/t/add-a-slug-field/345/15 "2022-04-03T09:51:09Z")

</div>

Also touches on this:

> **[Sequential Integer Id's (#462) · Issues · Bram Wiepjes / baserow](https://gitlab.com/bramw/baserow/-/issues/462)**
>
> Baserow uses sequential integer id's for its the primary keys of the model and directly exposes them in URL's and API endpoints. This creates a two...
