nerdexam
Snowflake

SOL-C01 · Question #166

You are loading data into a Snowflake table 'EMPLOYEE DATA (EMP_ID INT, EMP NAME VARCHAR, DEPARTMENT VARCHAR)' using 'INSERT' statements. You notice that some of the 'EMP NAME values in your source da

The correct answer is A. Replace each single quote (') with two single quotes (") in the `EMP NAME' values before C. Use parameterized queries or prepared statements to insert the data.. Escaping single quotes by doubling them ('') is standard SQL syntax - O'Brien becomes 'O''Brien' - and Snowflake, like all SQL-compliant databases, treats two consecutive single quotes inside a string literal as one literal quote character. Parameterized queries (option C) solve

Data Loading and Unloading

Question

You are loading data into a Snowflake table 'EMPLOYEE DATA (EMP_ID INT, EMP NAME VARCHAR, DEPARTMENT VARCHAR)' using 'INSERT' statements. You notice that some of the 'EMP NAME values in your source data contain single quotes ('). Which of the following methods can you use to ensure that these values are correctly inserted into the table without causing syntax errors?

Options

  • AReplace each single quote (') with two single quotes (") in the `EMP NAME' values before
  • BEnclose the EMP_NAME values in double quotes (") instead of single quotes in theINSERT
  • CUse parameterized queries or prepared statements to insert the data.
  • DBefore inserting, use 'REPLACE(EMP NAME, "", in the INSERT statement to escape the single
  • ERemove special characters and single quotes from all EMP_NAME.

How the community answered

(44 responses)
  • A
    66% (29)
  • B
    5% (2)
  • D
    20% (9)
  • E
    9% (4)

Explanation

Escaping single quotes by doubling them ('') is standard SQL syntax - O'Brien becomes 'O''Brien' - and Snowflake, like all SQL-compliant databases, treats two consecutive single quotes inside a string literal as one literal quote character. Parameterized queries (option C) solve the problem at a different level: values are passed as bound parameters separate from the SQL text, so the driver handles all escaping automatically and the single quote never touches the query string.

Why the distractors fail:

  • B is wrong because double quotes in SQL denote identifiers (column/table names), not string values - using them around a string literal will cause a syntax or reference error in Snowflake.
  • D is wrong because REPLACE() can't help here - the SQL statement already fails to parse before any function can execute on a string that contains an unescaped single quote.
  • E is wrong because stripping single quotes destroys data (e.g., O'BrienOBrien), which is data loss, not a correct insertion.

Memory tip: Think "double up or hand it off" - either double the offending quote ('') yourself, or hand the value off to a parameterized query and let the driver deal with it. Both options put the quote inside the value safely; the distractors either misuse SQL syntax or corrupt the data.

Topics

#INSERT statements#String escaping#Parameterized queries#Single quote handling

Community Discussion

No community discussion yet for this question.

Full SOL-C01 Practice