当数据存在时,内部联接返回空集



这是我的查询:

SELECT * 
FROM comments 
INNER JOIN posts ON 'comments.postPostId' = 'posts.post_id';

所有评论:

blog=# select * from comments;
comment_id              |                 uid                  |         content         |              postPostId              
--------------------------------------+--------------------------------------+-------------------------+--------------------------------------
49104d66-aebf-48f5-b816-46d9def8edc2 | 5ef3d422-8b98-4509-a752-5ac8d1aee40d | oh man this game is lit | 1c756322-0042-4d8e-bab8-e04a9ceb981e
(1 row)

所有帖子:

blog=# select * from posts;
post_id                |                 uid                  | title |   sub_title    | content |              userUserId              
--------------------------------------+--------------------------------------+-------+----------------+---------+--------------------------------------
1c756322-0042-4d8e-bab8-e04a9ceb981e | 2e83d249-7c7c-43c0-8e3d-854ddac7c1b8 | bf1   | love this game | bla bla | 6cc903a7-11bf-43a4-a75a-3e1456404525
(1 row)

结果:

blog=# SELECT * FROM comments INNER JOIN posts ON 'comments.postPostId' = 'posts.post_id';
comment_id | uid | content | postPostId | post_id | uid | title | sub_title | content | userUserId 
------------+-----+---------+------------+---------+-----+-------+-----------+---------+------------
(0 rows)

为什么它是一套空的?从技术上讲,我不应该后退一排吗?

编辑:

如果不使用单引号(如建议(,我会得到以下错误:

ERROR:  column comments.postpostid does not exist
LINE 1: SELECT * FROM comments INNER JOIN posts ON comments.postPost...
^
HINT:  Perhaps you meant to reference the column "comments.postPostId".

通过在'中包装列名,您可以比较这些文字,这总是会产生false。只需放下':

SELECT * FROM comments INNER JOIN posts ON comments."postPostId" = posts.post_id;

最新更新