PostgreSQL Database Quiz Questions

Course Name:PostgreSQL
Chapter Name:Chapter 7 - DQL (Data Query Language)
Lesson Content Link:CAST
Current Quiz Count:30
Progress
0%
Q1
True / False

In PostgreSQL, the CAST function can be used to convert a value from one data type to another.

Q2
True / False

The syntax CAST('123' AS INTEGER) will convert the string '123' into an integer.

Q3
True / False

In PostgreSQL, you cannot use CAST to convert a date to a string.

Q4
True / False

The CAST function in PostgreSQL can only be used with numeric data types.

Q5
True / False

CAST and the :: operator are interchangeable in PostgreSQL for type conversion.

Q6
True / False

When using CAST in PostgreSQL, the source and target data types must always be compatible.

Q7
True / False

You can use CAST in PostgreSQL to convert a JSONB data type to a text data type.

Q8
True / False

In PostgreSQL, using CAST to convert between incompatible data types will always result in an error.

Q9
True / False

PostgreSQL allows casting of a bytea data type to a text data type without any additional functions.

Q10
True / False

The following statement is valid in PostgreSQL: SELECT CAST(123 AS VARCHAR);

Q11
Single Choice

What is the purpose of the CAST operator in PostgreSQL?

Q12
Single Choice

Which of the following SQL statements correctly uses the CAST operator to convert a string '123' to an integer in PostgreSQL?

Q13
Single Choice

How do you convert a timestamp to a date in PostgreSQL using the CAST operator?

Q14
Single Choice

What will be the result of the following PostgreSQL query?

SQL Code
SELECT CAST('12.34' AS INTEGER);
Q15
Single Choice

How can you cast a character varying (varchar) column to text in PostgreSQL?

Q16
Single Choice

What does the following query return in PostgreSQL?

SQL Code
SELECT CAST('TRUE' AS BOOLEAN);
Q17
Single Choice

How does PostgreSQL handle the following CAST operation?

SQL Code
SELECT CAST(1234567890 AS VARCHAR(5));
Q18
Single Choice

Consider the following PostgreSQL query. What will be the result?

SQL Code
SELECT CAST(NULL AS INTEGER);
Q19
Single Choice

Which of the following CAST operations will fail in PostgreSQL?

Q20
Single Choice

Given the following query, what will be the output?

SQL Code
SELECT CAST(CAST('10.99' AS DECIMAL(3,1)) AS INTEGER);
Q21
Multiple Choice

How can the CAST function be used to convert a string to an integer in PostgreSQL?

SQL Code
SELECT CAST(price AS INTEGER) AS price_integer
FROM products;
Q22
Multiple Choice

How can you cast a date column to a string in PostgreSQL?

SQL Code
SELECT CAST(sale_date AS VARCHAR) AS sale_date_string
FROM sales;
Q23
Multiple Choice

What happens when casting a number to a string with CAST in PostgreSQL?

SQL Code
SELECT CAST(12345 AS VARCHAR) AS number_string;
Q24
Multiple Choice

How does the CAST function behave when converting a string to a date in PostgreSQL?

SQL Code
SELECT CAST('2024-08-23' AS DATE) AS converted_date;
Q25
Multiple Choice

Can you use CAST to convert a boolean value to an integer in PostgreSQL?

SQL Code
SELECT CAST(is_active AS INTEGER) AS active_status
FROM users;
Q26
Multiple Choice

What is the result of casting a float to an integer using CAST?

SQL Code
SELECT CAST(123.456 AS INTEGER) AS result;
Q27
Multiple Choice

How can you cast a text to a numeric data type using CAST?

SQL Code
SELECT CAST(amount AS NUMERIC) AS amount_numeric
FROM transactions;
Q28
Multiple Choice

What is the result of using CAST to convert a NULL value to another data type?

SQL Code
SELECT CAST(NULL AS INTEGER) AS result;
Q29
Multiple Choice

How can you cast a TIMESTAMP to a DATE in PostgreSQL using CAST?

SQL Code
SELECT CAST(created_at AS DATE) AS order_date
FROM orders;
Q30
Multiple Choice

How can you ensure proper data type conversion when using CAST with incompatible types?

SQL Code
SELECT CAST('abc' AS INTEGER) AS result;