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