I am trying to write a select query that should return a column value enclosed in a single quote. Let's say a column (ABC) has
Values: 123 567
Request must return
Output: '123' '567'
When dealing with numeric data, you can just concatenate. NULL values ββremain NULL. But for character data (or the like) that may need escaping, use the correct functions.
NULL
quote_nullable()orquote_literal() - depending on whether you have NULL values:
quote_nullable()
quote_literal()
SELECT quote_nullable(val) AS quoted_val FROM tbl;
Details for citation:
, SQL escape:
nunks=# select '''I''m escaping a string'''; ?column? ------------------------- 'I'm escaping a string' (1 row)
||:
nunks=# create table numbers (number int); CREATE TABLE nunks=# insert into numbers values (151515); INSERT 0 1 nunks=# select number from numbers; number -------- 151515 (1 row) nunks=# select ''''||number||'''' from numbers; ?column? ---------- '151515' (1 row)
, , E:
nunks=# select E'\''||number||E'\'' from numbers; ?column? ---------- '151515' (1 row)
Source: https://habr.com/ru/post/1684802/More articles:What are the differences between KTable and GlobalKTable and leftJoin () vs outerJoin ()? - apache-kafkaQt - Android app immediately fires - c ++there is an asynchronous problem in redis - redisCreating lists of lists with a new item at each position - listIOS / Swift x509 certificate character string - iosWPF app with OnScreenKeyboard on a Windows Tablet - c #Why for methods that call async methods? - asynchronousPhoton Networking Unity AllProperties not installing - c #Delphi TThread descendant return result - delphiCreating a network of objects from a custom XML configuration using Spring - javaAll Articles