Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DO $$
- DECLARE
- recordCount INTEGER;
- totalCount INTEGER;
- BEGIN
- SELECT COUNT(*) INTO recordCount FROM jobs;
- RAISE INFO 'Number of records in jobs table: %', recordCount;
- totalCount = recordCount;
- SELECT COUNT(*) INTO recordCount from categories;
- RAISE INFO 'Number of records in categories table: %', recordCount;
- totalCount = totalCount + recordCount;
- SELECT COUNT(*) INTO recordCount from trailers;
- RAISE INFO 'Number of records in trailers table: %', recordCount;
- totalCount = totalCount + recordCount;
- RAISE INFO 'Total number of records: %', totalCount;
- END
- $$;
- DO $$
- DECLARE
- name VARCHAR(255);
- age INTEGER;
- person RECORD;
- BEGIN
- FOR person IN SELECT * FROM people ORDER by id LIMIT 130 LOOP
- age = (CURRENT_DATE-person.birthday)/365;
- name = person.name;
- IF person.birthday IS NOT NULL THEN
- CASE
- WHEN person.deathday IS NOT NULL THEN
- RAISE INFO '% was alive for % years', person.name, age;
- ELSE
- RAISE INFO '% is alive for % years', person.name, age;
- END CASE;
- END IF;
- END LOOP;
- END
- $$;
- DO $$
- DECLARE
- movie RECORD;
- name VARCHAR(255);
- theCount INTEGER = 0;
- itCount INTEGER = 0;
- anCount INTEGER = 0;
- otherCount INTEGER = 0;
- BEGIN
- FOR movie IN SELECT * FROM movies WHERE kind = 'movie'
- LOOP
- CASE
- WHEN STRPOS(movie.name, 'The ') = 1 OR movie.name = 'The' THEN
- theCount = theCount + 1;
- WHEN STRPOS(movie.name, 'It ') = 1 OR movie.name = 'It' THEN
- itCount = itCount + 1;
- WHEN STRPOS(movie.name, 'A ') = 1 OR movie.name = 'A' OR STRPOS(movie.name, 'An ') = 1 OR movie.name = 'An' THEN
- anCount = anCount + 1;
- ELSE
- otherCount = otherCount + 1;
- END CASE;
- END LOOP;
- RAISE INFO 'Movies starting with The: %', theCount;
- RAISE INFO 'Movies starting with It: %', itCount;
- RAISE INFO 'Movies starting with A or An: %', anCount;
- RAISE INFO 'Movies starting with other words: %', otherCount;
- END
- $$;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement