A higher resolution is required to access the IDE
- 55
Learning Opportunities
This puzzle can be solved using the following concepts. Practice using these concepts and improve your skills.
Statement
Goal
Given a SQL file, you must:- remove the INSERT statements that are actually inserting data in the database
- keep the INSERT statements that are embedded in functions.
- All others statements must remains the same
SQL syntax to consider:
- INSERT statement is a statement that starts with the
- comments begin with
- the syntax used to denote the body of functions:
BEGIN start of body
END end of body
BEGIN andEND keywords are always at the start of a line.
Body is the main part of the function where SQL statements must be checked. If INSERT statements are written in this part, INSERT statements must be kept.
-
EXAMPLES:
- Example of INSERT statement that must be removed:
INSERT INTO ref_metric
VALUES (767, 'make it clear', 'some description', 2, 'LOW');
=> VALUES are hardcoded values or string literals
- Example of INSERT statement that must be kept:
CREATE FUNCTION my_function(pObj integer, pUser integer)
LANGUAGE plpgsql
AS $$
declare
begin
INSERT INTO lk_table(nb_object, id_user, stat)
VALUES ( pObj, pUser);
end;
=> VALUES are variables, INSERT is embedded in the body of a function. The body is defined by
TIP:
- You can copy/paste input file on some sql beautifier tools online to help you to identify relevant lines to remove.
- SQL statements are real statements that can be executed in SQL tools.
Input
Line 1: An integer n for the number of lines to read
Next n lines: SQL statements to parse
Next n lines: SQL statements to parse
Output
m lines: SQL statements cleaned up without INSERT statements that are doing data insertion in the database. comments must remain in the output. m is the number of lines that remain.
Constraints
Example
Input
8 CREATE TABLE vendeur ( id character integer NOT NULL, date_creation timestamp without time zone, name text, id_createur character varying(32), amount double precision, ); insert into vendeur(id,date_creation, name, id_createur, amount) values(1,'12/08/2020','John',1,100);
Output
CREATE TABLE vendeur ( id character integer NOT NULL, date_creation timestamp without time zone, name text, id_createur character varying(32), amount double precision, );
A higher resolution is required to access the IDE