@@ -110,7 +110,7 @@ CREATE statements
110110-- renderDefinition $
111111-- createTable #tab (int `As` #a :* real `As` #b :* Nil) Nil
112112-- :}
113−-- "CREATE TABLE tab (a int, b real);"
113+-- "CREATE TABLE \"tab\" (\"a\" int, \"b\" real);"
114114createTable
115115 :: ( KnownSymbol table
116116 , columns ~ (col ': cols)
@@ -136,7 +136,7 @@ createTable table columns constraints = UnsafeDefinition $
136136-- renderDefinition
137137-- (createTableIfNotExists #tab (int `As` #a :* real `As` #b :* Nil) Nil :: Definition Schema Schema)
138138-- :}
139−-- "CREATE TABLE IF NOT EXISTS tab (a int, b real);"
139+-- "CREATE TABLE IF NOT EXISTS \"tab\" (\"a\" int, \"b\" real);"
140140createTableIfNotExists
141141 :: ( Has table schema (constraints :=> columns)
142142 , SOP.SListI columns
@@ -225,7 +225,7 @@ renderColumn (Column column) = renderAlias column
225225-- (int & notNull) `As` #b :* Nil )
226226-- ( check (Column #a :* Column #b :* Nil) (#a .> #b) `As` #inequality :* Nil )
227227-- :}
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\")));"
229229check
230230 :: NP (Column columns) subcolumns
231231 -> Condition '[table ::: ColumnsToRelation subcolumns] 'Ungrouped '[]
@@ -244,7 +244,7 @@ check _cols condition = UnsafeTableConstraintExpression $
244244-- int `As` #b :* Nil )
245245-- ( unique (Column #a :* Column #b :* Nil) `As` #uq_a_b :* Nil )
246246-- :}
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\"));"
248248unique
249249 :: SOP.SListI subcolumns
250250 => NP (Column columns) subcolumns
@@ -264,7 +264,7 @@ unique columns = UnsafeTableConstraintExpression $
264264-- (text & notNull) `As` #name :* Nil )
265265-- ( primaryKey (Column #id :* Nil) `As` #pk_id :* Nil )
266266-- :}
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\"));"
268268primaryKey
269269 :: (SOP.SListI subcolumns, AllNotNull subcolumns)
270270 => NP (Column columns) subcolumns
@@ -313,7 +313,7 @@ primaryKey columns = UnsafeTableConstraintExpression $
313313-- OnDeleteCascade OnUpdateCascade `As` #fk_user_id :* Nil )
314314-- in renderDefinition setup
315315-- :}
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);"
317317foreignKey
318318 :: ForeignKeyed schema table reftable subcolumns refsubcolumns
319319 => NP (Column columns) subcolumns
@@ -390,7 +390,7 @@ DROP statements
390390-- | `dropTable` removes a table from the schema.
391391--
392392-- >>> renderDefinition $ dropTable #muh_table
393−-- "DROP TABLE muh_table;"
393+-- "DROP TABLE \"muh_table\";"
394394dropTable
395395 :: KnownSymbol table
396396 => Alias table -- ^ table to remove
@@ -416,7 +416,7 @@ alterTable table alteration = UnsafeDefinition $
416416-- | `alterTableRename` changes the name of a table from the schema.
417417--
418418-- >>> renderDefinition $ alterTableRename #foo #bar
419−-- "ALTER TABLE foo RENAME TO bar;"
419+-- "ALTER TABLE \"foo\" RENAME TO \"bar\";"
420420alterTableRename
421421 :: (KnownSymbol table0, KnownSymbol table1)
422422 => Alias table0 -- ^ table to rename
@@ -445,7 +445,7 @@ newtype AlterTable
445445-- definition = alterTable #tab (addConstraint #positive (check (Column #col :* Nil) (#col .> 0)))
446446-- in renderDefinition definition
447447-- :}
448−-- "ALTER TABLE tab ADD CONSTRAINT positive CHECK ((col > 0));"
448+-- "ALTER TABLE \"tab\" ADD CONSTRAINT \"positive\" CHECK ((\"col\" > 0));"
449449addConstraint
450450 :: KnownSymbol alias
451451 => Alias alias
@@ -467,7 +467,7 @@ addConstraint alias constraint = UnsafeAlterTable $
467467-- definition = alterTable #tab (dropConstraint #positive)
468468-- in renderDefinition definition
469469-- :}
470−-- "ALTER TABLE tab DROP CONSTRAINT positive;"
470+-- "ALTER TABLE \"tab\" DROP CONSTRAINT \"positive\";"
471471dropConstraint
472472 :: KnownSymbol constraint
473473 => Alias constraint
@@ -493,7 +493,7 @@ class AddColumn ty where
493493 -- definition = alterTable #tab (addColumn #col2 (text & default_ "foo"))
494494 -- in renderDefinition definition
495495 -- :}
496− -- "ALTER TABLE tab ADD COLUMN col2 text DEFAULT E'foo';"
496+ -- "ALTER TABLE \"tab\" ADD COLUMN \"col2\" text DEFAULT E'foo';"
497497 --
498498 -- >>> :{
499499 -- let
@@ -505,7 +505,7 @@ class AddColumn ty where
505505 -- definition = alterTable #tab (addColumn #col2 text)
506506 -- in renderDefinition definition
507507 -- :}
508− -- "ALTER TABLE tab ADD COLUMN col2 text;"
508+ -- "ALTER TABLE \"tab\" ADD COLUMN \"col2\" text;"
509509 addColumn
510510 :: KnownSymbol column
511511 => Alias column -- ^ column to add
@@ -532,7 +532,7 @@ instance {-# OVERLAPPABLE #-} AddColumn ('NoDef :=> 'Null ty)
532532-- definition = alterTable #tab (dropColumn #col2)
533533-- in renderDefinition definition
534534-- :}
535−-- "ALTER TABLE tab DROP COLUMN col2;"
535+-- "ALTER TABLE \"tab\" DROP COLUMN \"col2\";"
536536dropColumn
537537 :: KnownSymbol column
538538 => Alias column -- ^ column to remove
@@ -552,7 +552,7 @@ dropColumn column = UnsafeAlterTable $
552552-- definition = alterTable #tab (renameColumn #foo #bar)
553553-- in renderDefinition definition
554554-- :}
555−-- "ALTER TABLE tab RENAME COLUMN foo TO bar;"
555+-- "ALTER TABLE \"tab\" RENAME COLUMN \"foo\" TO \"bar\";"
556556renameColumn
557557 :: (KnownSymbol column0, KnownSymbol column1)
558558 => Alias column0 -- ^ column to rename
@@ -589,7 +589,7 @@ newtype AlterColumn (ty0 :: ColumnType) (ty1 :: ColumnType) =
589589-- definition = alterTable #tab (alterColumn #col (setDefault 5))
590590-- in renderDefinition definition
591591-- :}
592−-- "ALTER TABLE tab ALTER COLUMN col SET DEFAULT 5;"
592+-- "ALTER TABLE \"tab\" ALTER COLUMN \"col\" SET DEFAULT 5;"
593593setDefault
594594 :: Expression '[] 'Ungrouped '[] ty -- ^ default value to set
595595 -> AlterColumn (constraint :=> ty) ('Def :=> ty)
@@ -606,7 +606,7 @@ setDefault expression = UnsafeAlterColumn $
606606-- definition = alterTable #tab (alterColumn #col dropDefault)
607607-- in renderDefinition definition
608608-- :}
609−-- "ALTER TABLE tab ALTER COLUMN col DROP DEFAULT;"
609+-- "ALTER TABLE \"tab\" ALTER COLUMN \"col\" DROP DEFAULT;"
610610dropDefault :: AlterColumn ('Def :=> ty) ('NoDef :=> ty)
611611dropDefault = UnsafeAlterColumn $ "DROP DEFAULT"
612612
@@ -622,7 +622,7 @@ dropDefault = UnsafeAlterColumn $ "DROP DEFAULT"
622622-- definition = alterTable #tab (alterColumn #col setNotNull)
623623-- in renderDefinition definition
624624-- :}
625−-- "ALTER TABLE tab ALTER COLUMN col SET NOT NULL;"
625+-- "ALTER TABLE \"tab\" ALTER COLUMN \"col\" SET NOT NULL;"
626626setNotNull
627627 :: AlterColumn (constraint :=> 'Null ty) (constraint :=> 'NotNull ty)
628628setNotNull = UnsafeAlterColumn $ "SET NOT NULL"
@@ -637,7 +637,7 @@ setNotNull = UnsafeAlterColumn $ "SET NOT NULL"
637637-- definition = alterTable #tab (alterColumn #col dropNotNull)
638638-- in renderDefinition definition
639639-- :}
640−-- "ALTER TABLE tab ALTER COLUMN col DROP NOT NULL;"
640+-- "ALTER TABLE \"tab\" ALTER COLUMN \"col\" DROP NOT NULL;"
641641dropNotNull
642642 :: AlterColumn (constraint :=> 'NotNull ty) (constraint :=> 'Null ty)
643643dropNotNull = UnsafeAlterColumn $ "DROP NOT NULL"
@@ -655,6 +655,6 @@ dropNotNull = UnsafeAlterColumn $ "DROP NOT NULL"
655655-- alterTable #tab (alterColumn #col (alterType (numeric & notNull)))
656656-- in renderDefinition definition
657657-- :}
658−-- "ALTER TABLE tab ALTER COLUMN col TYPE numeric NOT NULL;"
658+-- "ALTER TABLE \"tab\" ALTER COLUMN \"col\" TYPE numeric NOT NULL;"
659659alterType :: TypeExpression ty -> AlterColumn ty0 ty
660660alterType ty = UnsafeAlterColumn $ "TYPE" <+> renderTypeExpression ty