PostgreSQL Quiz
PostgreSQL Quiz : This PostgreSQL Intermediate Quiz contains set of 60 PostgreSQL Quiz which will help to clear any Mcqs exam which is designed for Intermediate.
1) Default indexing alogorithm in postgresql
- B-Tree
- Hash
- Gist
- Brin
2) which index alogithm is best suited for indexing columns and expressions that contain an array, JSON, JSONB, etc
- Brin
- Gist
- Gin
- Hash
3) which type of indexing alogithm is used if a query used Eqlaity operation for searching rows
- Gin
- Hash
- Gist
- Brin
4) CREATE TABLESPACE fastspace LOCATION ‘/ssd1/postgresql/data’. What is true
- The location specified must be existing directory
- the directory will get created if doesnot exists
- the command will throw an error
- Location is an Optional keywod
5) Tablespaces
- Allow an administrator to designate specific locations in a file system where database objects can be stored.
- Are a fancy name for table.
- Are the amount of disk space a table is using
- Are the width, or number of columns, of a particular table
6) To restore a PostgreSQL backup created with pg_dump, the following may be used:
- $ psql -F database_dump.psql database_name
- $ psql -R database_dump.psql database_name
- $ psql -f database_dump.psql database_name
- $ psql -r database_dump.psql database_name
7) which tool is provided by postgres to help you backup databases easily and effectively.
- PG_BACKUP
- PG_DUMP
- BACKUP
- DUMP
8) Which of the following best describes a role
- A server’s purpose within a cluster
- The purpose of a particular database.
- A cluster’s purpose.
- A template for authorization to various database objects.
9) To create a database in PostgreSQL, you must have the special CREATEDB privilege or
- be an admin
- have a script do it
- be a superuser.
- the special CREATETBL privilege
10) ___________command is used to import the contents of a .csv file into portgres table
- Import
- Imp
- Copy
- \Import
11) which catalog that stores data about all available databases
- Pg_database
- Pg_DB
- catalog_db
- postgres_db
12) which command shows all databases in the current folder
- \list
- \l
- \db
- \show
13) how to execute a function in Postgresql
- Call <funcname>
- Select <funcname>
- execute <funcname>
- go <funcname>
14) when we have more than one function having the same name, but arguments are different , we call them as
- Overloaded function
- Recursive Function
- Overriding function
- repetable function
15) Which type of oop statement executes a block of statements until a condition evaluates to false
- Basic
- While
- For
- Do-While
16) which statement about FOR Loop is not true
- PostgreSQL creates an integer variable loop_counter that exists only inside the loop
- the from and to are expressions that specify the lower and upper bound of the range
- the expression following the BY clause specifies the iteration step
- For loop is an infinite loop
17) 1. declare a cursor. 2. Open the cursor 3. fetch the records
- 1,2,3,4
- 3,2,1,4
- 2,1,3,4
- 3,1,2,4
18) which function accepts an unlimited number of arguments and returns the first argument that is not null.
- Nullif
- IfNull
- IsNull
- Coalesce
19) NULLIF(20,10) returns
- NULL
- 20
- 10
- expression is invalid
20) SELECT CAST(‘10.2’ as DOUBLE);
- converts the value into Double
- throws error as DOUBLE datatype does not exists
- throws error as syntax is invalid
- FROM clause is mandatory
21) Which statements execute a sequence of statements multiple times?
- EXIT
- LOOP
- Both A and B
- Neither A not B
22) Which statements are used to control a cursor variable?
- OPEN-FOR
- FETCH
- CLOSE
- All of the Above
23) Which loop statement executes a block of statements until a condition evaluates to false
- WHILE
- FOR
- LOOP
- None of the Above
24) The CLOSE statement enables a cursor variable and makes the associated result set undefined
- TRUE
- FALSE
25) In which of the following, do you specify the same parameters in the same order as they are declared in the procedure?
- Positional Notation
- Names Notation
- Mixed Notation
- All of the Above
26) what is true about PL/pgSQL constants?
- the constants make the code more readable
- The constants reduce the maintenance efforts
- Both A and B
- Neither A not B
27) Because they should not contain SQL manipulation statements, what kind of trigger is typically used to enforce complex integrity constraints?
- AFTER ROW triggers.
- BEFORE ROW triggers.
- INSTEAD OF triggers.
- None of the above
28) Which privilege is needed to create a Database?
- createdb
- dbcreate
- Createdatabase
- Databasecreate
29) which is the correct command to restore from the dump file created using PG_DUMP command
- psql dbname > infile
- psql dbname < infile
- psql infile > dbname
- psql infile < dbname
30) What will be the output of the below code? DECLARE
- 200
- 200 and 100
- 100
- this code has a syntax error , so there wont be any output
) a number(3) := 100;
) b number(3) := 200;
) BEGIN
) IF( a = 100 ) THEN
) IF( b <> 200 ) THEN
) dbms_output.put_line(b);
) END IF;
) END IF;
) dbms_output.put_line(a);
) END;
31) Which is NOT the valid languages in which Function can be implemented?
- plpgsql
- C
- internal
- cobol
32) which function can be used with any datatypes?
- SUM
- Avg
- Count
- None of the Above
33) which is a valid command to grant all privileges on a table COMPANY to the user “manisha”
- GRANT ALL ON COMPANY TO manisha
- GRANT manisha all on COMPANY
- GRANT ALL COMPANY TO manisha
- GRANT COMPANY TO manisha
34) when you issue the command “DROP USER manisha” , what message appears on the screen?
- USER DROPPED
- DROP ROLE
- ROLE DROPPED
- DROP USER
35) which is a valid command to revoke all privileges on a table COMPANY from the user “manisha”
- REVOKE COMPANY FROM manisha
- REVOKE ALL ON COMPANY TO manisha
- REVOKE ALL ON COMPANY FROM manisha
- REVOKE ALL COMPANY FROM manisha
36) Which Keyword should be used to grant permission to all users?
- ALL
- PUBLIC
- EVERYONE
- ALL USERS
37) Which is not a valid privilege?
- INSERT
- UPDATE
- DELETE
- None of the Above
38) SELECT CURRENT_TIME command returns?
- Current time
- Current time with timezone
- Current timezone
- This is not a valid command
39) SELECT CURRENT_DATE command returns?
- Current date
- Current date with timezone
- Current date, time and timezone
- This is not a valid command
40) SELECT date_part(‘day’, TIMESTAMP ‘2001-02-16 20:38:40’) returns?
- 16-02-2001
- 16
- ‘2001-02-16 20:38:40’
- This is not a valid command
41) Which command is used to back up all the databases in one single go?
- pg_dump
- pgdump
- pg_dumpall
- pgdumpall
42) Which type of index is designed for handling cases where the items to be indexed are composite values
- B-TREE
- HASH
- GIST
- GIN
43) In Indexes, GIST stands for _______________
- Generalized search index
- General search index
- Generaized index
- Geneal index
44) Which is the valid command for reindexing an ITEMS table?
- TABLE item REINDEX
- TABLE REINDEX item
- REINDEX TABLE item
- REINDEX item
45) Which type of trigger is used on a View?
- INSERT
- UPDATE
- DELETE
- INSTEAD OF
46) Which type of trigger can only be defined a Row level trigger?
- INSERT
- UPDATE
- DELETE
- INSTEAD OF
47) In which scenario, FULL BACKUP is not recommended?
- When dealing with a lot of data
- When dealing with small amount of Data
- When Periodical backup is needed
- E
48) A table is defined as follows:
- There are cases where this function returns multiple lines.
- When NULL is passed for the argument and the function is executed, NULL is returned.
- If a function with the same name and with type BOOLEAN as the parameter is already defined, an error occurs.
- This function is defined using PL/pgSQL
) CREATE TABLE t (id INT, val TEXT);
) Select is correct statements from below about the function ‘get_head’ defined below.
) CREATE FUNCTION get_head(BOOLEAN)
) RETURNS TEXT LANGUAGE sql CALLED ON NULL INPUT
) AS ‘SELECT val FROM t WHERE $1 OR id > 0 ORDER BY id LIMIT 1;’;
49) I would like to restore the database cluster from the ‘db1.dump’ backup file.
- pg_dump –restore db1 < db1.dump
- pg_resetxlog -U postgres db1 < db1.dump
- pg_restore -U postgres -f db1.dump db1
- psql -U postgres -f db1.dump db1
) Select the correct command from below. (Note: ‘postgres’ is the superuser)
50) Select one option which cannot be specified using createdb.
- Database locale
- Host name
- Character encoding
- Database owner
51) Select the correct command to collect and save the statistical information of a table.
- STATISTIC COLLECTION
- REINDEX
- STATISTIC COLLECTOR
- ANALYZE
52) What does the following command do? Choose the most appropriate statement from the
- Writes a backup of the database postgres to the file pgsql.
- Writes a backup of the entire database cluster using user postgres to the file pgsql.
- Writes a backup of the entire database cluster to the file postgres and writes an error message to the file pgsql.
- Backs up the database postgres and writes an error message to the file pgsql.
) selection below.
)
) Note: $ is the command prompt.
) $ pg_dump postgres > pgsql
53) Select suitable statements regarding the pg_dump command.
- pg_dump is an SQL command.
- Only the user who executed initdb can execute pg_dump.
- pg_dump can create a backup while postmaster is stopped.
- pg_dump can create a backup of a specified table
54) PostgreSQL can use an index to access a table. Select an incorrect statements about indexes.
- An index is created by ‘CREATE INDEX’, and deleted by ‘DROP INDEX’.
- By using an index effectively, searching and sorting performs faster.
- Creating an unused index does not affect the performance of a database at all.
- There are B-tree, Hash, GIN and GiST index types.
55) What does the following command do? Select the correct description from below.
- Collects statistical information related to the content of the database foo.
- Collects statistical information related to the content of the table foo.
- Collects statistical information related to the content of the database test.
- Outputs statistical information related to the content of the table foo.
) Note: ‘text=#’ is the command prompt for psql.
) test=# ANALYZE foo;
56) I would like to check the privileges on the ‘items’ table in psql. Select the most appropriate
- \t items
- \p items
- \d items
- \z items
) command.
57) Select a correct SQL command to change existing user ‘george”s password to ‘michael’.
- ALTER USER george CHANGE PASSWORD ‘michael’;
- ALTER USER george SET PASSWORD ‘michael’;
- ALTER USER george ALTER PASSWORD ‘michael’;
- ALTER USER george WITH PASSWORD ‘michael’;
58) Select one incorrect statement about the command shown below.
- If there is a database owned by foo, an error will occur.
- If admin doesn’t have the superuser privilege, an error will occur.
- The user admin is removing the user foo.
- If admin is not the owner of foo, an error will occur.
) Note: $ is the command prompt.
) $ dropuser -U admin foo
59) It is possible to backup a database cluster by copying the entire data directory. Select suitable descriptions regarding this backup method
- The backup data will be a text file consisting of SQL statements.
- The database server must be stopped prior to the backup.
- The ‘pg_restore’ command is used to restore the database.
- psql’ is used to restore the database.
60) The following SQL defines an INSERT with respect to item_view.
- RULE
- TRIGGER
- VIEW
- FUNCTION