As commented above use the uuid
type
create table user_table (
id serial primary key,
access_token uuid default uuid_generate_v4() not null unique,
joined timestamp with time zone not null default current_timestamp
);
Then insert the default values
insert into user_table default values
returning access_token;
access_token
--------------------------------------
341ab75c-6b4e-4df0-a2ea-5148434fce5a
To be able to use the uuid
functions it is necessary to install the uuid-ossp
extension as superuser in the target database
create extension "uuid-ossp";
You can use the uuid
functions from Ruby or if they don't exist from somewhere else.
Now reading your comments it looks like you are after a session ID.
A session ID could be generated using a UUID generator. But notice that a session ID is just an ID for an certain session. It will change every time the user logs in. The session ID should not be stored in the user's table.
In general, sessions are handled by the application using some framework provided module. That module will have its own means to store the session ID and the session data. In general the session ID goes in a cookie, not in the URL. The application will pass a salt to the session manager and it will take care of generating the session ID and keeping its state, be it in a cookie, in the URL, in the page, whatever. The module will store the session data where it is configured to do, memory, disk file, database.
So don't do session management yourself. Let it to the framework's solution. Much simpler and very important, much safer.