错误:查询 PostgreSQL 数据库时消息中的字符串无效

问题描述 投票:0回答:1

进行此查询:

    SELECT "user".id AS user_id,
       "user".is_verified AS user_is_verified, 
       "user".name AS user_name, 
       "user".nickname AS user_nickname, 
       "user".password AS user_password, 
       "user".birthdate AS user_birthdate, 
       "user".food_restrictions AS user_food_restrictions, 
       "user".email AS user_email, 
       "user".telephone AS user_telephone, 
       "user".address AS user_address, 
       "user".shirt_size AS user_shirt_size, 
       "user".type AS user_type, 
       "user".created_at AS user_created_at, 
       "user".updated_at AS user_updated_at, 
       "user".image AS user_image, 
       "user".is_image_url AS user_is_image_url, 
       "user".code AS user_code, 
       "user".terms_accepted AS user_terms_accepted, 
       "user".recive_mails AS user_recive_mails, 
       "user".lleidacoins_claimed AS user_lleidacoins_claimed, 
       "user".token AS user_token, 
       "user".refresh_token AS user_refresh_token, 
       "user".verification_token AS user_verification_token, 
       "user".rest_password_token AS user_rest_password_token, 
       hacker.user_id AS hacker_user_id, 
       hacker.banned AS hacker_banned, 
       hacker.github AS hacker_github, 
       hacker.linkedin AS hacker_linkedin, 
       hacker.cv AS hacker_cv, 
       hacker.studies AS hacker_studies, 
       hacker.study_center AS hacker_study_center, 
       hacker.location AS hacker_location, 
       hacker.how_did_you_meet_us AS hacker_how_did_you_meet_us
    FROM hacker_event_accepted, 
         "user" JOIN hacker ON "user".id = hacker.user_id
    WHERE 1 = hacker_event_accepted.event_id 
          AND hacker.user_id = hacker_event_accepted.user_id

psql 向我显示此错误:

ERROR:  invalid string in message

我在fastapi中尝试了这个,但也尝试直接在psql连接上查询也失败了,我已经搜索过,postgresql有最大查询限制,但有1600列,而且如果我从选择中删除4列,查询也能完美工作

sql mysql postgresql relational-database postgresql-9.5
1个回答
0
投票

连接条件是将正确的现代连接与基于老式逗号的连接混合在一起。我建议解决这个问题,并使用正确的别名。试试这个版本:

SELECT
    u.id AS user_id,
    u.is_verified AS user_is_verified,
    u.name AS user_name,
    u.nickname AS user_nickname,
    u.password AS user_password,
    u.birthdate AS user_birthdate,
    u.food_restrictions AS user_food_restrictions,
    u.email AS user_email,
    u.telephone AS user_telephone,
    u.address AS user_address,
    u.shirt_size AS user_shirt_size,
    u.type AS user_type,
    u.created_at AS user_created_at,
    u.updated_at AS user_updated_at,
    u.image AS user_image,
    u.is_image_url AS user_is_image_url,
    u.code AS user_code,
    u.terms_accepted AS user_terms_accepted,
    u.recive_mails AS user_recive_mails,
    u.lleidacoins_claimed AS user_lleidacoins_claimed,
    u.token AS user_token,
    u.refresh_token AS user_refresh_token,
    u.verification_token AS user_verification_token,
    u.rest_password_token AS user_rest_password_token,
    h.user_id AS hacker_user_id,
    h.banned AS hacker_banned,
    h.github AS hacker_github,
    h.linkedin AS hacker_linkedin,
    h.cv AS hacker_cv,
    h.studies AS hacker_studies,
    h.study_center AS hacker_study_center,
    h.location AS hacker_location,
    h.how_did_you_meet_us AS hacker_how_did_you_meet_us
FROM "user" u
INNER JOIN hacker h
    ON h.user_id = u.id
INNER JOIN hacker_event_accepted hea
    ON hea.user_id = h.user_id
WHERE
    hea.event_id = 1;

旁注:

user
是保留的Postgres关键字,您应该避免用它命名您的表和列。

© www.soinside.com 2019 - 2024. All rights reserved.