如何在PostgreSQL中创建索引,如:
CREATE INDEX i_users_user_id
ON users
USING btree (user_id::character varying);
我希望Integer列的行为类似String列:
SELECT * FROM vw_users WHERE user_id='string'
'string'是一些值,我不知道它是user_id还是session_id,我只想要一个查询:)
vw_users是:
SELECT user_id::character varying FROM users
UNION
SELECT session_id as user_id FROM temp_users
表格是:
CREATE TABLE users (user_id integer)
CREATE TABLE temp_users (session_id character varying)
此致
答案 0 :(得分:1)
表达式的索引需要一组额外的括号:
CREATE INDEX i_users_user_id
ON users
USING btree ((user_id::character varying));