Hey! This content applies only to previous CARTO products

Please check if it's relevant to your use case. On October 2021 we released a new version of our platform.
You can learn more and read the latest documentation at docs.carto.com

Questions  /  Working with Data  /  SQL

How to generate a fake cartodb_id

Learn how to generate fake cartodb_id values to make your query work.

A very common scenario when applying nested queries using WITH and/or several subqueries is generating a new cartodb_id column to make the final query work. Luckily, it is possible to do it combining the row_number() and over() PostgreSQL functions:

  row_number() over() as cartodb_id