Skip to content

Instantly share code, notes, and snippets.

@morsapaes
Created April 25, 2022 09:53
Show Gist options
  • Save morsapaes/ba30d78c57ab4644a5df17b0b6411df6 to your computer and use it in GitHub Desktop.
Save morsapaes/ba30d78c57ab4644a5df17b0b6411df6 to your computer and use it in GitHub Desktop.
CREATE MATERIALIZED VIEW twitter_tweets AS
SELECT (data->>'id')::bigint AS tweet_id,
(data->'referenced_tweets'->0->>'type')::string AS tweet_type,
(data->>'text')::string AS tweet_text,
(data->'referenced_tweets'->0->>'id')::string AS tweet_id_rr,
(data->>'author_id')::bigint AS user_id,
(data->'geo'->>'place_id')::string AS place_id,
(data->>'created_at')::timestamp AS created_at
FROM (SELECT CONVERT_FROM(data,'utf8')::jsonb AS data FROM rp_twitter_tweets);
CREATE MATERIALIZED VIEW twitter_users AS
SELECT (data->>'id')::bigint AS user_id,
(data->>'username')::string AS username,
(data->>'name')::string AS user_name,
(data->>'location')::string AS location
FROM (SELECT CONVERT_FROM(data,'utf8')::jsonb AS data FROM rp_twitter_users);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment