1
0
mirror of https://github.com/balkian/gists.git synced 2024-11-25 10:42:28 +00:00
gists/repos/f17db63300ee88471ed9/Error SQL
J. Fernando Sánchez 0a26442ba1 Add 'repos/f17db63300ee88471ed9/' from commit '9e927e208975fb296a0f1e00cc050c5998d7d521'
git-subtree-dir: repos/f17db63300ee88471ed9
git-subtree-mainline: 4c05a13190
git-subtree-split: 9e927e2089
2021-10-30 15:13:16 +02:00

12 lines
825 B
Plaintext

SELECT count(*) AS C, payload->'retweeted_status'->>'id' AS cat, payload->'retweeted_status'->>'text' AS Tweet FROM messages WHERE jsonb_typeof(payload) = 'object' and payload->>'text' not like '%http%' GROUP BY cat, Tweet ORDER BY C DESC;
# Works just fine
SELECT count(*) AS C, payload->'retweeted_status'->>'id' AS cat, payload->'retweeted_status'->>'text' AS Tweet, payload->'retweeted_status'->'User'->>'screen_name' AS User FROM messages WHERE jsonb_typeof(payload) = 'object' and payload->>'text' not like '%http%' GROUP BY cat, Tweet, User ORDER BY C DESC;
# Doesn't work
# ------------
# ERROR: column "messages.payload" must appear in the GROUP BY clause or be used in an aggregate function
# LINE 1: ...t, payload->'retweeted_status'->>'text' AS Tweet, payload->'...
#Problem: User was the name of a column :)