Skip to content
Functions for Manipulating Data in PostgreSQL
Functions for Manipulating Data in PostgreSQL
Here you can access the tables used in the course. To access the table, you will need to specify the dvdrentals schema in your queries (e.g., dvdrentals.film for the film table and dvdrentals.country for the country table).
Note: When using sample integrations such as those that contain course data, you have read-only access. You can run queries, but cannot make any changes such as adding, deleting, or modifying the data (e.g., creating tables, views, etc.).
Take Notes
Add notes about the concepts you've learned and SQL cells with queries you want to keep.
Add your notes here
DataFrameas
movie_info
variable
-- Add your own queries here
SELECT *
FROM dvdrentals.film
LIMIT 10Explore Datasets
Use the different tables to explore the data and practice your skills!
- Select the
title,release_year, andratingof films in thefilmtable.- Add a
description_shortenedcolumn which contains the first 50 characters of thedescriptioncolumn, ending with "...". - Filter the
filmtable for rows where thespecial_featurescolumn contains "Commentaries".
- Add a
- Select the
customer_id,amount, andpayment_datefrom thepaymenttable.- Extract date information from the
payment_datecolumn, creating new columns for theday,month,quarter, andyearof transaction. - Use the
rentaltable to include a column containing the number of days rented (i.e., time between therental_dateand thereturn_date).
- Extract date information from the
- Update the title column so that titles with multiple words are reduced to the first word and the first letter of the second word followed by a period.
- For example:
- "BEACH HEARTBREAKERS" becomes "BEACH H."
- "BEAST HUNCHBACK" becomes "BEAST H."
- Reformat your shortened title to title case (e.g., "BEACH H." becomes "Beach H.").
- For example:
DataFrameas
df
variable
CONCAT(first_name, '', last_name) = first_name || '' || last_nameDataFrameas
df1
variable
Kiedy potrzebujemy skórcić tekst do określonej liczby znaków (tutaj 50) ale nie chcemy mieć uciętego słowa. żeby znaleźć odpowiednią liczbę znaków dla funkcji LEFT odejmujemy od 50 pozycję, na kótrej znajduje się pierwsza spacja w odwróconym ciągu znaków.
SELECT
UPPER(c.name) || ': ' || f.title AS film_category,
-- Truncate the description without cutting off a word
LEFT(description, 50 -
-- Subtract the position of the first whitespace character
POSITION(
' ' IN REVERSE(LEFT(description, 50))
)
)
FROM
film AS f
INNER JOIN film_category AS fc
ON f.film_id = fc.film_id
INNER JOIN category AS c
ON fc.category_id = c.category_id;