Numeric ID for transfer codes

Hello!, I wanted to know if with xata I had the possibility of creating a column that has unique numbers and that the numbers are created by themselves as they are created, like an ID field but personalized
7 Replies
cmck
cmck3d ago
Hi there! You can use SERIAL to add a column that will auto increment and stay unique. I created a table called test in my own environment then ran the following query in the UI:
ALTER TABLE test ADD COLUMN id_serial SERIAL PRIMARY KEY;
ALTER TABLE test ADD COLUMN id_serial SERIAL PRIMARY KEY;
If you return to the table and add records you'll see that the id_serial column is automatically updated with a unique id. The only caveat is that you can't use the name id
Triqueta Ventures
Thanks!, Your answer was very helpful to me
Triqueta Ventures
invalid SQL: unsupported statement [ALTER TABLE] on strict level, see https://xata.io/sql-support for the support matrix The ui throw me this error
Connect to Postgres
Learn how to connect to Postgres directly via the wire protocol
cmck
cmck3d ago
Is your database enabled for direct Postgres access? If so, does the database have the native sql table option enabled? Ah, I can see that your databases are not enabled for direct postgres access. Unfortuntately, running such statements is not supported on non-postgres enabled databases.
Triqueta Ventures
And is there any other type of solution that I can carry out for the problem I have?
cmck
cmck3d ago
I'm afraid this is one of the limitations of a non-postgres-enabled database. Your other option is to migrate your database to a postgres-enabled database (the option can only be toggled at db creation)
cmck
cmck3d ago
No description

Did you find this page helpful?