我试图建立一个联合,其中一列是带时区的时间戳。
UNION(SELECT au.accountId AS accountid,
u.id AS userId,
CAST (NULL AS INTEGER) AS searchprofileid,
u.name,
u.email AS email,
3 as searchitemtype,
ac.name AS accountname,
null AS searchprofiletype,
false AS isdeleted,
false AS hashostednewsroom,
u.lockoutenabled AS lockoutenabled,
u.lockoutend AS lockoutend
FROM users u
LEFT JOIN accountusers au
ON u.id = au.userid
LEFT JOIN accounts ac
ON au.accountid = ac.id
WHERE u.name ILIKE '%%'
OR u.email ILIKE '%%'
LIMIT 5)ORDER BY
这是一个更大的联盟的一部分,但我得到了这个错误:
UNION类型文本和时区与时区无法匹配
所以我把它投射到像这样的文本u.lockoutend :: text AS lockoutend 这确实有效,但是当我尝试将字符串解析为DateTimeOffset时,我的后端(C#)失败了? 。为什么要将lockoutend作为文本?我怎么能这样做?
编辑
CREATE TABLE public.users
(
id integer NOT NULL DEFAULT nextval('users_id_seq'::regclass),
accessfailedcount integer NOT NULL,
concurrencystamp character varying(255) COLLATE pg_catalog."default",
email character varying(128) COLLATE pg_catalog."default",
emailconfirmed boolean NOT NULL,
lockoutenabled boolean NOT NULL,
lockoutend timestamp with time zone,
name character varying(128) COLLATE pg_catalog."default",
normalizedemail character varying(128) COLLATE pg_catalog."default",
normalizedusername character varying(128) COLLATE pg_catalog."default",
passwordhash character varying(512) COLLATE pg_catalog."default",
phonenumber character varying(50) COLLATE pg_catalog."default",
phonenumberconfirmed boolean NOT NULL,
securitystamp character varying(255) COLLATE pg_catalog."default",
twofactorenabled boolean NOT NULL,
username character varying(50) COLLATE pg_catalog."default",
locale integer NOT NULL DEFAULT 1,
CONSTRAINT users_pkey PRIMARY KEY (id)
)
C#
using (var dbConnection = _dapperConnection.Open())
{
_logger.LogDebug("Executing AdminSearchRepository.AdminSearch {sql}", sql);
return await dbConnection.QueryAsync<DapperAdminSearchDto>(sql);
}
DapperAdminSearchDto的一部分:
public bool LockoutEnabled { get; set; }
public DateTimeOffset? LockoutEnd { get; set; }