Closed rpedela closed 8 years ago
Below is how Postgres format() handles timestamps, numbers, booleans. Either pg-escape crashes or does not do the right thing for these data types. I did not test arrays. Also how should objects be handled? Should they be converted to JSON strings?
format()
pg-escape
select format('SELECT %I', TRUE); -------------------------------------- SELECT "t" select format('SELECT %I', FALSE); -------------------------------------- SELECT "f" select format('SELECT %I', now()); -------------------------------------- SELECT "2014-09-11 00:02:43.486377+00" select format('SELECT %I', 45); -------------------------------------- SELECT "45" select format('SELECT %I', 45.13); -------------------------------------- SELECT "45.13"
select format('SELECT %L', TRUE); -------------------------------------- SELECT 't' select format('SELECT %L', FALSE); -------------------------------------- SELECT 'f' select format('SELECT %L', now()); -------------------------------------- SELECT '2014-09-11 00:02:43.486377+00' select format('SELECT %L', 45); -------------------------------------- SELECT '45' select format('SELECT %L', 45.13); -------------------------------------- SELECT '45.13'
select format('SELECT %s', TRUE); -------------------------------------- SELECT t select format('SELECT %s', FALSE); -------------------------------------- SELECT f select format('SELECT %s', now()); -------------------------------------- SELECT 2014-09-11 00:02:43.486377+00 select format('SELECT %s', 45); -------------------------------------- SELECT 45 select format('SELECT %s', 45.13); -------------------------------------- SELECT 45.13
For anyone who needs this: https://github.com/datalanche/node-pg-format
Below is how Postgres
format()
handles timestamps, numbers, booleans. Eitherpg-escape
crashes or does not do the right thing for these data types. I did not test arrays. Also how should objects be handled? Should they be converted to JSON strings?Identifier formatting
Literal formatting
String formatting