I discovered today, to my horror, that Postgres accepts newline characters inside single- and double-quoted string literals:
postgres=# select 'a
postgres'# b';
┌──────────┐
│ ?column? │
├──────────┤
│ a ↵│
│ b │
└──────────┘
(1 row)
This lead to a really confusing syntax error today in a query with a typo:
SELECT "updateFields"->>'enumTypeName"
FROM input
...
I wish Postgres would report a syntax error at the end of the line after 'enumTypeName"
instead of in a random location way down in the query...is there any way to turn off tolerating newlines inside non-$$
-quoted string literals? It does more harm than good.
I discovered today, to my horror, that Postgres accepts newline characters inside single- and double-quoted string literals:
postgres=# select 'a
postgres'# b';
┌──────────┐
│ ?column? │
├──────────┤
│ a ↵│
│ b │
└──────────┘
(1 row)
This lead to a really confusing syntax error today in a query with a typo:
SELECT "updateFields"->>'enumTypeName"
FROM input
...
I wish Postgres would report a syntax error at the end of the line after 'enumTypeName"
instead of in a random location way down in the query...is there any way to turn off tolerating newlines inside non-$$
-quoted string literals? It does more harm than good.
- 3 The answer is no. – Adrian Klaver Commented Feb 4 at 22:22
- Why would that be an error? – Frank Heikens Commented Feb 4 at 23:27
- Most programming languages I’ve worked with don’t allow newlines in string literals, so I didn’t anticipate that SQL is like this. It’s fine when you’re writing code in an IDE with syntax checking, but pretty painful when your dynamically generated query has a syntax error that’s hard to locate – Andy Commented Feb 6 at 15:54
- If you’re very used to SQL you probably take it for granted. If you’re not it seems very questionable. I’ve been writing SQL for half a dozen years without realizing this – Andy Commented Feb 6 at 15:57
1 Answer
Reset to default 2There is not a possibility in standard Postgres. But you can write a own extension and assign it to post analyze hook, and proposed check can be implemented there.
I don't know any database, that disallow new line in the string.