【发布时间】:2014-03-07 23:17:19
【问题描述】:
在插入时,我应该如何将uniquely set 的值access_token 转换为random string 并将该值返回给客户端?
我有:
CREATE TABLE user (
id serial PRIMARY KEY,
access_token char(32) NOT NULL UNIQUE,
joined timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
);
数据库服务器:PostgreSQL
应用服务器:Sinatra (Ruby)
客户端:iOS
【问题讨论】:
-
为什么这是一个 Ruby 问题?
-
您考虑过触发器吗?当插入发生时,可以定义触发器,以便将
access_token设置为随机字符串并返回该值?见postgresql.org/docs/9.3/static/sql-createtrigger.html -
@theTinMan 因为我不确定solution stack 的哪个部分应该这样做。
-
相关问题除了不需要唯一性:dba.stackexchange.com/questions/19632/…
-
如何在列上使用 UUID 和默认值? postgresql.org/docs/current/static/datatype-uuid.html
标签: postgresql stored-procedures access-token