Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Adjust the query below to return the name and old_name of the countries! Adjust the composite data type and rename it to name_oldname_type. If old_name

Adjust the query below to return the name and old_name of the countries! Adjust the composite data type and rename it to name_oldname_type. If old_name is an empty text string '', then replace it with name. This can be done easily by combining the functions COALESCE() and NULLIF(). In the function call, select countries whose names contain 'pan' or 'yan' (case-insensitive). Expected result:

Query to be Adjusted:

-- Create a composite data type nps_type: DROP TYPE IF EXISTS nps_type CASCADE; CREATE TYPE nps_type AS (name TEXT, population INT, surfacearea REAL);

-- Function definition: CREATE OR REPLACE FUNCTION get_country(TEXT) RETURNS SETOF nps_type AS $$ SELECT name, population, surfacearea FROM world.country WHERE LOWER(name) SIMILAR TO '%' || LOWER($1) || '%' ORDER BY name; $$ STABLE LANGUAGE SQL;

-- Function call: SELECT * FROM get_country('[MN]e') AS countries;

Expected Result:

image text in transcribed

HINT

The new composite data type will have two values name TEXT and old_name TEXT.

An empty text string old_name can be replaced with name via COALESCE(NULLIF(old_name, ''), name).

\begin{tabular}{l|l} name & old_name \\ \hline Guyana & British Guiana \\ Japan & Nippon \\ Libyan Arab Jamahiriya & Libyan Arab Jamahiriya \\ Myanmar & Burma \\ Panama & Gran Colombia \end{tabular}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Theory Icdt 97 6th International Conference Delphi Greece January 8 10 1997 Proceedings Lncs 1186

Authors: Foto N. Afrati ,Phokion G. Kolaitis

1st Edition

3540622225, 978-3540622222

More Books

Students also viewed these Databases questions

Question

Why do social networks need to keep innovating in AI research?

Answered: 1 week ago