-3

How do you define variable value that includes new line?

const statement = "SELECT *
                   FROM `users` u;";

enter image description here

It shows error newline in string.

1

1 Answer 1

3

You would normally use a raw string literal like this

const s = `first line
second line`

However, this is not possible in your case since the string itself contains backticks. In this case I would use + to connect the lines:

const statement = "SELECT *" +
                  " FROM `users` u;";

The string value in this example does not contain a newline (but that's ok for SQL). If you really want a newline in the string, use the escape sequence \n.

const s = "first line\nsecond line"
Sign up to request clarification or add additional context in comments.

1 Comment

It’s also OK to remove the backticks from the SQL, since “users” is not a reserved word in any flavour of SQL. MySQL unfortunately dumps schema with every entity name backtick wrapped, whether it needs it or not.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.