on dev help sign in
Update tests to expect quoted identifiers
0bd30cePetter Rasmussen
squeal-postgresql/src/Squeal/PostgreSQL.hs+5−5
@@ -80,7 +80,7 @@
80-- We can easily see the generated SQL is unsuprising looking.
80-- We can easily see the generated SQL is unsuprising looking.
81--
81--
82-- >>> renderDefinition setup
82-- >>> renderDefinition setup
83−-- "CREATE TABLE users (id serial, name text NOT NULL, CONSTRAINT pk_users PRIMARY KEY (id)); CREATE TABLE emails (id serial, user_id int NOT NULL, email text, CONSTRAINT pk_emails PRIMARY KEY (id), CONSTRAINT fk_user_id FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE ON UPDATE CASCADE);"
83+-- "CREATE TABLE \"users\" (\"id\" serial, \"name\" text NOT NULL, CONSTRAINT \"pk_users\" PRIMARY KEY (\"id\")); CREATE TABLE \"emails\" (\"id\" serial, \"user_id\" int NOT NULL, \"email\" text, CONSTRAINT \"pk_emails\" PRIMARY KEY (\"id\"), CONSTRAINT \"fk_user_id\" FOREIGN KEY (\"user_id\") REFERENCES \"users\" (\"id\") ON DELETE CASCADE ON UPDATE CASCADE);"
84--
84--
85-- Notice that @setup@ starts with an empty schema @'[]@ and produces @Schema@.
85-- Notice that @setup@ starts with an empty schema @'[]@ and produces @Schema@.
86-- In our `createTable` commands we included `TableConstraint`s to define
86-- In our `createTable` commands we included `TableConstraint`s to define
@@ -94,7 +94,7 @@
94-- :}
94-- :}
95--
95--
96-- >>> renderDefinition teardown
96-- >>> renderDefinition teardown
97−-- "DROP TABLE emails; DROP TABLE users;"
97+-- "DROP TABLE \"emails\"; DROP TABLE \"users\";"
98--
98--
99-- Next, we'll write `Manipulation`s to insert data into our two tables.
99-- Next, we'll write `Manipulation`s to insert data into our two tables.
100-- A `Manipulation` is an `insertRow` (or other inserts), `update`
100-- A `Manipulation` is an `insertRow` (or other inserts), `update`
@@ -127,9 +127,9 @@
127-- :}
127-- :}
128--
128--
129-- >>> renderManipulation insertUser
129-- >>> renderManipulation insertUser
130−-- "INSERT INTO users (id, name) VALUES (DEFAULT, ($1 :: text)) ON CONFLICT DO NOTHING RETURNING id AS fromOnly;"
130+-- "INSERT INTO \"users\" (\"id\", \"name\") VALUES (DEFAULT, ($1 :: text)) ON CONFLICT DO NOTHING RETURNING \"id\" AS \"fromOnly\";"
131-- >>> renderManipulation insertEmail
131-- >>> renderManipulation insertEmail
132−-- "INSERT INTO emails (id, user_id, email) VALUES (DEFAULT, ($1 :: int4), ($2 :: text)) ON CONFLICT DO NOTHING;"
132+-- "INSERT INTO \"emails\" (\"id\", \"user_id\", \"email\") VALUES (DEFAULT, ($1 :: int4), ($2 :: text)) ON CONFLICT DO NOTHING;"
133--
133--
134-- Next we write a `Query` to retrieve users from the database. We're not
134-- Next we write a `Query` to retrieve users from the database. We're not
135-- interested in the ids here, just the usernames and email addresses. We
135-- interested in the ids here, just the usernames and email addresses. We
@@ -149,7 +149,7 @@
149-- :}
149-- :}
150--
150--
151-- >>> renderQuery getUsers
151-- >>> renderQuery getUsers
152−-- "SELECT u.name AS userName, e.email AS userEmail FROM users AS u INNER JOIN emails AS e ON (u.id = e.user_id)"
152+-- "SELECT \"u\".\"name\" AS \"userName\", \"e\".\"email\" AS \"userEmail\" FROM \"users\" AS \"u\" INNER JOIN \"emails\" AS \"e\" ON (\"u\".\"id\" = \"e\".\"user_id\")"
153--
153--
154-- Now that we've defined the SQL side of things, we'll need a Haskell type
154-- Now that we've defined the SQL side of things, we'll need a Haskell type
155-- for users. We give the type `Generics.SOP.Generic` and
155-- for users. We give the type `Generics.SOP.Generic` and
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+19−19
@@ -110,7 +110,7 @@ CREATE statements
110-- renderDefinition $
110-- renderDefinition $
111-- createTable #tab (int `As` #a :* real `As` #b :* Nil) Nil
111-- createTable #tab (int `As` #a :* real `As` #b :* Nil) Nil
112-- :}
112-- :}
113−-- "CREATE TABLE tab (a int, b real);"
113+-- "CREATE TABLE \"tab\" (\"a\" int, \"b\" real);"
114createTable
114createTable
115 :: ( KnownSymbol table
115 :: ( KnownSymbol table
116 , columns ~ (col ': cols)
116 , columns ~ (col ': cols)
@@ -136,7 +136,7 @@ createTable table columns constraints = UnsafeDefinition $
136-- renderDefinition
136-- renderDefinition
137-- (createTableIfNotExists #tab (int `As` #a :* real `As` #b :* Nil) Nil :: Definition Schema Schema)
137-- (createTableIfNotExists #tab (int `As` #a :* real `As` #b :* Nil) Nil :: Definition Schema Schema)
138-- :}
138-- :}
139−-- "CREATE TABLE IF NOT EXISTS tab (a int, b real);"
139+-- "CREATE TABLE IF NOT EXISTS \"tab\" (\"a\" int, \"b\" real);"
140createTableIfNotExists
140createTableIfNotExists
141 :: ( Has table schema (constraints :=> columns)
141 :: ( Has table schema (constraints :=> columns)
142 , SOP.SListI columns
142 , SOP.SListI columns
@@ -225,7 +225,7 @@ renderColumn (Column column) = renderAlias column
225-- (int & notNull) `As` #b :* Nil )
225-- (int & notNull) `As` #b :* Nil )
226-- ( check (Column #a :* Column #b :* Nil) (#a .> #b) `As` #inequality :* Nil )
226-- ( check (Column #a :* Column #b :* Nil) (#a .> #b) `As` #inequality :* Nil )
227-- :}
227-- :}
228−-- "CREATE TABLE tab (a int NOT NULL, b int NOT NULL, CONSTRAINT inequality CHECK ((a > b)));"
228+-- "CREATE TABLE \"tab\" (\"a\" int NOT NULL, \"b\" int NOT NULL, CONSTRAINT \"inequality\" CHECK ((\"a\" > \"b\")));"
229check
229check
230 :: NP (Column columns) subcolumns
230 :: NP (Column columns) subcolumns
231 -> Condition '[table ::: ColumnsToRelation subcolumns] 'Ungrouped '[]
231 -> Condition '[table ::: ColumnsToRelation subcolumns] 'Ungrouped '[]
@@ -244,7 +244,7 @@ check _cols condition = UnsafeTableConstraintExpression $
244-- int `As` #b :* Nil )
244-- int `As` #b :* Nil )
245-- ( unique (Column #a :* Column #b :* Nil) `As` #uq_a_b :* Nil )
245-- ( unique (Column #a :* Column #b :* Nil) `As` #uq_a_b :* Nil )
246-- :}
246-- :}
247−-- "CREATE TABLE tab (a int, b int, CONSTRAINT uq_a_b UNIQUE (a, b));"
247+-- "CREATE TABLE \"tab\" (\"a\" int, \"b\" int, CONSTRAINT \"uq_a_b\" UNIQUE (\"a\", \"b\"));"
248unique
248unique
249 :: SOP.SListI subcolumns
249 :: SOP.SListI subcolumns
250 => NP (Column columns) subcolumns
250 => NP (Column columns) subcolumns
@@ -264,7 +264,7 @@ unique columns = UnsafeTableConstraintExpression $
264-- (text & notNull) `As` #name :* Nil )
264-- (text & notNull) `As` #name :* Nil )
265-- ( primaryKey (Column #id :* Nil) `As` #pk_id :* Nil )
265-- ( primaryKey (Column #id :* Nil) `As` #pk_id :* Nil )
266-- :}
266-- :}
267−-- "CREATE TABLE tab (id serial, name text NOT NULL, CONSTRAINT pk_id PRIMARY KEY (id));"
267+-- "CREATE TABLE \"tab\" (\"id\" serial, \"name\" text NOT NULL, CONSTRAINT \"pk_id\" PRIMARY KEY (\"id\"));"
268primaryKey
268primaryKey
269 :: (SOP.SListI subcolumns, AllNotNull subcolumns)
269 :: (SOP.SListI subcolumns, AllNotNull subcolumns)
270 => NP (Column columns) subcolumns
270 => NP (Column columns) subcolumns
@@ -313,7 +313,7 @@ primaryKey columns = UnsafeTableConstraintExpression $
313-- OnDeleteCascade OnUpdateCascade `As` #fk_user_id :* Nil )
313-- OnDeleteCascade OnUpdateCascade `As` #fk_user_id :* Nil )
314-- in renderDefinition setup
314-- in renderDefinition setup
315-- :}
315-- :}
316−-- "CREATE TABLE users (id serial, name text NOT NULL, CONSTRAINT pk_users PRIMARY KEY (id)); CREATE TABLE emails (id serial, user_id int NOT NULL, email text, CONSTRAINT pk_emails PRIMARY KEY (id), CONSTRAINT fk_user_id FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE ON UPDATE CASCADE);"
316+-- "CREATE TABLE \"users\" (\"id\" serial, \"name\" text NOT NULL, CONSTRAINT \"pk_users\" PRIMARY KEY (\"id\")); CREATE TABLE \"emails\" (\"id\" serial, \"user_id\" int NOT NULL, \"email\" text, CONSTRAINT \"pk_emails\" PRIMARY KEY (\"id\"), CONSTRAINT \"fk_user_id\" FOREIGN KEY (\"user_id\") REFERENCES \"users\" (\"id\") ON DELETE CASCADE ON UPDATE CASCADE);"
317foreignKey
317foreignKey
318 :: ForeignKeyed schema table reftable subcolumns refsubcolumns
318 :: ForeignKeyed schema table reftable subcolumns refsubcolumns
319 => NP (Column columns) subcolumns
319 => NP (Column columns) subcolumns
@@ -390,7 +390,7 @@ DROP statements
390-- | `dropTable` removes a table from the schema.
390-- | `dropTable` removes a table from the schema.
391--
391--
392-- >>> renderDefinition $ dropTable #muh_table
392-- >>> renderDefinition $ dropTable #muh_table
393−-- "DROP TABLE muh_table;"
393+-- "DROP TABLE \"muh_table\";"
394dropTable
394dropTable
395 :: KnownSymbol table
395 :: KnownSymbol table
396 => Alias table -- ^ table to remove
396 => Alias table -- ^ table to remove
@@ -416,7 +416,7 @@ alterTable table alteration = UnsafeDefinition $
416-- | `alterTableRename` changes the name of a table from the schema.
416-- | `alterTableRename` changes the name of a table from the schema.
417--
417--
418-- >>> renderDefinition $ alterTableRename #foo #bar
418-- >>> renderDefinition $ alterTableRename #foo #bar
419−-- "ALTER TABLE foo RENAME TO bar;"
419+-- "ALTER TABLE \"foo\" RENAME TO \"bar\";"
420alterTableRename
420alterTableRename
421 :: (KnownSymbol table0, KnownSymbol table1)
421 :: (KnownSymbol table0, KnownSymbol table1)
422 => Alias table0 -- ^ table to rename
422 => Alias table0 -- ^ table to rename
@@ -445,7 +445,7 @@ newtype AlterTable
445-- definition = alterTable #tab (addConstraint #positive (check (Column #col :* Nil) (#col .> 0)))
445-- definition = alterTable #tab (addConstraint #positive (check (Column #col :* Nil) (#col .> 0)))
446-- in renderDefinition definition
446-- in renderDefinition definition
447-- :}
447-- :}
448−-- "ALTER TABLE tab ADD CONSTRAINT positive CHECK ((col > 0));"
448+-- "ALTER TABLE \"tab\" ADD CONSTRAINT \"positive\" CHECK ((\"col\" > 0));"
449addConstraint
449addConstraint
450 :: KnownSymbol alias
450 :: KnownSymbol alias
451 => Alias alias
451 => Alias alias
@@ -467,7 +467,7 @@ addConstraint alias constraint = UnsafeAlterTable $
467-- definition = alterTable #tab (dropConstraint #positive)
467-- definition = alterTable #tab (dropConstraint #positive)
468-- in renderDefinition definition
468-- in renderDefinition definition
469-- :}
469-- :}
470−-- "ALTER TABLE tab DROP CONSTRAINT positive;"
470+-- "ALTER TABLE \"tab\" DROP CONSTRAINT \"positive\";"
471dropConstraint
471dropConstraint
472 :: KnownSymbol constraint
472 :: KnownSymbol constraint
473 => Alias constraint
473 => Alias constraint
@@ -493,7 +493,7 @@ class AddColumn ty where
493 -- definition = alterTable #tab (addColumn #col2 (text & default_ "foo"))
493 -- definition = alterTable #tab (addColumn #col2 (text & default_ "foo"))
494 -- in renderDefinition definition
494 -- in renderDefinition definition
495 -- :}
495 -- :}
496− -- "ALTER TABLE tab ADD COLUMN col2 text DEFAULT E'foo';"
496+ -- "ALTER TABLE \"tab\" ADD COLUMN \"col2\" text DEFAULT E'foo';"
497 --
497 --
498 -- >>> :{
498 -- >>> :{
499 -- let
499 -- let
@@ -505,7 +505,7 @@ class AddColumn ty where
505 -- definition = alterTable #tab (addColumn #col2 text)
505 -- definition = alterTable #tab (addColumn #col2 text)
506 -- in renderDefinition definition
506 -- in renderDefinition definition
507 -- :}
507 -- :}
508− -- "ALTER TABLE tab ADD COLUMN col2 text;"
508+ -- "ALTER TABLE \"tab\" ADD COLUMN \"col2\" text;"
509 addColumn
509 addColumn
510 :: KnownSymbol column
510 :: KnownSymbol column
511 => Alias column -- ^ column to add
511 => Alias column -- ^ column to add
@@ -532,7 +532,7 @@ instance {-# OVERLAPPABLE #-} AddColumn ('NoDef :=> 'Null ty)
532-- definition = alterTable #tab (dropColumn #col2)
532-- definition = alterTable #tab (dropColumn #col2)
533-- in renderDefinition definition
533-- in renderDefinition definition
534-- :}
534-- :}
535−-- "ALTER TABLE tab DROP COLUMN col2;"
535+-- "ALTER TABLE \"tab\" DROP COLUMN \"col2\";"
536dropColumn
536dropColumn
537 :: KnownSymbol column
537 :: KnownSymbol column
538 => Alias column -- ^ column to remove
538 => Alias column -- ^ column to remove
@@ -552,7 +552,7 @@ dropColumn column = UnsafeAlterTable $
552-- definition = alterTable #tab (renameColumn #foo #bar)
552-- definition = alterTable #tab (renameColumn #foo #bar)
553-- in renderDefinition definition
553-- in renderDefinition definition
554-- :}
554-- :}
555−-- "ALTER TABLE tab RENAME COLUMN foo TO bar;"
555+-- "ALTER TABLE \"tab\" RENAME COLUMN \"foo\" TO \"bar\";"
556renameColumn
556renameColumn
557 :: (KnownSymbol column0, KnownSymbol column1)
557 :: (KnownSymbol column0, KnownSymbol column1)
558 => Alias column0 -- ^ column to rename
558 => Alias column0 -- ^ column to rename
@@ -589,7 +589,7 @@ newtype AlterColumn (ty0 :: ColumnType) (ty1 :: ColumnType) =
589-- definition = alterTable #tab (alterColumn #col (setDefault 5))
589-- definition = alterTable #tab (alterColumn #col (setDefault 5))
590-- in renderDefinition definition
590-- in renderDefinition definition
591-- :}
591-- :}
592−-- "ALTER TABLE tab ALTER COLUMN col SET DEFAULT 5;"
592+-- "ALTER TABLE \"tab\" ALTER COLUMN \"col\" SET DEFAULT 5;"
593setDefault
593setDefault
594 :: Expression '[] 'Ungrouped '[] ty -- ^ default value to set
594 :: Expression '[] 'Ungrouped '[] ty -- ^ default value to set
595 -> AlterColumn (constraint :=> ty) ('Def :=> ty)
595 -> AlterColumn (constraint :=> ty) ('Def :=> ty)
@@ -606,7 +606,7 @@ setDefault expression = UnsafeAlterColumn $
606-- definition = alterTable #tab (alterColumn #col dropDefault)
606-- definition = alterTable #tab (alterColumn #col dropDefault)
607-- in renderDefinition definition
607-- in renderDefinition definition
608-- :}
608-- :}
609−-- "ALTER TABLE tab ALTER COLUMN col DROP DEFAULT;"
609+-- "ALTER TABLE \"tab\" ALTER COLUMN \"col\" DROP DEFAULT;"
610dropDefault :: AlterColumn ('Def :=> ty) ('NoDef :=> ty)
610dropDefault :: AlterColumn ('Def :=> ty) ('NoDef :=> ty)
611dropDefault = UnsafeAlterColumn $ "DROP DEFAULT"
611dropDefault = UnsafeAlterColumn $ "DROP DEFAULT"
612
612
@@ -622,7 +622,7 @@ dropDefault = UnsafeAlterColumn $ "DROP DEFAULT"
622-- definition = alterTable #tab (alterColumn #col setNotNull)
622-- definition = alterTable #tab (alterColumn #col setNotNull)
623-- in renderDefinition definition
623-- in renderDefinition definition
624-- :}
624-- :}
625−-- "ALTER TABLE tab ALTER COLUMN col SET NOT NULL;"
625+-- "ALTER TABLE \"tab\" ALTER COLUMN \"col\" SET NOT NULL;"
626setNotNull
626setNotNull
627 :: AlterColumn (constraint :=> 'Null ty) (constraint :=> 'NotNull ty)
627 :: AlterColumn (constraint :=> 'Null ty) (constraint :=> 'NotNull ty)
628setNotNull = UnsafeAlterColumn $ "SET NOT NULL"
628setNotNull = UnsafeAlterColumn $ "SET NOT NULL"
@@ -637,7 +637,7 @@ setNotNull = UnsafeAlterColumn $ "SET NOT NULL"
637-- definition = alterTable #tab (alterColumn #col dropNotNull)
637-- definition = alterTable #tab (alterColumn #col dropNotNull)
638-- in renderDefinition definition
638-- in renderDefinition definition
639-- :}
639-- :}
640−-- "ALTER TABLE tab ALTER COLUMN col DROP NOT NULL;"
640+-- "ALTER TABLE \"tab\" ALTER COLUMN \"col\" DROP NOT NULL;"
641dropNotNull
641dropNotNull
642 :: AlterColumn (constraint :=> 'NotNull ty) (constraint :=> 'Null ty)
642 :: AlterColumn (constraint :=> 'NotNull ty) (constraint :=> 'Null ty)
643dropNotNull = UnsafeAlterColumn $ "DROP NOT NULL"
643dropNotNull = UnsafeAlterColumn $ "DROP NOT NULL"
@@ -655,6 +655,6 @@ dropNotNull = UnsafeAlterColumn $ "DROP NOT NULL"
655-- alterTable #tab (alterColumn #col (alterType (numeric & notNull)))
655-- alterTable #tab (alterColumn #col (alterType (numeric & notNull)))
656-- in renderDefinition definition
656-- in renderDefinition definition
657-- :}
657-- :}
658−-- "ALTER TABLE tab ALTER COLUMN col TYPE numeric NOT NULL;"
658+-- "ALTER TABLE \"tab\" ALTER COLUMN \"col\" TYPE numeric NOT NULL;"
659alterType :: TypeExpression ty -> AlterColumn ty0 ty
659alterType :: TypeExpression ty -> AlterColumn ty0 ty
660alterType ty = UnsafeAlterColumn $ "TYPE" <+> renderTypeExpression ty
660alterType ty = UnsafeAlterColumn $ "TYPE" <+> renderTypeExpression ty
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+14−14
@@ -797,7 +797,7 @@ unsafeAggregateDistinct fun x = UnsafeExpression $ mconcat
797-- expression = sum_ #col
797-- expression = sum_ #col
798-- in renderExpression expression
798-- in renderExpression expression
799-- :}
799-- :}
800−-- "sum(col)"
800+-- "sum(\"col\")"
801sum_
801sum_
802 :: PGNum ty
802 :: PGNum ty
803 => Expression relations 'Ungrouped params (nullity ty)
803 => Expression relations 'Ungrouped params (nullity ty)
@@ -811,7 +811,7 @@ sum_ = unsafeAggregate "sum"
811-- expression = sumDistinct #col
811-- expression = sumDistinct #col
812-- in renderExpression expression
812-- in renderExpression expression
813-- :}
813-- :}
814−-- "sum(DISTINCT col)"
814+-- "sum(DISTINCT \"col\")"
815sumDistinct
815sumDistinct
816 :: PGNum ty
816 :: PGNum ty
817 => Expression relations 'Ungrouped params (nullity ty)
817 => Expression relations 'Ungrouped params (nullity ty)
@@ -842,7 +842,7 @@ instance PGAvg 'PGinterval 'PGinterval
842-- expression = bitAnd #col
842-- expression = bitAnd #col
843-- in renderExpression expression
843-- in renderExpression expression
844-- :}
844-- :}
845−-- "bit_and(col)"
845+-- "bit_and(\"col\")"
846bitAnd
846bitAnd
847 :: PGIntegral int
847 :: PGIntegral int
848 => Expression relations 'Ungrouped params (nullity int)
848 => Expression relations 'Ungrouped params (nullity int)
@@ -856,7 +856,7 @@ bitAnd = unsafeAggregate "bit_and"
856-- expression = bitOr #col
856-- expression = bitOr #col
857-- in renderExpression expression
857-- in renderExpression expression
858-- :}
858-- :}
859−-- "bit_or(col)"
859+-- "bit_or(\"col\")"
860bitOr
860bitOr
861 :: PGIntegral int
861 :: PGIntegral int
862 => Expression relations 'Ungrouped params (nullity int)
862 => Expression relations 'Ungrouped params (nullity int)
@@ -870,7 +870,7 @@ bitOr = unsafeAggregate "bit_or"
870-- expression = bitAndDistinct #col
870-- expression = bitAndDistinct #col
871-- in renderExpression expression
871-- in renderExpression expression
872-- :}
872-- :}
873−-- "bit_and(DISTINCT col)"
873+-- "bit_and(DISTINCT \"col\")"
874bitAndDistinct
874bitAndDistinct
875 :: PGIntegral int
875 :: PGIntegral int
876 => Expression relations 'Ungrouped params (nullity int)
876 => Expression relations 'Ungrouped params (nullity int)
@@ -884,7 +884,7 @@ bitAndDistinct = unsafeAggregateDistinct "bit_and"
884-- expression = bitOrDistinct #col
884-- expression = bitOrDistinct #col
885-- in renderExpression expression
885-- in renderExpression expression
886-- :}
886-- :}
887−-- "bit_or(DISTINCT col)"
887+-- "bit_or(DISTINCT \"col\")"
888bitOrDistinct
888bitOrDistinct
889 :: PGIntegral int
889 :: PGIntegral int
890 => Expression relations 'Ungrouped params (nullity int)
890 => Expression relations 'Ungrouped params (nullity int)
@@ -898,7 +898,7 @@ bitOrDistinct = unsafeAggregateDistinct "bit_or"
898-- expression = boolAnd #col
898-- expression = boolAnd #col
899-- in renderExpression expression
899-- in renderExpression expression
900-- :}
900-- :}
901−-- "bool_and(col)"
901+-- "bool_and(\"col\")"
902boolAnd
902boolAnd
903 :: Expression relations 'Ungrouped params (nullity 'PGbool)
903 :: Expression relations 'Ungrouped params (nullity 'PGbool)
904 -- ^ what to aggregate
904 -- ^ what to aggregate
@@ -911,7 +911,7 @@ boolAnd = unsafeAggregate "bool_and"
911-- expression = boolOr #col
911-- expression = boolOr #col
912-- in renderExpression expression
912-- in renderExpression expression
913-- :}
913-- :}
914−-- "bool_or(col)"
914+-- "bool_or(\"col\")"
915boolOr
915boolOr
916 :: Expression relations 'Ungrouped params (nullity 'PGbool)
916 :: Expression relations 'Ungrouped params (nullity 'PGbool)
917 -- ^ what to aggregate
917 -- ^ what to aggregate
@@ -924,7 +924,7 @@ boolOr = unsafeAggregate "bool_or"
924-- expression = boolAndDistinct #col
924-- expression = boolAndDistinct #col
925-- in renderExpression expression
925-- in renderExpression expression
926-- :}
926-- :}
927−-- "bool_and(DISTINCT col)"
927+-- "bool_and(DISTINCT \"col\")"
928boolAndDistinct
928boolAndDistinct
929 :: Expression relations 'Ungrouped params (nullity 'PGbool)
929 :: Expression relations 'Ungrouped params (nullity 'PGbool)
930 -- ^ what to aggregate
930 -- ^ what to aggregate
@@ -937,7 +937,7 @@ boolAndDistinct = unsafeAggregateDistinct "bool_and"
937-- expression = boolOrDistinct #col
937-- expression = boolOrDistinct #col
938-- in renderExpression expression
938-- in renderExpression expression
939-- :}
939-- :}
940−-- "bool_or(DISTINCT col)"
940+-- "bool_or(DISTINCT \"col\")"
941boolOrDistinct
941boolOrDistinct
942 :: Expression relations 'Ungrouped params (nullity 'PGbool)
942 :: Expression relations 'Ungrouped params (nullity 'PGbool)
943 -- ^ what to aggregate
943 -- ^ what to aggregate
@@ -958,7 +958,7 @@ countStar = UnsafeExpression $ "count(*)"
958-- expression = count #col
958-- expression = count #col
959-- in renderExpression expression
959-- in renderExpression expression
960-- :}
960-- :}
961−-- "count(col)"
961+-- "count(\"col\")"
962count
962count
963 :: Expression relations 'Ungrouped params ty
963 :: Expression relations 'Ungrouped params ty
964 -- ^ what to count
964 -- ^ what to count
@@ -971,7 +971,7 @@ count = unsafeAggregate "count"
971-- expression = countDistinct #col
971-- expression = countDistinct #col
972-- in renderExpression expression
972-- in renderExpression expression
973-- :}
973-- :}
974−-- "count(DISTINCT col)"
974+-- "count(DISTINCT \"col\")"
975countDistinct
975countDistinct
976 :: Expression relations 'Ungrouped params ty
976 :: Expression relations 'Ungrouped params ty
977 -- ^ what to count
977 -- ^ what to count
@@ -986,7 +986,7 @@ countDistinct = unsafeAggregateDistinct "count"
986-- expression = every #col
986-- expression = every #col
987-- in renderExpression expression
987-- in renderExpression expression
988-- :}
988-- :}
989−-- "every(col)"
989+-- "every(\"col\")"
990every
990every
991 :: Expression relations 'Ungrouped params (nullity 'PGbool)
991 :: Expression relations 'Ungrouped params (nullity 'PGbool)
992 -- ^ what to aggregate
992 -- ^ what to aggregate
@@ -1001,7 +1001,7 @@ every = unsafeAggregate "every"
1001-- expression = everyDistinct #col
1001-- expression = everyDistinct #col
1002-- in renderExpression expression
1002-- in renderExpression expression
1003-- :}
1003-- :}
1004−-- "every(DISTINCT col)"
1004+-- "every(DISTINCT \"col\")"
1005everyDistinct
1005everyDistinct
1006 :: Expression relations 'Ungrouped params (nullity 'PGbool)
1006 :: Expression relations 'Ungrouped params (nullity 'PGbool)
1007 -- ^ what to aggregate
1007 -- ^ what to aggregate
squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs+8−8
@@ -80,7 +80,7 @@ let
80 insertRow_ #tab (Set 2 `As` #col1 :* Default `As` #col2 :* Nil)
80 insertRow_ #tab (Set 2 `As` #col1 :* Default `As` #col2 :* Nil)
81in renderManipulation manipulation
81in renderManipulation manipulation
82:}
82:}
83−"INSERT INTO tab (col1, col2) VALUES (2, DEFAULT);"
83+"INSERT INTO \"tab\" (\"col1\", \"col2\") VALUES (2, DEFAULT);"
84
84
85parameterized insert:
85parameterized insert:
86
86
@@ -96,7 +96,7 @@ let
96 (Set (param @1) `As` #col1 :* Set (param @2) `As` #col2 :* Nil)
96 (Set (param @1) `As` #col1 :* Set (param @2) `As` #col2 :* Nil)
97in renderManipulation manipulation
97in renderManipulation manipulation
98:}
98:}
99−"INSERT INTO tab (col1, col2) VALUES (($1 :: int4), ($2 :: int4));"
99+"INSERT INTO \"tab\" (\"col1\", \"col2\") VALUES (($1 :: int4), ($2 :: int4));"
100
100
101returning insert:
101returning insert:
102
102
@@ -112,7 +112,7 @@ let
112 OnConflictDoRaise (Returning (#col1 `As` #fromOnly :* Nil))
112 OnConflictDoRaise (Returning (#col1 `As` #fromOnly :* Nil))
113in renderManipulation manipulation
113in renderManipulation manipulation
114:}
114:}
115−"INSERT INTO tab (col1, col2) VALUES (2, DEFAULT) RETURNING col1 AS fromOnly;"
115+"INSERT INTO \"tab\" (\"col1\", \"col2\") VALUES (2, DEFAULT) RETURNING \"col1\" AS \"fromOnly\";"
116
116
117upsert:
117upsert:
118
118
@@ -133,7 +133,7 @@ let
133 (Returning $ (#col1 + #col2) `As` #sum :* Nil)
133 (Returning $ (#col1 + #col2) `As` #sum :* Nil)
134in renderManipulation manipulation
134in renderManipulation manipulation
135:}
135:}
136−"INSERT INTO tab (col1, col2) VALUES (2, 4), (6, 8) ON CONFLICT DO UPDATE SET col1 = 2 WHERE (col1 = col2) RETURNING (col1 + col2) AS sum;"
136+"INSERT INTO \"tab\" (\"col1\", \"col2\") VALUES (2, 4), (6, 8) ON CONFLICT DO UPDATE SET \"col1\" = 2 WHERE (\"col1\" = \"col2\") RETURNING (\"col1\" + \"col2\") AS \"sum\";"
137
137
138query insert:
138query insert:
139
139
@@ -154,7 +154,7 @@ let
154 (selectStar (from (table (#other_tab `As` #t))))
154 (selectStar (from (table (#other_tab `As` #t))))
155in renderManipulation manipulation
155in renderManipulation manipulation
156:}
156:}
157−"INSERT INTO tab SELECT * FROM other_tab AS t;"
157+"INSERT INTO \"tab\" SELECT * FROM \"other_tab\" AS \"t\";"
158
158
159update:
159update:
160
160
@@ -169,7 +169,7 @@ let
169 (#col1 ./= #col2)
169 (#col1 ./= #col2)
170in renderManipulation manipulation
170in renderManipulation manipulation
171:}
171:}
172−"UPDATE tab SET col1 = 2 WHERE (col1 <> col2);"
172+"UPDATE \"tab\" SET \"col1\" = 2 WHERE (\"col1\" <> \"col2\");"
173
173
174delete:
174delete:
175
175
@@ -184,7 +184,7 @@ let
184 manipulation = deleteFrom #tab (#col1 .== #col2) ReturningStar
184 manipulation = deleteFrom #tab (#col1 .== #col2) ReturningStar
185in renderManipulation manipulation
185in renderManipulation manipulation
186:}
186:}
187−"DELETE FROM tab WHERE (col1 = col2) RETURNING *;"
187+"DELETE FROM \"tab\" WHERE (\"col1\" = \"col2\") RETURNING *;"
188-}
188-}
189newtype Manipulation
189newtype Manipulation
190 (schema :: TablesType)
190 (schema :: TablesType)
@@ -488,7 +488,7 @@ WITH statements
488-- (insertQuery_ #products_deleted (selectStar (from (table (#deleted_rows `As` #t)))))
488-- (insertQuery_ #products_deleted (selectStar (from (table (#deleted_rows `As` #t)))))
489-- in renderManipulation manipulation
489-- in renderManipulation manipulation
490-- :}
490-- :}
491−-- "WITH deleted_rows AS (DELETE FROM products WHERE (date < ($1 :: date)) RETURNING *) INSERT INTO products_deleted SELECT * FROM deleted_rows AS t;"
491+-- "WITH \"deleted_rows\" AS (DELETE FROM \"products\" WHERE (\"date\" < ($1 :: date)) RETURNING *) INSERT INTO \"products_deleted\" SELECT * FROM \"deleted_rows\" AS \"t\";"
492with
492with
493 :: SOP.SListI commons
493 :: SOP.SListI commons
494 => NP (Aliased (Manipulation schema params)) commons
494 => NP (Aliased (Manipulation schema params)) commons
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+10−10
@@ -106,7 +106,7 @@ let
106 query = selectStar (from (table (#tab `As` #t)))
106 query = selectStar (from (table (#tab `As` #t)))
107in renderQuery query
107in renderQuery query
108:}
108:}
109−"SELECT * FROM tab AS t"
109+"SELECT * FROM \"tab\" AS \"t\""
110
110
111restricted query:
111restricted query:
112
112
@@ -127,7 +127,7 @@ let
127 & where_ (#col2 .> 0) )
127 & where_ (#col2 .> 0) )
128in renderQuery query
128in renderQuery query
129:}
129:}
130−"SELECT (col1 + col2) AS sum, col1 AS col1 FROM tab AS t WHERE ((col1 > col2) AND (col2 > 0))"
130+"SELECT (\"col1\" + \"col2\") AS \"sum\", \"col1\" AS \"col1\" FROM \"tab\" AS \"t\" WHERE ((\"col1\" > \"col2\") AND (\"col2\" > 0))"
131
131
132subquery:
132subquery:
133
133
@@ -142,7 +142,7 @@ let
142 (from (subquery (selectStar (from (table (#tab `As` #t))) `As` #sub)))
142 (from (subquery (selectStar (from (table (#tab `As` #t))) `As` #sub)))
143in renderQuery query
143in renderQuery query
144:}
144:}
145−"SELECT * FROM (SELECT * FROM tab AS t) AS sub"
145+"SELECT * FROM (SELECT * FROM \"tab\" AS \"t\") AS \"sub\""
146
146
147limits and offsets:
147limits and offsets:
148
148
@@ -156,7 +156,7 @@ let
156 (from (table (#tab `As` #t)) & limit 100 & offset 2 & limit 50 & offset 2)
156 (from (table (#tab `As` #t)) & limit 100 & offset 2 & limit 50 & offset 2)
157in renderQuery query
157in renderQuery query
158:}
158:}
159−"SELECT * FROM tab AS t LIMIT 50 OFFSET 4"
159+"SELECT * FROM \"tab\" AS \"t\" LIMIT 50 OFFSET 4"
160
160
161parameterized query:
161parameterized query:
162
162
@@ -170,7 +170,7 @@ let
170 (from (table (#tab `As` #t)) & where_ (#col .> param @1))
170 (from (table (#tab `As` #t)) & where_ (#col .> param @1))
171in renderQuery query
171in renderQuery query
172:}
172:}
173−"SELECT * FROM tab AS t WHERE (col > ($1 :: float8))"
173+"SELECT * FROM \"tab\" AS \"t\" WHERE (\"col\" > ($1 :: float8))"
174
174
175aggregation query:
175aggregation query:
176
176
@@ -190,7 +190,7 @@ let
190 & having (#col1 + sum_ #col2 .> 1) )
190 & having (#col1 + sum_ #col2 .> 1) )
191in renderQuery query
191in renderQuery query
192:}
192:}
193−"SELECT sum(col2) AS sum, col1 AS col1 FROM tab AS table1 GROUP BY col1 HAVING ((col1 + sum(col2)) > 1)"
193+"SELECT sum(\"col2\") AS \"sum\", \"col1\" AS \"col1\" FROM \"tab\" AS \"table1\" GROUP BY \"col1\" HAVING ((\"col1\" + sum(\"col2\")) > 1)"
194
194
195sorted query:
195sorted query:
196
196
@@ -204,7 +204,7 @@ let
204 (from (table (#tab `As` #t)) & orderBy [#col & AscNullsFirst])
204 (from (table (#tab `As` #t)) & orderBy [#col & AscNullsFirst])
205in renderQuery query
205in renderQuery query
206:}
206:}
207−"SELECT * FROM tab AS t ORDER BY col ASC NULLS FIRST"
207+"SELECT * FROM \"tab\" AS \"t\" ORDER BY \"col\" ASC NULLS FIRST"
208
208
209joins:
209joins:
210
210
@@ -248,7 +248,7 @@ let
248 (#o ! #shipper_id .== #s ! #id)) )
248 (#o ! #shipper_id .== #s ! #id)) )
249in renderQuery query
249in renderQuery query
250:}
250:}
251−"SELECT o.price AS order_price, c.name AS customer_name, s.name AS shipper_name FROM orders AS o INNER JOIN customers AS c ON (o.customer_id = c.id) INNER JOIN shippers AS s ON (o.shipper_id = s.id)"
251+"SELECT \"o\".\"price\" AS \"order_price\", \"c\".\"name\" AS \"customer_name\", \"s\".\"name\" AS \"shipper_name\" FROM \"orders\" AS \"o\" INNER JOIN \"customers\" AS \"c\" ON (\"o\".\"customer_id\" = \"c\".\"id\") INNER JOIN \"shippers\" AS \"s\" ON (\"o\".\"shipper_id\" = \"s\".\"id\")"
252
252
253self-join:
253self-join:
254
254
@@ -262,7 +262,7 @@ let
262 (from (table (#tab `As` #t1) & crossJoin (table (#tab `As` #t2))))
262 (from (table (#tab `As` #t1) & crossJoin (table (#tab `As` #t2))))
263in renderQuery query
263in renderQuery query
264:}
264:}
265−"SELECT t1.* FROM tab AS t1 CROSS JOIN tab AS t2"
265+"SELECT \"t1\".* FROM \"tab\" AS \"t1\" CROSS JOIN \"tab\" AS \"t2\""
266
266
267set operations:
267set operations:
268
268
@@ -278,7 +278,7 @@ let
278 selectStar (from (table (#tab `As` #t)))
278 selectStar (from (table (#tab `As` #t)))
279in renderQuery query
279in renderQuery query
280:}
280:}
281−"(SELECT * FROM tab AS t) UNION ALL (SELECT * FROM tab AS t)"
281+"(SELECT * FROM \"tab\" AS \"t\") UNION ALL (SELECT * FROM \"tab\" AS \"t\")"
282-}
282-}
283newtype Query
283newtype Query
284 (schema :: TablesType)
284 (schema :: TablesType)
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+1−1
@@ -384,7 +384,7 @@ deriving instance Ord (expression ty)
384
384
385-- | >>> let renderMaybe = fromString . maybe "Nothing" (const "Just")
385-- | >>> let renderMaybe = fromString . maybe "Nothing" (const "Just")
386-- >>> renderAliasedAs renderMaybe (Just (3::Int) `As` #an_int)
386-- >>> renderAliasedAs renderMaybe (Just (3::Int) `As` #an_int)
387−-- "Just AS an_int"
387+-- "Just AS \"an_int\""
388renderAliasedAs
388renderAliasedAs
389 :: (forall ty. expression ty -> ByteString)
389 :: (forall ty. expression ty -> ByteString)
390 -> Aliased expression aliased
390 -> Aliased expression aliased