Create a slug before inserting a row

Create a slug before inserting a row

Hi everyone,
that's my first post on this forum, so hello Smiley Happy
I came here because I'm struggling with something. For each product I insert in the db, I must create a slug (from its name) that will be used in further URLs. Basically it just replace every special characters with an '-' and checks that it is unique.
For example a product named "Playstation 3 160Go", the slug should be "playstation-3-160go".
But if there are two products with the same name but that are differents somehow, the slug should still be unique and therefore have a number at the end.
For example if a there are 2 products named "Playstation 3" in the db (one black and one white), the respective slugs should "playstation-3" and "playstation-3-1".

So my question is, is there a native way to do that in Talend when inserting row in a table ?
If not, what's the best way ?
Thanks !
Guillaume
Seventeen Stars

Re: Create a slug before inserting a row

There is not native way or any way supported natively by a database. I would strongly suggest using a administration table for your slugs. This table should have a field for the slug text and an auto increment id field.
For the slug column you should add a unique index on the table.
You can try to create a slug in the first step like your rule and if this slug is already present you should read the existing one and add "salt" to it.

Re: Create a slug before inserting a row

Thanks for you answer.
Actually I changed myapproch a little. Instead of trying to have the exact slug creation system I described, I went to something custom where I slugify the name and concat it with its id. So I don't have to manage an extra table.
PS : By slugify, I mean that I have a Java snippet replacing all special characters with '-'