!̜      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~                                                                                 ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~                                                Rendering helper functions(c) Eitan Chatav, 2017eitan@morphism.tech experimentalNone ,<DFQVi= squeal-postgresqlA class for rendering SQLsqueal-postgresqlParenthesize a .squeal-postgresqlConcatenate two s with a space between.squeal-postgresqlComma separate a list of s.squeal-postgresqlAdd double quotes around a .squeal-postgresqlAdd single quotes around a $ and escape single quotes within it.squeal-postgresqlAdd single quotes around a $ and escape single quotes within it.squeal-postgresql6Comma separate the renderings of a heterogeneous list. squeal-postgresqlComma separate the / renderings of a heterogeneous list, dropping s.!squeal-postgresqlRender a promoted ."squeal-postgresqlRender a promoted .#squeal-postgresql Print SQL.  !"#  !"#7-Embedding of PostgreSQL type and alias system(c) Eitan Chatav, 2017eitan@morphism.tech experimentalNone&'+,-068;<=>?AFQSTV]il$squeal-postgresqlAn $) is a type-aligned list or free category.'squeal-postgresqlIs a type a valid JSON type?(squeal-postgresqlIs a type a valid JSON key?squeal-postgresql,Calculate the names of nullary constructors.squeal-postgresqlPCalculates the name of a nullary constructor, otherwise generates a type error.squeal-postgresql&Calculates constructors of a datatype.)squeal-postgresql)T turns a Haskell tuple type (including record types) into the corresponding list of {s.#:kind! TuplePG (Double, Maybe Char)-TuplePG (Double, Maybe Char) :: [NullityType]*= '['NotNull 'PGfloat8, 'Null ('PGchar 1)]*squeal-postgresql* turns a Haskell type into a {.:kind! NullPG DoubleNullPG Double :: NullityType= 'NotNull 'PGfloat8:kind! NullPG (Maybe Double)$NullPG (Maybe Double) :: NullityType= 'Null 'PGfloat8+squeal-postgresql+$ turns a Haskell record type into a k.Hdata Person = Person { name :: Text, age :: Int32 } deriving GHC.Genericinstance Generic Personinstance HasDatatypeInfo Person:kind! RowPG Person'RowPG Person :: [(Symbol, NullityType)]<= '["name" ::: 'NotNull 'PGtext, "age" ::: 'NotNull 'PGint4],squeal-postgresqlThe ,@ type family calculates the constructors of a Haskell enum type.:data Schwarma = Beef | Lamb | Chicken deriving GHC.Genericinstance Generic Schwarma!instance HasDatatypeInfo Schwarma:kind! LabelsPG Schwarma+LabelsPG Schwarma :: [Type.ConstructorName]= '["Beef", "Lamb", "Chicken"]-squeal-postgresqlThe -T newtype is an indication that the Haskell type it's applied to should be stored as .0squeal-postgresqlThe 0V newtype is an indication that the Haskell type it's applied to should be stored as a .3squeal-postgresqlThe 3T newtype is an indication that the Haskell type it's applied to should be stored as .6squeal-postgresqlThe 6T newtype is an indication that the Haskell type it's applied to should be stored as .9squeal-postgresqlThe 9Y type family embeds a subset of Haskell types as Postgres types. As an open type family, 9 is extensible.:kind! PG LocalTimePG LocalTime :: PGType= 'PGtimestampnewtype MyDouble = My Double%type instance PG MyDouble = 'PGfloat8:squeal-postgresqlA : unit type with an < instance<squeal-postgresql< looks very much like the ' class. Whereas the overloaded label, ! is used for column references, =s are used for enum terms. A =7 is called with type application like `label @"beef"`.>squeal-postgresqlEThe schema of a database consists of a list of aliased, user-defined ?s.:{&type family Schema :: SchemaType where Schema = '[ "users" ::: 'Table (3 '[ "pk_users" ::: 'PrimaryKey '["id"] ] :=>1 '[ "id" ::: 'Def :=> 'NotNull 'PGint40 , "name" ::: 'NoDef :=> 'NotNull 'PGtext ]) , "emails" ::: 'Table (/ '[ "pk_emails" ::: 'PrimaryKey '["id"]C , "fk_user_id" ::: 'ForeignKey '["user_id"] "users" '["id"] ] :=>4 '[ "id" ::: 'Def :=> 'NotNull 'PGint43 , "user_id" ::: 'NoDef :=> 'NotNull 'PGint43 , "email" ::: 'NoDef :=> 'Null 'PGtext ]) ]:}?squeal-postgresqlA ?" is a user-defined type, either a @, A or B.Csqueal-postgresqlCalculate the C of a type level list(:kind! Length '[Char,String,Bool,Double](Length '[Char,String,Bool,Double] :: Nat= 4Dsqueal-postgresql Drop all os that involve a columnsqueal-postgresql Check if a o involves a columnEsqueal-postgresqlRename alias0 alias1 xs replaces the alias alias0 by alias1 in xs and is used in   and  .Fsqueal-postgresqlAlter alias x xs& replaces the type associated with an alias in xs with the type x and is used in  and .Gsqueal-postgresql Drop alias xs" removes the type associated with alias in xs and is used in  statements and in  ALTER TABLE  statements.Hsqueal-postgresqlCreate alias x xs adds  alias ::: x to the end of xs and is used in  statements and in  ALTER TABLE .Isqueal-postgresqlI is simply promoted  and is used in JOINs in s.Jsqueal-postgresqlJ# is an idempotent that nullifies a jE used to nullify the left or right hand side of an outer join in a .Ksqueal-postgresqlK# is an idempotent that nullifies a k.Lsqueal-postgresqlL# is an idempotent that nullifies a {.Msqueal-postgresqlM is a constraint that proves a t has some NOT NULL.Nsqueal-postgresqlN is a constraint that proves a t has no NULLs.Osqueal-postgresql&Equality constraint on the underlying  of two columns.Psqueal-postgresqlP forgets about NULL and any column constraints.Qsqueal-postgresql<Ensure a type is a valid array type whose elements are text.Rsqueal-postgresqlAEnsure a type is a valid array type with a specific element type.Ssqueal-postgresql$Ensure a type is a valid array type.squeal-postgresqlhError message helper for displaying unavailable/unknown/placeholder type variables whose kind is known.Tsqueal-postgresqlIntegral Postgres types.Usqueal-postgresqlFloating Postgres types.Vsqueal-postgresqlNumeric Postgres types.Wsqueal-postgresqlIn x xs" is a constraint that proves that x is in xs.Xsqueal-postgresqlElem is a promoted .Ysqueal-postgresql Analagous to , the constraint Y defines Z0 for a column alias qualified by a table alias.[squeal-postgresql[ extends \ to take lists of aliases and fields and infer a list of  subfields.\squeal-postgresqlHas alias fields field# is a constraint that proves that fields has a field of alias ::: field , inferring field from alias and fields.]squeal-postgresqlHasUnique alias fields field# is a constraint that proves that fields is a singleton of alias ::: field.^squeal-postgresqlThe ^$ class provides a way to scrap your  s in an  list of ` expressions.`squeal-postgresqlThe a) operator is used to name an expression. a is like a demoted version of y.8Just "hello" `As` #hi :: Aliased Maybe ("hi" ::: String)As (Just "hello") Aliasbsqueal-postgresqlb*es are proxies for a type level string or  and have an  instance so that with -XOverloadedLabels:set -XOverloadedLabels#foobar :: Alias "foobar"Aliasdsqueal-postgresqlA df constraint indicates that a table qualified column is a member of the auxiliary namespace created by GROUP BY. clauses and thus, may be called in an output  without aggregating.esqueal-postgresqle( is an auxiliary namespace, created by GROUP BY clauses (%), and used for typesafe aggregationfsqueal-postgresqlno aggregation permittedgsqueal-postgresql8aggregation required for any column which is not groupedhsqueal-postgresqlConvert a table to a row type.isqueal-postgresqli removes table constraints.squeal-postgresql removes column constraints.jsqueal-postgresqlj is a row of kJs. It can be thought of as a product, or horizontal gluing and is used in s and s.ksqueal-postgresqlA k is a row of {6. They correspond to Haskell record types by means of + and are used in many places.:{&type family PersonRow :: RowType where PersonRow =) '[ "name" ::: 'NotNull 'PGtext) , "age" ::: 'NotNull 'PGint4) , "dateOfBirth" ::: 'Null 'PGdate ]:}lsqueal-postgresqllN encodes a row of constraints on a table as well as the types of its columns.:{)type family UsersTable :: TableType where UsersTable =/ '[ "pk_users" ::: 'PrimaryKey '["id"] ] :=>1 '[ "id" ::: 'Def :=> 'NotNull 'PGint41 , "name" ::: 'NoDef :=> 'NotNull 'PGtext ]:}msqueal-postgresqlA s+ must reference columns that either are a r or form a q constraint.nsqueal-postgresqlA n is a row of os.osqueal-postgresqloD encodes various forms of data constraints of columns in a table. os give you as much control over the data in your tables as you wish. If a user attempts to store data in a column that would violate a constraint, an error is raised. This applies even if the value came from the default value definition.tsqueal-postgresqlt is a row of us.:{-type family UsersColumns :: ColumnsType where UsersColumns =- '[ "name" ::: 'NoDef :=> 'NotNull 'PGtext- , "id" ::: 'Def :=> 'NotNull 'PGint4 ]:}usqueal-postgresqlu encodes the allowance of DEFAULT and NULL and the base  for a column. :set -XTypeFamilies -XTypeInTypeimport GHC.TypeLitsMtype family IdColumn :: ColumnType where IdColumn = 'Def :=> 'NotNull 'PGint4Rtype family EmailColumn :: ColumnType where EmailColumn = 'NoDef :=> 'Null 'PGtextvsqueal-postgresqlv encodes the availability of DEFAULTM for inserts and updates. A column can be assigned a default value. A data | command can also request explicitly that a column be set to its default value, without having to know what that value is.wsqueal-postgresqlDEFAULT% is available for inserts and updatesxsqueal-postgresqlDEFAULT' is unavailable for inserts and updatesysqueal-postgresqlThe alias operator y is like a promoted version of a4, a type level pair between an alias and some type.zsqueal-postgresqlThe constraint operator, zS is a type level pair between a "constraint" and some type, for use in pairing a v with a { to produce a u or a n and a t to produce a l.{squeal-postgresql{: encodes the potential presence or definite absence of a NULLB allowing operations which are sensitive to such to be well typed.:kind 'Null 'PGint4'Null 'PGint4 :: NullityType:kind 'NotNull ('PGvarchar 50)''NotNull ('PGvarchar 50) :: NullityType|squeal-postgresqlNULL may be present}squeal-postgresqlNULL is absent~squeal-postgresqlThe object identifier of a .:set -XTypeApplications oid @'PGbool16squeal-postgresql. is the promoted datakind of PostgreSQL types.import Squeal.PostgreSQL.Schema :kind 'PGbool'PGbool :: PGTypesqueal-postgresqllogical Boolean (true/false)squeal-postgresqlsigned two-byte integersqueal-postgresqlsigned four-byte integersqueal-postgresqlsigned eight-byte integersqueal-postgresql arbitrary precision numeric typesqueal-postgresql0single precision floating-point number (4 bytes)squeal-postgresql0double precision floating-point number (8 bytes)squeal-postgresqlfixed-length character stringsqueal-postgresql variable-length character stringsqueal-postgresql variable-length character stringsqueal-postgresqlbinary data ("byte array")squeal-postgresqldate and time (no time zone)squeal-postgresql"date and time, including time zonesqueal-postgresql calendar date (year, month, day)squeal-postgresqltime of day (no time zone)squeal-postgresql time of day, including time zonesqueal-postgresql time spansqueal-postgresqluniversally unique identifiersqueal-postgresqlIPv4 or IPv6 host addresssqueal-postgresqltextual JSON datasqueal-postgresqlbinary JSON data, decomposedsqueal-postgresqlvariable length arraysqueal-postgresqlfixed length arraysqueal-postgresqlUenumerated (enum) types are data types that comprise a static, ordered set of values.squeal-postgresqla composite type represents the structure of a row or record; it is essentially just a list of field names and their data types.squeal-postgresql0an escape hatch for unsupported PostgreSQL typessqueal-postgresqlrenderAlias #jimbob "\"jimbob\""squeal-postgresqlrenderAliasString #ohmahgerd "'ohmahgerd'"squeal-postgresqlimport Generics.SOP (NP(..))!renderAliases (#jimbob :* #kandi)["\"jimbob\"","\"kandi\""]squeal-postgresql=let renderMaybe = fromString . maybe "Nothing" (const "Just")8renderAliasedAs renderMaybe (Just (3::Int) `As` #an_int)"Just AS \"an_int\""squeal-postgresqlRenders a labelsqueal-postgresqlRenders a list of labelssqueal-postgresqlA  step.$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnoqprstuvwxyz{|}~{|}kj9*)+678345012-./utl?@AB>zvwxoqprsnmybc`a^_\][YZ<=:;,efgd$%&HGFEDIXWC~VTUPRSQ'(ONMLKJih&7Z9 y6z7Squeal expressions(c) Eitan Chatav, 2017eitan@morphism.tech experimentalNone+,-6;<=>?ADFKQSTV]iAĕsqueal-postgresql is a demoted version of a squeal-postgresqls are used in s and  createTable commands.squeal-postgresqlA constraint for 3s that you can take averages of and the resulting .squeal-postgresqlA  is an , which can evaluate to  ,   or 1. This is because SQL uses a three valued logic.squeal-postgresqlA X constraint is used to indicate a value that is supplied externally to a SQL statement. ,  and V support specifying data values separately from the SQL command string, in which case 3s are used to refer to the out-of-line data values.squeal-postgresql takes a  using type application and a .Ylet expr = parameter @1 int4 :: Expression sch rels grp '[ 'Null 'PGint4] ('Null 'PGint4) printSQL expr ($1 :: int4)squeal-postgresqlGs are used in a variety of contexts, such as in the target list of the " command, as new column values in   or !, or in search s in a number of commands.The expression syntax allows the calculation of values from primitive expression using arithmetic, logical, and other operations.squeal-postgresql takes a 7 using type application and for basic types, infers a .Plet expr = param @1 :: Expression sch rels grp '[ 'Null 'PGint4] ('Null 'PGint4) printSQL expr ($1 :: int4)squeal-postgresql analagous to printSQL null_NULLsqueal-postgresql analagous to printSQL $ notNull trueTRUEsqueal-postgresql+return the leftmost value which is not NULL'printSQL $ coalesce [null_, true] falseCOALESCE(NULL, TRUE, FALSE)squeal-postgresql analagous to "# using COALESCEprintSQL $ fromNull true null_COALESCE(NULL, TRUE)squeal-postgresqlprintSQL $ null_ & isNull NULL IS NULLsqueal-postgresqlprintSQL $ null_ & isNotNullNULL IS NOT NULLsqueal-postgresql analagous to  using IS NULL$printSQL $ matchNull true not_ null_4CASE WHEN NULL IS NULL THEN TRUE ELSE (NOT NULL) ENDsqueal-postgresqlright inverse to ", if its arguments are equal then  gives NULL.#:set -XTypeApplications -XDataKindselet expr = nullIf false (param @1) :: Expression schema rels grp '[ 'NotNull 'PGbool] ('Null 'PGbool) printSQL exprNULL IF (FALSE, ($1 :: bool))squeal-postgresql%printSQL $ array [null_, false, true]ARRAY[NULL, FALSE, TRUE]squeal-postgresql/printSQL $ array [null_, false, true] & index 2(ARRAY[NULL, FALSE, TRUE])[2]squeal-postgresqlA row constructor is an expression that builds a row value (also called a composite value) using values for its member fields.:{type Complex = 'PGcomposite' '[ "real" ::: 'NotNull 'PGfloat8) , "imaginary" ::: 'NotNull 'PGfloat8 ]:}glet i = row (0 `as` #real :* 1 `as` #imaginary) :: Expression '[] '[] 'Ungrouped '[] ('NotNull Complex) printSQL i ROW(0, 1)squeal-postgresql:{type Complex = 'PGcomposite' '[ "real" ::: 'NotNull 'PGfloat8) , "imaginary" ::: 'NotNull 'PGfloat8 ]:}let i = row (0 `as` #real :* 1 `as` #imaginary) :: Expression '["complex" ::: 'Typedef Complex] '[] 'Ungrouped '[] ('NotNull Complex)(printSQL $ i & field #complex #imaginary"(ROW(0, 1)::"complex")."imaginary"squeal-postgresqllet expr = greatest currentTimestamp [param @1] :: Expression sch rels grp '[ 'NotNull 'PGtimestamptz] ('NotNull 'PGtimestamptz) printSQL expr=GREATEST(CURRENT_TIMESTAMP, ($1 :: timestamp with time zone))squeal-postgresql)printSQL $ least currentTimestamp [null_]LEAST(CURRENT_TIMESTAMP, NULL)squeal-postgresql)printSQL $ unsafeBinaryOp "OR" true false(TRUE OR FALSE)squeal-postgresql#printSQL $ unsafeUnaryOp "NOT" true (NOT TRUE)squeal-postgresql"printSQL $ unsafeFunction "f" truef(TRUE)squeal-postgresql'Helper for defining variadic functions.squeal-postgresql:{letJ expression :: Expression schema from grouping params (nullity 'PGfloat4) expression = atan2_ pi 2in printSQL expression:}atan2(pi(), 2)squeal-postgresqlprintSQL $ true & cast int4(TRUE :: int4)squeal-postgresql&integer division, truncates the result:{letH expression :: Expression schema from grouping params (nullity 'PGint2) expression = 5 `quot_` 2in printSQL expression:}(5 / 2)squeal-postgresqlremainder upon integer division:{letH expression :: Expression schema from grouping params (nullity 'PGint2) expression = 5 `rem_` 2in printSQL expression:}(5 % 2) squeal-postgresql:{letJ expression :: Expression schema from grouping params (nullity 'PGfloat4) expression = trunc piin printSQL expression:} trunc(pi()) squeal-postgresql:{letJ expression :: Expression schema from grouping params (nullity 'PGfloat4) expression = round_ piin printSQL expression:} round(pi()) squeal-postgresql:{letJ expression :: Expression schema from grouping params (nullity 'PGfloat4) expression = ceiling_ piin printSQL expression:} ceiling(pi()) squeal-postgresql printSQL trueTRUE squeal-postgresqlprintSQL falseFALSEsqueal-postgresqlprintSQL $ not_ true (NOT TRUE)squeal-postgresqlprintSQL $ true .&& false(TRUE AND FALSE)squeal-postgresqlprintSQL $ true .|| false(TRUE OR FALSE)squeal-postgresql:{letH expression :: Expression schema from grouping params (nullity 'PGint2)9 expression = caseWhenThenElse [(true, 1), (false, 2)] 3in printSQL expression:}2CASE WHEN TRUE THEN 1 WHEN FALSE THEN 2 ELSE 3 ENDsqueal-postgresql:{letH expression :: Expression schema from grouping params (nullity 'PGint2)" expression = ifThenElse true 1 0in printSQL expression:} CASE WHEN TRUE THEN 1 ELSE 0 ENDsqueal-postgresqlComparison operations like , , , ,  and  will produce NULLs if one of their arguments is NULL.printSQL $ true .== null_ (TRUE = NULL)squeal-postgresqlprintSQL $ true ./= null_(TRUE <> NULL)squeal-postgresqlprintSQL $ true .>= null_(TRUE >= NULL)squeal-postgresqlprintSQL $ true .< null_ (TRUE < NULL)squeal-postgresqlprintSQL $ true .<= null_(TRUE <= NULL)squeal-postgresqlprintSQL $ true .> null_ (TRUE > NULL)squeal-postgresqlprintSQL currentDate CURRENT_DATEsqueal-postgresqlprintSQL currentTime CURRENT_TIMEsqueal-postgresqlprintSQL currentTimestampCURRENT_TIMESTAMPsqueal-postgresqlprintSQL localTime LOCALTIMEsqueal-postgresqlprintSQL localTimestampLOCALTIMESTAMPsqueal-postgresqlprintSQL $ lower "ARRRGGG"lower(E'ARRRGGG')squeal-postgresqlprintSQL $ upper "eeee"upper(E'eeee') squeal-postgresqlprintSQL $ charLength "four"char_length(E'four')!squeal-postgresqlThe ! expression returns true if the string matches the supplied pattern. If patterns does not contain percent signs or underscores, then the pattern only represents the string itself; in that case ! acts like the equals operator. An underscore (_) in pattern stands for (matches) any single character; a percent sign (%) matches any sequence of zero or more characters.printSQL $ "abc" `like` "a%"(E'abc' LIKE E'a%')"squeal-postgresql8Get JSON value (object field or array element) at a key.#squeal-postgresqlAGet JSON value (object field or array element) at a key, as text.$squeal-postgresql#Get JSON value at a specified path.%squeal-postgresql+Get JSON value at a specified path as text.&squeal-postgresqlUDoes the left JSON value contain the right JSON path/value entries at the top level?'squeal-postgresql]Are the left JSON path/value entries contained at the top level within the right JSON value?(squeal-postgresql?Does the string exist as a top-level key within the JSON value?)squeal-postgresql6Do any of these array strings exist as top-level keys?*squeal-postgresql6Do all of these array strings exist as top-level keys?+squeal-postgresqlDDelete a key or keys from a JSON object, or remove an array element.If the right operand is.. text  : Delete key3value pair or string element from left operand. Key2value pairs are matched based on their key value. text[] ~: Delete multiple key/value pairs or string elements from left operand. Key/value pairs are matched based on their key value. integer : Delete the array element with specified index (Negative integers count from the end). Throws an error if top level container is not an array.,squeal-postgresqlhDelete the field or element with specified path (for JSON arrays, negative integers count from the end)-squeal-postgresqlLiteral binary JSON.squeal-postgresql Literal JSON/squeal-postgresqlReturns the value as json. Arrays and composites are converted (recursively) to arrays and objects; otherwise, if there is a cast from the type to json, the cast function will be used to perform the conversion; otherwise, a scalar value is produced. For any scalar type other than a number, a Boolean, or a null value, the text representation will be used, in such a fashion that it is a valid json value.0squeal-postgresqlReturns the value as jsonb. Arrays and composites are converted (recursively) to arrays and objects; otherwise, if there is a cast from the type to json, the cast function will be used to perform the conversion; otherwise, a scalar value is produced. For any scalar type other than a number, a Boolean, or a null value, the text representation will be used, in such a fashion that it is a valid jsonb value.1squeal-postgresqlgReturns the array as a JSON array. A PostgreSQL multidimensional array becomes a JSON array of arrays.2squeal-postgresql!Returns the row as a JSON object.3squeal-postgresqlTBuilds a possibly-heterogeneously-typed JSON array out of a variadic argument list.4squeal-postgresql]Builds a possibly-heterogeneously-typed (binary) JSON array out of a variadic argument list.5squeal-postgresqlBuilds a possibly-heterogeneously-typed JSON object out of a variadic argument list. The elements of the argument list must alternate between text and values.6squeal-postgresqlBuilds a possibly-heterogeneously-typed (binary) JSON object out of a variadic argument list. The elements of the argument list must alternate between text and values.7squeal-postgresql&Builds a JSON object out of a text array. The array must have either exactly one dimension with an even number of members, in which case they are taken as alternating key/value pairs, or two dimensions such that each inner array has exactly two elements, which are taken as a key/value pair.8squeal-postgresql-Builds a binary JSON object out of a text array. The array must have either exactly one dimension with an even number of members, in which case they are taken as alternating key/value pairs, or two dimensions such that each inner array has exactly two elements, which are taken as a key/value pair.9squeal-postgresqlThis is an alternate form of 7k that takes two arrays; one for keys and one for values, that are zipped pairwise to create a JSON object.:squeal-postgresqlThis is an alternate form of 7s that takes two arrays; one for keys and one for values, that are zipped pairwise to create a binary JSON object.;squeal-postgresql;Returns the number of elements in the outermost JSON array.<squeal-postgresqlBReturns the number of elements in the outermost binary JSON array.=squeal-postgresqlMReturns JSON value pointed to by the given path (equivalent to #> operator).>squeal-postgresqlMReturns JSON value pointed to by the given path (equivalent to #> operator).?squeal-postgresqlVReturns JSON value pointed to by the given path (equivalent to #> operator), as text.@squeal-postgresqlVReturns JSON value pointed to by the given path (equivalent to #> operator), as text.Asqueal-postgresqlReturns the type of the outermost JSON value as a text string. Possible types are object, array, string, number, boolean, and null.Bsqueal-postgresqlReturns the type of the outermost binary JSON value as a text string. Possible types are object, array, string, number, boolean, and null.Csqueal-postgresqllReturns its argument with all object fields that have null values omitted. Other null values are untouched.Dsqueal-postgresqllReturns its argument with all object fields that have null values omitted. Other null values are untouched.Esqueal-postgresql . jsonbSet target path new_value create_missing2Returns target with the section designated by path replaced by new_value, or with new_value added if create_missing is true ( default is true) and the item designated by path does not exist. As with the path orientated operators, negative integers that appear in path count from the end of JSON arrays.Fsqueal-postgresql / jsonbInsert target path new_value insert_afterReturns target with new_value inserted. If target section designated by path is in a JSONB array, new_value will be inserted before target or after if insert_after is true (default is false). If target section designated by path is in JSONB object, new_value will be inserted only if target does not exist. As with the path orientated operators, negative integers that appear in path count from the end of JSON arrays.Gsqueal-postgresql+Returns its argument as indented JSON text.Hsqueal-postgresql*escape hatch to define aggregate functionsIsqueal-postgresql?escape hatch to define aggregate functions over distinct valuesJsqueal-postgresql:{lets expression :: Expression schema '[tab ::: '["col" ::: 'Null 'PGnumeric]] ('Grouped bys) params ('Null 'PGnumeric) expression = sum_ #colin printSQL expression:} sum("col")Ksqueal-postgresql:{letw expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGnumeric]] ('Grouped bys) params (nullity 'PGnumeric) expression = sumDistinct #colin printSQL expression:}sum(DISTINCT "col")Lsqueal-postgresql:{letp expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4) expression = bitAnd #colin printSQL expression:}bit_and("col")Msqueal-postgresql:{letp expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4) expression = bitOr #colin printSQL expression:} bit_or("col")Nsqueal-postgresql:{letp expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)" expression = bitAndDistinct #colin printSQL expression:}bit_and(DISTINCT "col")Osqueal-postgresql:{letp expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)! expression = bitOrDistinct #colin printSQL expression:}bit_or(DISTINCT "col")Psqueal-postgresql:{letp expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool) expression = boolAnd #colin printSQL expression:}bool_and("col")Qsqueal-postgresql:{letp expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool) expression = boolOr #colin printSQL expression:}bool_or("col")Rsqueal-postgresql:{letp expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)# expression = boolAndDistinct #colin printSQL expression:}bool_and(DISTINCT "col")Ssqueal-postgresql:{letp expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)" expression = boolOrDistinct #colin printSQL expression:}bool_or(DISTINCT "col")Tsqueal-postgresql4A special aggregation that does not require an inputprintSQL countStarcount(*)Usqueal-postgresql:{letl expression :: Expression schema '[tab ::: '["col" ::: nullity ty]] (Grouped bys) params ('NotNull 'PGint8) expression = count #colin printSQL expression:} count("col")Vsqueal-postgresql:{letl expression :: Expression schema '[tab ::: '["col" ::: nullity ty]] (Grouped bys) params ('NotNull 'PGint8)! expression = countDistinct #colin printSQL expression:}count(DISTINCT "col")Wsqueal-postgresql synonym for P:{letp expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool) expression = every #colin printSQL expression:} every("col")Xsqueal-postgresql synonym for R:{letp expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)! expression = everyDistinct #colin printSQL expression:}every(DISTINCT "col")Ysqueal-postgresqlminimum and maximum aggregationZsqueal-postgresqlminimum and maximum aggregation[squeal-postgresqlminimum and maximum aggregation\squeal-postgresqlminimum and maximum aggregation]squeal-postgresql The enum or composite type in a B can be expressed by its alias.^squeal-postgresql&The composite type corresponding to a @+ definition can be expressed by its alias._squeal-postgresql&The composite type corresponding to a A+ definition can be expressed by its alias.`squeal-postgresqllogical Boolean (true/false)asqueal-postgresqlsigned two-byte integerbsqueal-postgresqlsigned two-byte integercsqueal-postgresqlsigned four-byte integerdsqueal-postgresqlsigned four-byte integeresqueal-postgresqlsigned four-byte integerfsqueal-postgresqlsigned eight-byte integergsqueal-postgresqlsigned eight-byte integerhsqueal-postgresql arbitrary precision numeric typeisqueal-postgresql0single precision floating-point number (4 bytes)jsqueal-postgresql0single precision floating-point number (4 bytes)ksqueal-postgresql0double precision floating-point number (8 bytes)lsqueal-postgresql0double precision floating-point number (8 bytes)msqueal-postgresql variable-length character stringnsqueal-postgresqlfixed-length character stringosqueal-postgresqlfixed-length character stringpsqueal-postgresql variable-length character stringqsqueal-postgresql variable-length character stringrsqueal-postgresqlbinary data ("byte array")ssqueal-postgresqldate and time (no time zone)tsqueal-postgresql"date and time, including time zoneusqueal-postgresql calendar date (year, month, day)vsqueal-postgresqltime of day (no time zone)wsqueal-postgresql time of day, including time zonexsqueal-postgresql time spanysqueal-postgresqluniversally unique identifierzsqueal-postgresqlIPv4 or IPv6 host address{squeal-postgresqltextual JSON data|squeal-postgresqlbinary JSON data, decomposed}squeal-postgresqlvariable length array~squeal-postgresqlfixed length array'renderTypeExpression (fixarray @2 json) "json[2]"squeal-postgresql4Concatenate two jsonb values into a new jsonb value.:squeal-postgresqlwhat to averagesqueal-postgresqlwhat to averagesqueal-postgresqlparamsqueal-postgresqlNULLs may be presentsqueal-postgresqlNULL is absentsqueal-postgresqlwhat to convert NULL tosqueal-postgresql possibly NULLsqueal-postgresql possibly NULLsqueal-postgresqlwhat to convert NULL tosqueal-postgresqlfunction to perform when NULL is absentsqueal-postgresqlNULL is absentsqueal-postgresqlNULL is absentsqueal-postgresqlarray elementssqueal-postgresqlindexsqueal-postgresqlarraysqueal-postgresql1zero or more expressions for the row field valuessqueal-postgresqlrow typesqueal-postgresql field namesqueal-postgresqlneeds at least 1 argumentsqueal-postgresqlor moresqueal-postgresqlneeds at least 1 argumentsqueal-postgresqlor moresqueal-postgresqloperatorsqueal-postgresqloperatorsqueal-postgresqlfunctionsqueal-postgresqlfunctionsqueal-postgresql numeratorsqueal-postgresql denominatorsqueal-postgresqltype to cast assqueal-postgresqlvalue to convertsqueal-postgresql numeratorsqueal-postgresql denominatorsqueal-postgresql numeratorsqueal-postgresql denominator squeal-postgresqlfractional number squeal-postgresqlfractional number squeal-postgresqlfractional numbersqueal-postgresqlwhens and thenssqueal-postgresqlelsesqueal-postgresqlthensqueal-postgresqlelsesqueal-postgresqllhssqueal-postgresqlrhssqueal-postgresqllhssqueal-postgresqlrhssqueal-postgresqllhssqueal-postgresqlrhssqueal-postgresqllhssqueal-postgresqlrhssqueal-postgresqllhssqueal-postgresqlrhssqueal-postgresqllhssqueal-postgresqlrhssqueal-postgresqlstring to lower casesqueal-postgresqlstring to upper case squeal-postgresqlstring to measure!squeal-postgresqlstringsqueal-postgresqlpatternHsqueal-postgresqlaggregate functionIsqueal-postgresqlaggregate functionJsqueal-postgresql what to sumKsqueal-postgresql what to sumLsqueal-postgresqlwhat to aggregateMsqueal-postgresqlwhat to aggregateNsqueal-postgresqlwhat to aggregateOsqueal-postgresqlwhat to aggregatePsqueal-postgresqlwhat to aggregateQsqueal-postgresqlwhat to aggregateRsqueal-postgresqlwhat to aggregateSsqueal-postgresqlwhat to aggregateUsqueal-postgresql what to countVsqueal-postgresql what to countWsqueal-postgresqlwhat to aggregateXsqueal-postgresqlwhat to aggregateYsqueal-postgresqlwhat to aggregateZsqueal-postgresqlwhat to aggregate[squeal-postgresqlwhat to aggregate\squeal-postgresqlwhat to aggregate      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~      !"#$%&'()*+,.-/0123456789:;<=>?@ABCDEFGHIJKLMPQNORSTUVWXY[Z\]^_`abcdefghijklmnopqrstuvwxyz{|}~32444444"8#8$8%8&9 '9 (9 )9 *9 +6,6Squeal queries(c) Eitan Chatav, 2017eitan@morphism.tech experimentalNone&'+,-06;<=>?FKQSTV]\squeal-postgresqlk provides a way to write auxiliary statements for use in a larger query. These statements, referred to as Qs, can be thought of as defining temporary tables that exist just for one query.squeal-postgresqlA  is an auxiliary statement in a  clause.squeal-postgresqls are used by sortBy& to optionally sort the results of a .  or  set the sort direction of a } result column to ascending or descending. Ascending order puts smaller values first, where "smaller" is defined in terms of the ? operator. Similarly, descending order is determined with the  operator. , ,  and p options are used to determine whether nulls appear before or after non-null values in the sort ordering of a | result column.squeal-postgresqlA ; is used to eliminate groups that are not of interest. An f  may only use  while a g  must use % whose conditions are combined with .squeal-postgresqlA  indicates the e of a . A  indicates f while a  indicates g. NoGroups is distinguised from  Group Nil& since no aggregation can be done on NoGroups while all output s must be aggregated in  Group Nil. In general, all output s in the complement of bys must be aggregated in  Group bys.squeal-postgresqls are used in group to reference a list of columns which are then used to group together those rows in a table that have the same values in all the columns listed. By #col' will reference an unambiguous column col ; otherwise By2 (#tab ! #col)* will reference a table qualified column tab.col.squeal-postgresqlA ? can be a table name, or a derived table such as a subquery, a JOIN- construct, or complex combinations of these.squeal-postgresqlA 4 computes a table. The table expression contains a " that is optionally followed by a , , , ,  and s. Trivial table expressions simply refer to a table on disk, a so-called base table, but more complex expressions can be used to modify or combine base tables in various ways.squeal-postgresqlVA table reference that can be a table name, or a derived table such as a subquery, a JOIN- construct, or complex combinations of these.squeal-postgresql)optional search coditions, combined with . After the processing of the ! is done, each row of the derived virtual table is checked against the search condition. If the result of the condition is true, the row is kept in the output table, otherwise it is discarded. The search condition typically references at least one column of the table generated in the P; this is not required, but otherwise the WHERE clause will be fairly useless.squeal-postgresqlThe  is used to group together those rows in a table that have the same values in all the columns listed. The order in which the columns are listed does not matter. The effect is to combine each set of rows having common values into one group row that represents all rows in the group. This is done to eliminate redundancy in the output and/or compute aggregates that apply to these groups.squeal-postgresql"If a table has been grouped using 0, but only certain groups are of interest, the  can be used, much like a ;, to eliminate groups from the result. Expressions in the w can refer both to grouped expressions and to ungrouped expressions (which necessarily involve an aggregate function).squeal-postgresqlThe . is for optional sorting. When more than one u is specified, the later (right) values are used to sort rows that are equal according to the earlier (left) values.squeal-postgresqlThe  is combined with  to give a limit count if nonempty. If a limit count is given, no more than that many rows will be returned (but possibly fewer, if the query itself yields fewer rows).squeal-postgresqlThe  is combined with  to give an offset count if nonempty. The offset count says to skip that many rows before beginning to return rows. The rows are skipped before the limit count is applied.squeal-postgresqlVThe process of retrieving or the command to retrieve data from a database is called a %. Let's see some examples of queries. simple query::{ let query :: QueryG '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])] '[] '["col" ::: 'Null 'PGint4]( query = selectStar (from (table #tab))in printSQL query:}SELECT * FROM "tab" AS "tab"restricted query::{let query :: Query '[ "tab" ::: 'Table ('[] :=>0 '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint44 , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ])] '[]! '[ "sum" ::: 'NotNull 'PGint4$ , "col1" ::: 'NotNull 'PGint4 ] query = select* ((#col1 + #col2) `as` #sum :* #col1) ( from (table #tab)! & where_ (#col1 .> #col2) & where_ (#col2 .> 0) )in printSQL query:}rSELECT ("col1" + "col2") AS "sum", "col1" AS "col1" FROM "tab" AS "tab" WHERE (("col1" > "col2") AND ("col2" > 0)) subquery::{ let query :: QueryG '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])] '[] '["col" ::: 'Null 'PGint4] query = selectStarB (from (subquery (selectStar (from (table #tab)) `as` #sub)))in printSQL query:}5SELECT * FROM (SELECT * FROM "tab" AS "tab") AS "sub"limits and offsets::{ let query :: QueryG '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])] '[] '["col" ::: 'Null 'PGint4] query = selectStarD (from (table #tab) & limit 100 & offset 2 & limit 50 & offset 2)in printSQL query:}.SELECT * FROM "tab" AS "tab" LIMIT 50 OFFSET 4parameterized query::{ let query :: QueryL '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGfloat8])] '[ 'NotNull 'PGfloat8]# '["col" ::: 'NotNull 'PGfloat8] query = selectStar3 (from (table #tab) & where_ (#col .> param @1))in printSQL query:};SELECT * FROM "tab" AS "tab" WHERE ("col" > ($1 :: float8))aggregation query::{let query :: Query '[ "tab" ::: 'Table ('[] :=>0 '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint44 , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ])] '[]! '[ "sum" ::: 'NotNull 'PGint4$ , "col1" ::: 'NotNull 'PGint4 ] query =* select (sum_ #col2 `as` #sum :* #col1)& ( from (table (#tab `as` #table1)) & groupBy #col1* & having (#col1 + sum_ #col2 .> 1) )in printSQL query:}xSELECT sum("col2") AS "sum", "col1" AS "col1" FROM "tab" AS "table1" GROUP BY "col1" HAVING (("col1" + sum("col2")) > 1) sorted query::{ let query :: QueryG '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])] '[] '["col" ::: 'Null 'PGint4] query = selectStar8 (from (table #tab) & orderBy [#col & AscNullsFirst])in printSQL query:};SELECT * FROM "tab" AS "tab" ORDER BY "col" ASC NULLS FIRSTjoins::set -XFlexibleContexts:{'let query :: Query '[ "orders" ::: 'Table (- '["pk_orders" ::: PrimaryKey '["id"]M ,"fk_customers" ::: ForeignKey '["customer_id"] "customers" '["id"]O ,"fk_shippers" ::: ForeignKey '["shipper_id"] "shippers" '["id"]] :=>3 '[ "id" ::: 'NoDef :=> 'NotNull 'PGint47 , "price" ::: 'NoDef :=> 'NotNull 'PGfloat49 , "customer_id" ::: 'NoDef :=> 'NotNull 'PGint49 , "shipper_id" ::: 'NoDef :=> 'NotNull 'PGint4 ]) , "customers" ::: 'Table (5 '["pk_customers" ::: PrimaryKey '["id"]] :=>0 '[ "id" ::: 'NoDef :=> 'NotNull 'PGint42 , "name" ::: 'NoDef :=> 'NotNull 'PGtext ]) , "shippers" ::: 'Table (4 '["pk_shippers" ::: PrimaryKey '["id"]] :=>0 '[ "id" ::: 'NoDef :=> 'NotNull 'PGint42 , "name" ::: 'NoDef :=> 'NotNull 'PGtext ]) ] '[]+ '[ "order_price" ::: 'NotNull 'PGfloat4+ , "customer_name" ::: 'NotNull 'PGtext* , "shipper_name" ::: 'NotNull 'PGtext ] query = select& ( #o ! #price `as` #order_price :*' #c ! #name `as` #customer_name :*% #s ! #name `as` #shipper_name )# ( from (table (#orders `as` #o). & innerJoin (table (#customers `as` #c))( (#o ! #customer_id .== #c ! #id)- & innerJoin (table (#shippers `as` #s))* (#o ! #shipper_id .== #s ! #id)) )in printSQL query:}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") self-join::{ let query :: QueryG '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])] '[] '["col" ::: 'Null 'PGint4] query = selectDotStar #t1F (from (table (#tab `as` #t1) & crossJoin (table (#tab `as` #t2))))in printSQL query:}9SELECT "t1".* FROM "tab" AS "t1" CROSS JOIN "tab" AS "t2"value queries::{letR query :: Query '[] '[] '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]Q query = values (1 `as` #foo :* true `as` #bar) [2 `as` #foo :* false `as` #bar]in printSQL query:}@SELECT * FROM (VALUES (1, TRUE), (2, FALSE)) AS t ("foo", "bar")set operations::{ let query :: QueryG '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])] '[] '["col" ::: 'Null 'PGint4] query =" selectStar (from (table #tab)) `unionAll`" selectStar (from (table #tab))in printSQL query:}G(SELECT * FROM "tab" AS "tab") UNION ALL (SELECT * FROM "tab" AS "tab") with queries::{let query :: Query '[ "t1" ::: 'View# '[ "c1" ::: 'NotNull 'PGtext& , "c2" ::: 'NotNull 'PGtext] ] '[] '[ "c1" ::: 'NotNull 'PGtext" , "c2" ::: 'NotNull 'PGtext ] query = with (- selectStar (from (view #t1)) `as` #t2 :>>) selectStar (from (view #t2)) `as` #t3$ ) (selectStar (from (view #t3)))in printSQL query:}jWITH "t2" AS (SELECT * FROM "t1" AS "t1"), "t3" AS (SELECT * FROM "t2" AS "t2") SELECT * FROM "t3" AS "t3"squeal-postgresqlDThe results of two queries can be combined using the set operation  . Duplicate rows are eliminated.squeal-postgresqlDThe results of two queries can be combined using the set operation 2, the disjoint union. Duplicate rows are retained.squeal-postgresqlDThe results of two queries can be combined using the set operation 2, the intersection. Duplicate rows are eliminated.squeal-postgresqlDThe results of two queries can be combined using the set operation 0, the intersection. Duplicate rows are retained.squeal-postgresqlDThe results of two queries can be combined using the set operation 4, the set difference. Duplicate rows are eliminated.squeal-postgresqlDThe results of two queries can be combined using the set operation 2, the set difference. Duplicate rows are retained.squeal-postgresqlthe  in the  command constructs an intermediate virtual table by possibly combining tables, views, eliminating rows, grouping, etc. This table is finally passed on to processing by the select list. The select list determines which columns of the intermediate table are actually output.squeal-postgresqlvAfter the select list has been processed, the result table can be subject to the elimination of duplicate rows using .squeal-postgresqlThe simplest kind of query is = which emits all columns that the table expression produces.squeal-postgresqlA U emits all columns that the table expression produces and eliminates duplicate rows.squeal-postgresqlrWhen working with multiple tables, it can also be useful to ask for all the columns of a particular table, using .squeal-postgresqlA P asks for all the columns of a particular table, and eliminates duplicate rows.squeal-postgresql computes a row value or set of row values specified by value expressions. It is most commonly used to generate a constant table  within a larger command, but it can be used on its own.@type Row = '["a" ::: 'NotNull 'PGint4, "b" ::: 'NotNull 'PGtext]Glet query = values (1 `as` #a :* "one" `as` #b) [] :: Query '[] '[] RowprintSQL query2SELECT * FROM (VALUES (1, E'one')) AS t ("a", "b")squeal-postgresqlK computes a row value or set of row values specified by value expressions.squeal-postgresql Render a squeal-postgresqlA  generates a  from a table reference that can be a table name, or a derived table such as a subquery, a JOIN construct, or complex combinations of these. A  may be transformed by , group, , ,  and  , using the K operator to match the left-to-right sequencing of their placement in SQL.squeal-postgresqlA  is an endomorphism of (s which adds a search condition to the .squeal-postgresqlA  is a transformation of s which switches its e from f to g. Use  group Nil/ to perform a "grand total" aggregation query.squeal-postgresqlA  is an endomorphism of (s which adds a search condition to the .squeal-postgresqlAn  is an endomorphism of 1s which appends an ordering to the right of the .squeal-postgresqlA  is an endomorphism of s which adds to the .squeal-postgresqlAn  is an endomorphism of s which adds to the .squeal-postgresql@Expands the outermost JSON object into a set of key/value pairs.squeal-postgresqlGExpands the outermost binary JSON object into a set of key/value pairs.squeal-postgresql@Expands the outermost JSON object into a set of key/value pairs.squeal-postgresqlGExpands the outermost binary JSON object into a set of key/value pairs.squeal-postgresql1Returns set of keys in the outermost JSON object.squeal-postgresql1Returns set of keys in the outermost JSON object.squeal-postgresqleExpands the JSON expression to a row whose columns match the record type defined by the given table.squeal-postgresqllExpands the binary JSON expression to a row whose columns match the record type defined by the given table.squeal-postgresqlExpands the outermost array of objects in the given JSON expression to a set of rows whose columns match the record type defined by the given table.squeal-postgresqlExpands the outermost array of objects in the given binary JSON expression to a set of rows whose columns match the record type defined by the given table.squeal-postgresql.Builds an arbitrary record from a JSON object.squeal-postgresql5Builds an arbitrary record from a binary JSON object.squeal-postgresql@Builds an arbitrary set of records from a JSON array of objects.squeal-postgresqlGBuilds an arbitrary set of records from a binary JSON array of objects.squeal-postgresqlA real  is a table from the schema.squeal-postgresql derives a table from a .squeal-postgresql derives a table from a A. squeal-postgresqlleft & crossJoin right2. For every possible combination of rows from left and rightc (i.e., a Cartesian product), the joined table will contain a row consisting of all columns in left followed by all columns in right. If the tables have n and m3 rows respectively, the joined table will have n * m rows. squeal-postgresqlleft & innerJoin right on&. The joined table is filtered by the on condition. squeal-postgresqlleft & leftOuterJoin right on?. First, an inner join is performed. Then, for each row in left that does not satisfy the on condition with any row in right7, a joined row is added with null values in columns of rightI. Thus, the joined table always has at least one row for each row in left. squeal-postgresqlleft & rightOuterJoin right on?. First, an inner join is performed. Then, for each row in right that does not satisfy the on condition with any row in left7, a joined row is added with null values in columns of leftg. This is the converse of a left join: the result table will always have a row for each row in right. squeal-postgresqlleft & fullOuterJoin right on?. First, an inner join is performed. Then, for each row in left that does not satisfy the on condition with any row in right7, a joined row is added with null values in columns of right. Also, for each row of right> that does not satisfy the join condition with any row in left2, a joined row with null values in the columns of left is added.squeal-postgresql Renders a .squeal-postgresql Renders a .squeal-postgresql Render a .squeal-postgresql Render a .squeal-postgresqlThe right-hand side is a subs, which must return exactly one column. The left-hand expression is evaluated and compared to each row of the sub result. The result of  is  4 if any equal subquery row is found. The result is  S if no equal row is found (including the case where the subquery returns no rows)..printSQL $ true `in_` values_ (true `as` #foo)4TRUE IN (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))squeal-postgresql#The left-hand side of this form of 3 is a row constructor. The right-hand side is a sub, which must return exactly as many columns as there are expressions in the left-hand row. The left-hand expressions are evaluated and compared row-wise to each row of the subquery result. The result of  is  3 if any equal subquery row is found. The result is  R if no equal row is found (including the case where the subquery returns no rows).let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]&printSQL $ myRow `rowIn` values_ myRowHROW(1, FALSE) IN (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))squeal-postgresql0printSQL $ true `eqAll` values_ (true `as` #foo)7TRUE = ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))squeal-postgresqllet myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool])printSQL $ myRow `rowEqAll` values_ myRowKROW(1, FALSE) = ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))squeal-postgresql0printSQL $ true `eqAny` values_ (true `as` #foo)7TRUE = ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))squeal-postgresqllet myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool])printSQL $ myRow `rowEqAny` values_ myRowKROW(1, FALSE) = ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))squeal-postgresql1printSQL $ true `neqAll` values_ (true `as` #foo)8TRUE <> ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))squeal-postgresqllet myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]*printSQL $ myRow `rowNeqAll` values_ myRowLROW(1, FALSE) <> ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))squeal-postgresql1printSQL $ true `neqAny` values_ (true `as` #foo)8TRUE <> ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))squeal-postgresqllet myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]*printSQL $ myRow `rowNeqAny` values_ myRowLROW(1, FALSE) <> ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))squeal-postgresql0printSQL $ true `allLt` values_ (true `as` #foo)7TRUE ALL < (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))squeal-postgresqllet myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool])printSQL $ myRow `rowLtAll` values_ myRowKROW(1, FALSE) ALL < (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))squeal-postgresql0printSQL $ true `ltAny` values_ (true `as` #foo)7TRUE ANY < (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))squeal-postgresqllet myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool])printSQL $ myRow `rowLtAll` values_ myRowKROW(1, FALSE) ALL < (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar")) squeal-postgresql1printSQL $ true `lteAll` values_ (true `as` #foo)8TRUE <= ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))!squeal-postgresqllet myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]*printSQL $ myRow `rowLteAll` values_ myRowLROW(1, FALSE) <= ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))"squeal-postgresql1printSQL $ true `lteAny` values_ (true `as` #foo)8TRUE <= ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))#squeal-postgresqllet myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]*printSQL $ myRow `rowLteAny` values_ myRowLROW(1, FALSE) <= ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))$squeal-postgresql0printSQL $ true `gtAll` values_ (true `as` #foo)7TRUE > ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))%squeal-postgresqllet myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool])printSQL $ myRow `rowGtAll` values_ myRowKROW(1, FALSE) > ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))&squeal-postgresql0printSQL $ true `gtAny` values_ (true `as` #foo)7TRUE > ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))'squeal-postgresqllet myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool])printSQL $ myRow `rowGtAny` values_ myRowKROW(1, FALSE) > ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))(squeal-postgresql1printSQL $ true `gteAll` values_ (true `as` #foo)8TRUE >= ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo")))squeal-postgresqllet myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]*printSQL $ myRow `rowGteAll` values_ myRowLROW(1, FALSE) >= ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))*squeal-postgresql1printSQL $ true `gteAny` values_ (true `as` #foo)8TRUE >= ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))+squeal-postgresqllet myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]*printSQL $ myRow `rowGteAny` values_ myRowLROW(1, FALSE) >= ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar")),squeal-postgresql render a .-squeal-postgresqlrender a non-empty $ of s.?squeal-postgresqlcommon table expressionssqueal-postgresql larger querysqueal-postgresql select listsqueal-postgresqlintermediate virtual tablesqueal-postgresql select listsqueal-postgresqlintermediate virtual tablesqueal-postgresqlintermediate virtual tablesqueal-postgresqlintermediate virtual tablesqueal-postgresqlparticular virtual subtablesqueal-postgresqlintermediate virtual tablesqueal-postgresqlparticular virtual tablesqueal-postgresqlintermediate virtual tablesqueal-postgresql]When more than one row is specified, all the rows must must have the same number of elementssqueal-postgresqlone row of valuessqueal-postgresqltable referencesqueal-postgresqlfiltering conditionsqueal-postgresqlgrouped columnssqueal-postgresqlhaving conditionsqueal-postgresqlsort expressionssqueal-postgresqllimit parametersqueal-postgresqloffset parametersqueal-postgresql json objectsqueal-postgresql jsonb objectsqueal-postgresql json objectsqueal-postgresql jsonb objectsqueal-postgresql json objectsqueal-postgresql jsonb objectsqueal-postgresqlrow typesqueal-postgresql json objectsqueal-postgresqlrow typesqueal-postgresql jsonb objectsqueal-postgresqlrow typesqueal-postgresql json arraysqueal-postgresqlrow typesqueal-postgresql jsonb arraysqueal-postgresql json objectsqueal-postgresql record typessqueal-postgresql jsonb objectsqueal-postgresql record typessqueal-postgresql json arraysqueal-postgresql record typessqueal-postgresql jsonb arraysqueal-postgresql record types squeal-postgresqlrightsqueal-postgresqlleft squeal-postgresqlrightsqueal-postgresqlon conditionsqueal-postgresqlleft squeal-postgresqlrightsqueal-postgresqlon conditionsqueal-postgresqlleft squeal-postgresqlrightsqueal-postgresqlon conditionsqueal-postgresqlleft squeal-postgresqlrightsqueal-postgresqlon conditionsqueal-postgresqlleftsqueal-postgresql expressionsqueal-postgresqlsubquerysqueal-postgresqlrow constructorsqueal-postgresqlsubquerysqueal-postgresql expressionsqueal-postgresqlsubquerysqueal-postgresqlrow constructorsqueal-postgresqlsubquerysqueal-postgresql expressionsqueal-postgresqlsubquerysqueal-postgresqlrow constructorsqueal-postgresqlsubquerysqueal-postgresql expressionsqueal-postgresqlsubquerysqueal-postgresqlrow constructorsqueal-postgresqlsubquerysqueal-postgresql expressionsqueal-postgresqlsubquerysqueal-postgresqlrow constructorsqueal-postgresqlsubquerysqueal-postgresql expressionsqueal-postgresqlsubquerysqueal-postgresqlrow constructorsqueal-postgresqlsubquerysqueal-postgresql expressionsqueal-postgresqlsubquerysqueal-postgresqlrow constructorsqueal-postgresqlsubquery squeal-postgresql expressionsqueal-postgresqlsubquery!squeal-postgresqlrow constructorsqueal-postgresqlsubquery"squeal-postgresql expressionsqueal-postgresqlsubquery#squeal-postgresqlrow constructorsqueal-postgresqlsubquery$squeal-postgresql expressionsqueal-postgresqlsubquery%squeal-postgresqlrow constructorsqueal-postgresqlsubquery&squeal-postgresql expressionsqueal-postgresqlsubquery'squeal-postgresqlrow constructorsqueal-postgresqlsubquery(squeal-postgresql expressionsqueal-postgresqlsubquery)squeal-postgresqlrow constructorsqueal-postgresqlsubquery*squeal-postgresql expressionsqueal-postgresqlsubquery+squeal-postgresqlrow constructorsqueal-postgresqlsubquery,squeal-postgresqlrender statement-squeal-postgresqlrender statemento      !"#$%&'()*+,-o,-      !"#$%&'()*+!Squeal data manipulation language(c) Eitan Chatav, 2017eitan@morphism.tech experimentalNone&',-6<FKQSTV]^#Gsqueal-postgresqlA G> specifies an action to perform upon a constraint violation. H will raise an error. I! simply avoids inserting a row. JN updates the existing row that conflicts with the row proposed for insertion.Ksqueal-postgresqlA K computes and return value(s) based on each row actually inserted, updated or deleted. This is primarily useful for obtaining values that were supplied by defaults, such as a serial sequence number. However, any expression using the table's columns is allowed. Only rows that were successfully inserted or updated or deleted will be returned. For example, if a row was locked but not updated because an J= condition was not satisfied, the row will not be returned. L* will return all columns in the row. Use  Returning Nil8 in the common case where no return values are desired.Nsqueal-postgresqlN,s are values to insert or update in a row. O updates with the same value. P inserts or updates with the DEFAULT value. Q sets a value to be an >, which can refer to existing value in the row for an update.Rsqueal-postgresqlA R is a statement which may modify data in the database, but does not alter the schema. Examples are inserts, updates and deletes. A  is also considered a R% even though it does not modify data.simple insert::{ let manipulation :: Manipulation '[ "tab" ::: 'Table ('[] :=>/ '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint49 , "col2" ::: 'Def :=> 'NotNull 'PGint4 ])] '[] '[] manipulation =< insertRow_ #tab (Set 2 `as` #col1 :* Default `as` #col2)in printSQL manipulation:}6INSERT INTO "tab" ("col1", "col2") VALUES (2, DEFAULT)parameterized insert::{ let manipulation :: Manipulation '[ "tab" ::: 'Table ('[] :=>/ '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint43 , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ])]/ '[ 'NotNull 'PGint4, 'NotNull 'PGint4 ] '[] manipulation = insertRow_ #tab> (Set (param @1) `as` #col1 :* Set (param @2) `as` #col2)in printSQL manipulation:}FINSERT INTO "tab" ("col1", "col2") VALUES (($1 :: int4), ($2 :: int4))returning insert::{ let manipulation :: Manipulation '[ "tab" ::: 'Table ('[] :=>/ '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint45 , "col2" ::: 'Def :=> 'NotNull 'PGint4 ])] '[]& '["fromOnly" ::: 'NotNull 'PGint4] manipulation =; insertRow #tab (Set 2 `as` #col1 :* Default `as` #col2): OnConflictDoRaise (Returning (#col1 `as` #fromOnly))in printSQL manipulation:}UINSERT INTO "tab" ("col1", "col2") VALUES (2, DEFAULT) RETURNING "col1" AS "fromOnly"upsert::{let manipulation :: Manipulation '[ "tab" ::: 'Table ('[] :=>/ '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint43 , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ])]& '[] '[ "sum" ::: 'NotNull 'PGint4] manipulation = insertRows #tab, (Set 2 `as` #col1 :* Set 4 `as` #col2), [Set 6 `as` #col1 :* Set 8 `as` #col2] (OnConflictDoUpdate- (Set 2 `as` #col1 :* Same `as` #col2) [#col1 .== #col2])- (Returning $ (#col1 + #col2) `as` #sum)in printSQL manipulation:}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" query insert::{let manipulation :: Manipulation '[ "tab" ::: 'Table ('[] :=>/ '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4/ , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ])& , "other_tab" ::: 'Table ('[] :=>/ '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4/ , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ]) ] '[] '[] manipulation = insertQuery_ #tab6 (selectStar (from (table (#other_tab `as` #t))))in printSQL manipulation:}2INSERT INTO "tab" SELECT * FROM "other_tab" AS "t"update::{ let manipulation :: Manipulation '[ "tab" ::: 'Table ('[] :=>/ '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4; , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ])] '[] '[] manipulation =6 update_ #tab (Set 2 `as` #col1 :* Same `as` #col2) (#col1 ./= #col2)in printSQL manipulation:}4UPDATE "tab" SET "col1" = 2 WHERE ("col1" <> "col2")delete::{ let manipulation :: Manipulation '[ "tab" ::: 'Table ('[] :=>/ '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint47 , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ])] '[]" '[ "col1" ::: 'NotNull 'PGint4$ , "col2" ::: 'NotNull 'PGint4 ]@ manipulation = deleteFrom #tab (#col1 .== #col2) ReturningStarin printSQL manipulation:}5DELETE FROM "tab" WHERE ("col1" = "col2") RETURNING *with manipulation:otype ProductsTable = '[] :=> '["product" ::: 'NoDef :=> 'NotNull 'PGtext, "date" ::: 'Def :=> 'NotNull 'PGdate]:{ let manipulation :: Manipulation* '[ "products" ::: 'Table ProductsTable2 , "products_deleted" ::: 'Table ProductsTable ] '[ 'NotNull 'PGdate] '[] manipulation = withO (deleteFrom #products (#date .< param @1) ReturningStar `as` #deleted_rows)W (insertQuery_ #products_deleted (selectStar (from (view (#deleted_rows `as` #t)))))in printSQL manipulation:}WITH "deleted_rows" AS (DELETE FROM "products" WHERE ("date" < ($1 :: date)) RETURNING *) INSERT INTO "products_deleted" SELECT * FROM "deleted_rows" AS "t"Usqueal-postgresql Convert a  into a R.Vsqueal-postgresqlInsert multiple rows.\When a table is created, it contains no data. The first thing to do before a database can be of much use is to insert data. Data is conceptually inserted one row at a time. Of course you can also insert more than one row, but there is no way to insert less than one row. Even if you know only some column values, a complete row must be created.Wsqueal-postgresqlInsert a single row.Xsqueal-postgresqlInsert multiple rows returning # and raising an error on conflicts.Ysqueal-postgresqlInsert a single row returning # and raising an error on conflicts.Zsqueal-postgresql Insert a .[squeal-postgresql Insert a  returning # and raising an error on conflicts.\squeal-postgresql Render a K.]squeal-postgresql Render a G.^squeal-postgresqlAn ^] command changes the values of the specified columns in all rows that satisfy the condition._squeal-postgresqlUpdate a row returning .`squeal-postgresqlDelete rows of a table.asqueal-postgresqlDelete rows returning . Vsqueal-postgresqltable to insert intosqueal-postgresql row to insertsqueal-postgresqlmore rows to insertsqueal-postgresql)what to do in case of constraint conflictsqueal-postgresqlresults to returnWsqueal-postgresqltable to insert intosqueal-postgresql row to insertsqueal-postgresql)what to do in case of constraint conflictsqueal-postgresqlresults to returnXsqueal-postgresqltable to insert intosqueal-postgresql row to insertsqueal-postgresqlmore rows to insertYsqueal-postgresqltable to insert intosqueal-postgresql row to insertZsqueal-postgresqltable to insert intosqueal-postgresql)what to do in case of constraint conflictsqueal-postgresqlresults to return[squeal-postgresqltable to insert into^squeal-postgresqltable to updatesqueal-postgresql%modified values to replace old valuessqueal-postgresql0condition under which to perform update on a rowsqueal-postgresqlresults to return_squeal-postgresqltable to updatesqueal-postgresql%modified values to replace old valuessqueal-postgresql0condition under which to perform update on a row`squeal-postgresqltable to delete fromsqueal-postgresql%condition under which to delete a rowsqueal-postgresqlresults to returnasqueal-postgresqltable to delete fromsqueal-postgresql%condition under which to delete a rowGHIJKLMNQPORSTUVWXYZ[\]^_`aRSTUNQPOKLMGHIJVWXYZ[\]^_`aSqueal data definition language(c) Eitan Chatav, 2017eitan@morphism.tech experimentalNone&'+,-6;<=>?FKQSTV]i5isqueal-postgresqlis are used in  commands.lsqueal-postgresqlAn l8 describes the alteration to perform on a single column.osqueal-postgresqlAn o is either NULL or has DEFAULT.psqueal-postgresqlpS adds a new column, initially filled with whatever default value is given or with NULL.:{ let definition :: DefinitionH '["tab" ::: 'Table ('[] :=> '["col1" ::: 'NoDef :=> 'Null 'PGint4])] '["tab" ::: 'Table ('[] :=>- '[ "col1" ::: 'NoDef :=> 'Null 'PGint4/ , "col2" ::: 'Def :=> 'Null 'PGtext ])]S definition = alterTable #tab (addColumn #col2 (text & nullable & default_ "foo"))in printSQL definition:}=ALTER TABLE "tab" ADD COLUMN "col2" text NULL DEFAULT E'foo';:{ let definition :: DefinitionH '["tab" ::: 'Table ('[] :=> '["col1" ::: 'NoDef :=> 'Null 'PGint4])] '["tab" ::: 'Table ('[] :=>- '[ "col1" ::: 'NoDef :=> 'Null 'PGint41 , "col2" ::: 'NoDef :=> 'Null 'PGtext ])]B definition = alterTable #tab (addColumn #col2 (text & nullable))in printSQL definition:}.ALTER TABLE "tab" ADD COLUMN "col2" text NULL;qsqueal-postgresqlAn q@ describes the alteration to perform on the columns of a table.tsqueal-postgresql Analagous to x there is also tA which is invoked when a referenced column is changed (updated).usqueal-postgresql[if any referencing rows has not changed when the constraint is checked, an error is raisedvsqueal-postgresql#prevents update of a referenced rowwsqueal-postgresql\the updated values of the referenced column(s) should be copied into the referencing row(s)xsqueal-postgresqlx= indicates what to do with rows that reference a deleted row.ysqueal-postgresqlWif any referencing rows still exist when the constraint is checked, an error is raisedzsqueal-postgresql%prevents deletion of a referenced row{squeal-postgresqlospecifies that when a referenced row is deleted, row(s) referencing it should be automatically deleted as well|squeal-postgresqlHA constraint synonym between types involved in a foreign key constraint.}squeal-postgresqlData types are a way to limit the kind of data that can be stored in a table. For many applications, however, the constraint they provide is too coarse. For example, a column containing a product price should probably only accept positive values. But there is no standard data type that accepts only positive numbers. Another issue is that you might want to constrain column data with respect to other columns or rows. For example, in a table containing product information, there should be only one row for each product number. os give you as much control over the data in your tables as you wish. If a user attempts to store data in a column that would violate a constraint, an error is raised. This applies even if the value came from the default value definition.squeal-postgresqlA A is a statement that changes the schema of the database, like a , , or  command. s may be composed using the  operator.squeal-postgresql adds a table to the schema.:set -XOverloadedLabels:{type Table = '[] :=>% '[ "a" ::: 'NoDef :=> 'Null 'PGint4) , "b" ::: 'NoDef :=> 'Null 'PGfloat4 ]:}:{let3 setup :: Definition '[] '["tab" ::: 'Table Table] setup = createTable #tab7 (nullable int `as` #a :* nullable real `as` #b) Nilin printSQL setup:}1CREATE TABLE "tab" ("a" int NULL, "b" real NULL);squeal-postgresql creates a table if it doesn't exist, but does not add it to the schema. Instead, the schema already has the table so if the table did not yet exist, the schema was wrong. H fixes this. Interestingly, this property makes it an idempotent in the  of s.*:set -XOverloadedLabels -XTypeApplications:{type Table = '[] :=>% '[ "a" ::: 'NoDef :=> 'Null 'PGint4) , "b" ::: 'NoDef :=> 'Null 'PGfloat4 ]:}'type Schema = '["tab" ::: 'Table Table]:{let# setup :: Definition Schema Schema% setup = createTableIfNotExists #tab7 (nullable int `as` #a :* nullable real `as` #b) Nilin printSQL setup:}?CREATE TABLE IF NOT EXISTS "tab" ("a" int NULL, "b" real NULL);squeal-postgresqlA  constraint is the most generic os type. It allows you to specify that the value in a certain column must satisfy a Boolean (truth-value) expression.:{type Schema = '[A "tab" ::: 'Table ('[ "inequality" ::: 'Check '["a","b"]] :=> '[( "a" ::: 'NoDef :=> 'NotNull 'PGint4,' "b" ::: 'NoDef :=> 'NotNull 'PGint4 ])]:}:{let% definition :: Definition '[] Schema definition = createTable #tab$ ( (int & notNullable) `as` #a :*# (int & notNullable) `as` #b )4 ( check (#a :* #b) (#a .> #b) `as` #inequality ):}printSQL definitioneCREATE TABLE "tab" ("a" int NOT NULL, "b" int NOT NULL, CONSTRAINT "inequality" CHECK (("a" > "b")));squeal-postgresqlA y constraint ensure that the data contained in a column, or a group of columns, is unique among all the rows in the table.:{type Schema = '[> "tab" ::: 'Table( '[ "uq_a_b" ::: 'Unique '["a","b"]] :=> '[% "a" ::: 'NoDef :=> 'Null 'PGint4,$ "b" ::: 'NoDef :=> 'Null 'PGint4 ])]:}:{let% definition :: Definition '[] Schema definition = createTable #tab! ( (int & nullable) `as` #a :* (int & nullable) `as` #b )& ( unique (#a :* #b) `as` #uq_a_b ):}printSQL definitionWCREATE TABLE "tab" ("a" int NULL, "b" int NULL, CONSTRAINT "uq_a_b" UNIQUE ("a", "b"));squeal-postgresqlA  constraint indicates that a column, or group of columns, can be used as a unique identifier for rows in the table. This requires that the values be both unique and not null.:{type Schema = '[> "tab" ::: 'Table ('[ "pk_id" ::: 'PrimaryKey '["id"]] :=> '[' "id" ::: 'Def :=> 'NotNull 'PGint4,* "name" ::: 'NoDef :=> 'NotNull 'PGtext ])]:}:{let% definition :: Definition '[] Schema definition = createTable #tab ( serial `as` #id :*' (text & notNullable) `as` #name )" ( primaryKey #id `as` #pk_id ):}printSQL definition^CREATE TABLE "tab" ("id" serial, "name" text NOT NULL, CONSTRAINT "pk_id" PRIMARY KEY ("id"));squeal-postgresqlA  specifies that the values in a column (or a group of columns) must match the values appearing in some row of another table. We say this maintains the referential integrity between two related tables.:{ type Schema = '[ "users" ::: 'Table (2 '[ "pk_users" ::: 'PrimaryKey '["id"] ] :=>, '[ "id" ::: 'Def :=> 'NotNull 'PGint40 , "name" ::: 'NoDef :=> 'NotNull 'PGtext ]) , "emails" ::: 'Table (. '[ "pk_emails" ::: 'PrimaryKey '["id"]C , "fk_user_id" ::: 'ForeignKey '["user_id"] "users" '["id"] ] :=>, '[ "id" ::: 'Def :=> 'NotNull 'PGint43 , "user_id" ::: 'NoDef :=> 'NotNull 'PGint4. , "email" ::: 'NoDef :=> 'Null 'PGtext ]) ]:}:{let setup :: Definition '[] Schema setup = createTable #users ( serial `as` #id :*( (text & notNullable) `as` #name )* ( primaryKey #id `as` #pk_users ) >>> createTable #emails ( serial `as` #id :*+ (int & notNullable) `as` #user_id :*& (text & nullable) `as` #email )( ( primaryKey #id `as` #pk_emails :*% foreignKey #user_id #users #id; OnDeleteCascade OnUpdateCascade `as` #fk_user_id )in printSQL setup:}cCREATE 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 NULL, CONSTRAINT "pk_emails" PRIMARY KEY ("id"), CONSTRAINT "fk_user_id" FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE CASCADE);A $ can even be a table self-reference.:{ type Schema = '[ "employees" ::: 'Table (9 '[ "employees_pk" ::: 'PrimaryKey '["id"]V , "employees_employer_fk" ::: 'ForeignKey '["employer_id"] "employees" '["id"] ] :=>7 '[ "id" ::: 'Def :=> 'NotNull 'PGint47 , "name" ::: 'NoDef :=> 'NotNull 'PGtext7 , "employer_id" ::: 'NoDef :=> 'Null 'PGint4 ]) ]:}:{ let setup :: Definition '[] Schema setup = createTable #employees ( serial `as` #id :*) (text & notNullable) `as` #name :*/ (integer & nullable) `as` #employer_id )+ ( primaryKey #id `as` #employees_pk :*- foreignKey #employer_id #employees #idF OnDeleteCascade OnUpdateCascade `as` #employees_employer_fk )in printSQL setup:} CREATE TABLE "employees" ("id" serial, "name" text NOT NULL, "employer_id" integer NULL, CONSTRAINT "employees_pk" PRIMARY KEY ("id"), CONSTRAINT "employees_employer_fk" FOREIGN KEY ("employer_id") REFERENCES "employees" ("id") ON DELETE CASCADE ON UPDATE CASCADE);squeal-postgresqlRender x.squeal-postgresqlRender t.squeal-postgresql! removes a table from the schema.:{let: definition :: Definition '["muh_table" ::: 'Table t] '[]# definition = dropTable #muh_table:}printSQL definitionDROP TABLE "muh_table";squeal-postgresql3 changes the definition of a table from the schema.squeal-postgresql- changes the name of a table from the schema.%printSQL $ alterTableRename #foo #bar"ALTER TABLE "foo" RENAME TO "bar";squeal-postgresqlAn  adds a table constraint.:{let definition :: DefinitionJ '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]g '["tab" ::: 'Table ('["positive" ::: Check '["col"]] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]Q definition = alterTable #tab (addConstraint #positive (check #col (#col .> 0)))in printSQL definition:}@ALTER TABLE "tab" ADD CONSTRAINT "positive" CHECK (("col" > 0));squeal-postgresqlA  drops a table constraint.:{let definition :: Definitiong '["tab" ::: 'Table ('["positive" ::: Check '["col"]] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]J '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]9 definition = alterTable #tab (dropConstraint #positive)in printSQL definition:}-ALTER TABLE "tab" DROP CONSTRAINT "positive";squeal-postgresqlA  removes a column. Whatever data was in the column disappears. Table constraints involving the column are dropped, too. However, if the column is referenced by a foreign key constraint of another table, PostgreSQL will not silently drop that constraint.:{ let definition :: Definition '["tab" ::: 'Table ('[] :=>- '[ "col1" ::: 'NoDef :=> 'Null 'PGint41 , "col2" ::: 'NoDef :=> 'Null 'PGtext ])]H '["tab" ::: 'Table ('[] :=> '["col1" ::: 'NoDef :=> 'Null 'PGint4])]1 definition = alterTable #tab (dropColumn #col2)in printSQL definition:}%ALTER TABLE "tab" DROP COLUMN "col2";squeal-postgresqlA  renames a column.:{let definition :: DefinitionG '["tab" ::: 'Table ('[] :=> '["foo" ::: 'NoDef :=> 'Null 'PGint4])]G '["tab" ::: 'Table ('[] :=> '["bar" ::: 'NoDef :=> 'Null 'PGint4])]7 definition = alterTable #tab (renameColumn #foo #bar)in printSQL definition:}/ALTER TABLE "tab" RENAME COLUMN "foo" TO "bar";squeal-postgresqlAn  alters a single column.squeal-postgresqlA  sets a new default for a column. Note that this doesn't affect any existing rows in the table, it just changes the default for future insert and update commands.:{let definition :: DefinitionG '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]E '["tab" ::: 'Table ('[] :=> '["col" ::: 'Def :=> 'Null 'PGint4])]@ definition = alterTable #tab (alterColumn #col (setDefault 5))in printSQL definition:}3ALTER TABLE "tab" ALTER COLUMN "col" SET DEFAULT 5;squeal-postgresqlA ( removes any default value for a column.:{let definition :: DefinitionE '["tab" ::: 'Table ('[] :=> '["col" ::: 'Def :=> 'Null 'PGint4])]G '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]= definition = alterTable #tab (alterColumn #col dropDefault)in printSQL definition:}2ALTER TABLE "tab" ALTER COLUMN "col" DROP DEFAULT;squeal-postgresqlA  adds a NOT NULL constraint to a column. The constraint will be checked immediately, so the table data must satisfy the constraint before it can be added.:{let definition :: DefinitionG '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]J '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]< definition = alterTable #tab (alterColumn #col setNotNull)in printSQL definition:}2ALTER TABLE "tab" ALTER COLUMN "col" SET NOT NULL;squeal-postgresqlA  drops a NOT NULL constraint from a column.:{let definition :: DefinitionJ '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]G '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]= definition = alterTable #tab (alterColumn #col dropNotNull)in printSQL definition:}3ALTER TABLE "tab" ALTER COLUMN "col" DROP NOT NULL;squeal-postgresqlAn  converts a column to a different data type. This will succeed only if each existing entry in the column can be converted to the new type by an implicit cast.:{ let definition :: DefinitionJ '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]M '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGnumeric])] definition =J alterTable #tab (alterColumn #col (alterType (numeric & notNullable)))in printSQL definition:};ALTER TABLE "tab" ALTER COLUMN "col" TYPE numeric NOT NULL;squeal-postgresqlCreate a view.:{ let definition :: Definition '[ "abc" ::: 'Table ('[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGint4, "c" ::: 'NoDef :=> 'Null 'PGint4])] '[ "abc" ::: 'Table ('[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGint4, "c" ::: 'NoDef :=> 'Null 'PGint4])I , "bc" ::: 'View ('["b" ::: 'Null 'PGint4, "c" ::: 'Null 'PGint4])] definition =: createView #bc (select (#b :* #c) (from (table #abc)))in printSQL definition:}FCREATE VIEW "bc" AS SELECT "b" AS "b", "c" AS "c" FROM "abc" AS "abc";squeal-postgresql Drop a view.:{ let definition :: Definition '[ "abc" ::: 'Table ('[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGint4, "c" ::: 'NoDef :=> 'Null 'PGint4])I , "bc" ::: 'View ('["b" ::: 'Null 'PGint4, "c" ::: 'Null 'PGint4])] '[ "abc" ::: 'Table ('[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGint4, "c" ::: 'NoDef :=> 'Null 'PGint4])] definition = dropView #bcin printSQL definition:}DROP VIEW "bc";squeal-postgresql'Enumerated types are created using the  command, for exampleOprintSQL $ createTypeEnum #mood (label @"sad" :* label @"ok" :* label @"happy")2CREATE TYPE "mood" AS ENUM ('sad', 'ok', 'happy');squeal-postgresqlGEnumerated types can also be generated from a Haskell type, for example:data Schwarma = Beef | Lamb | Chicken deriving GHC.Genericinstance SOP.Generic Schwarma%instance SOP.HasDatatypeInfo Schwarma1printSQL $ createTypeEnumFrom @Schwarma #schwarma;CREATE TYPE "schwarma" AS ENUM ('Beef', 'Lamb', 'Chicken');squeal-postgresqlg creates a composite type. The composite type is specified by a list of attribute names and data types.:{type PGcomplex = 'PGcomposite' '[ "real" ::: 'NotNull 'PGfloat8) , "imaginary" ::: 'NotNull 'PGfloat8 ]:}:{let= setup :: Definition '[] '["complex" ::: 'Typedef PGcomplex]& setup = createTypeComposite #complex1 (float8 `as` #real :* float8 `as` #imaginary)in printSQL setup:}=CREATE TYPE "complex" AS ("real" float8, "imaginary" float8);squeal-postgresqlFComposite types can also be generated from a Haskell type, for exampleQdata Complex = Complex {real :: Double, imaginary :: Double} deriving GHC.Genericinstance SOP.Generic Complex$instance SOP.HasDatatypeInfo Complex4printSQL $ createTypeCompositeFrom @Complex #complex=CREATE TYPE "complex" AS ("real" float8, "imaginary" float8);squeal-postgresql Drop a type.:data Schwarma = Beef | Lamb | Chicken deriving GHC.Genericinstance SOP.Generic Schwarma%instance SOP.HasDatatypeInfo SchwarmaeprintSQL (dropType #schwarma :: Definition '["schwarma" ::: 'Typedef (PG (Enumerated Schwarma))] '[])DROP TYPE "schwarma";squeal-postgresqlused in / commands as a column constraint to note that NULL may be present in a columnsqueal-postgresqlused in , commands as a column constraint to ensure NULL is not present in a columnsqueal-postgresqlused in 2 commands as a column constraint to give a defaultsqueal-postgresqlgnot a true type, but merely a notational convenience for creating unique identifier columns with type squeal-postgresqlgnot a true type, but merely a notational convenience for creating unique identifier columns with type squeal-postgresqlgnot a true type, but merely a notational convenience for creating unique identifier columns with type squeal-postgresqlgnot a true type, but merely a notational convenience for creating unique identifier columns with type squeal-postgresqlgnot a true type, but merely a notational convenience for creating unique identifier columns with type squeal-postgresqlgnot a true type, but merely a notational convenience for creating unique identifier columns with type psqueal-postgresql column to addsqueal-postgresqltype of the new columnsqueal-postgresqlthe name of the table to addsqueal-postgresql%the names and datatype of each columnsqueal-postgresql(constraints that must hold for the tablesqueal-postgresqlthe name of the table to addsqueal-postgresql%the names and datatype of each columnsqueal-postgresql(constraints that must hold for the tablesqueal-postgresqlthe name of the table to addsqueal-postgresql%the names and datatype of each columnsqueal-postgresql(constraints that must hold for the tablesqueal-postgresql0specify the subcolumns which are getting checkedsqueal-postgresql a closed  on those subcolumnssqueal-postgresql9specify subcolumns which together are unique for each rowsqueal-postgresql9specify the subcolumns which together form a primary key.squeal-postgresqlcolumn or columns in the tablesqueal-postgresqlreference tablesqueal-postgresql2reference column or columns in the reference tablesqueal-postgresql$what to do when reference is deletedsqueal-postgresql$what to do when reference is updatedsqueal-postgresqltable to removesqueal-postgresqltable to altersqueal-postgresqlalteration to performsqueal-postgresqltable to renamesqueal-postgresqlwhat to rename itsqueal-postgresqlconstraint to addsqueal-postgresqlconstraint to dropsqueal-postgresqlcolumn to removesqueal-postgresqlcolumn to renamesqueal-postgresqlwhat to rename the columnsqueal-postgresqlcolumn to altersqueal-postgresqlalteration to performsqueal-postgresqldefault value to setsqueal-postgresqlthe name of the view to addsqueal-postgresqlquerysqueal-postgresqlview to removesqueal-postgresql(name of the user defined enumerated typesqueal-postgresqllabels of the enumerated typesqueal-postgresql(name of the user defined enumerated typesqueal-postgresql'name of the user defined composite typesqueal-postgresql&list of attribute names and data typessqueal-postgresql'name of the user defined composite typesqueal-postgresqlname of the user defined type@ijklmnopqrstuvwxyz{|}~@}~|xyz{tuvwqrsoplmnijk Binary encoding and decoding(c) Eitan Chatav, 2017eitan@morphism.tech experimentalNone&',-34567;<=>?AFSTV]i squeal-postgresqlA is a 1-tuple type, useful for encoding a single parameter with ! or decoding a single value with .import Data.TextDtoParams @(Only (Maybe Text)) @'[ 'Null 'PGtext] (Only (Just "foo"))K (Just "foo") :* NilUfromRow @'["fromOnly" ::: 'Null 'PGtext] @(Only (Maybe Text)) (K (Just "bar") :* Nil)$Right (Only {fromOnly = Just "bar"})squeal-postgresqlA D constraint generically sequences the parsings of the columns of a k into the fields of a record N provided they have the same field names. You should not define instances of . Instead define  and " instances which in turn provide  instances.squeal-postgresql :set -XOverloadedStringsimport Data.Text<newtype UserId = UserId { getUserId :: Int16 } deriving ShowQinstance FromValue 'PGint2 UserId where fromValue = UserId <$> fromValue @'PGint2`data UserRow = UserRow { userId :: UserId, userName :: Maybe Text } deriving (Show, GHC.Generic)instance Generic UserRow instance HasDatatypeInfo UserRowJtype User = '["userId" ::: 'NotNull 'PGint2, "userName" ::: 'Null 'PGtext]LfromRow @User @UserRow (K (Just "\NUL\SOH") :* K (Just "bloodninja") :* Nil)ORight (UserRow {userId = UserId {getUserId = 1}, userName = Just "bloodninja"})squeal-postgresqlA  constraint lifts the  parser to a decoding of a (Symbol, NullityType) to a  , decoding |s to (s. You should not define instances for ", just use the provided instances.squeal-postgresqlA C constraint gives a parser from the binary format of a PostgreSQL  into a Haskell .squeal-postgresql0newtype Id = Id { getId :: Int16 } deriving ShowIinstance FromValue 'PGint2 Id where fromValue = Id <$> fromValue @'PGint2squeal-postgresqlA 3 constraint generically sequences the encodings of 2s of the fields of a tuple or record to a row of u's. You should not define instances of . Instead define " instances which in turn provide  instances.squeal-postgresql1type Params = '[ 'NotNull 'PGbool, 'Null 'PGint2]RtoParams @(Bool, Maybe Int16) @'[ 'NotNull 'PGbool, 'Null 'PGint2] (False, Just 0)-K (Just "\NUL") :* K (Just "\NUL\NUL") :* Nil:set -XDeriveGenericHdata Tuple = Tuple { p1 :: Bool, p2 :: Maybe Int16} deriving GHC.Genericinstance Generic Tuple.toParams @Tuple @Params (Tuple False (Just 0))-K (Just "\NUL") :* K (Just "\NUL\NUL") :* Nilsqueal-postgresqlA + constraint gives an encoding of a Haskell . into into the binary format of a PostgreSQL .squeal-postgresql#:set -XTypeApplications -XDataKindstoParam @Bool @'PGbool FalseK "\NUL"toParam @Int16 @'PGint2 0 K "\NUL\NUL"toParam @Int32 @'PGint4 0K "\NUL\NUL\NUL\NUL":set -XMultiParamTypeClasses0newtype Id = Id { getId :: Int16 } deriving Show;instance ToParam Id 'PGint2 where toParam = toParam . getIdtoParam @Id @'PGint2 (Id 1) K "\NUL\SOH"  PQ monad(c) Eitan Chatav, 2017eitan@morphism.tech experimentalNone,-7;<=>?AFQSTVi G 6squeal-postgresqls that can be thrown by Squeal.;squeal-postgresql Ehttps://www.postgresql.org/docs/current/static/errcodes-appendix.html=squeal-postgresqlA snapshot of the state of a P computation.>squeal-postgresql> is an mtl style constraint, similar to $% , for using LibPQ to ? runs a R# with params from a type with a  constraint. It calls # and doesn't afraid of anything.@ is like ? for a parameter-free statement.A is like ? for query statements.B is like A for a parameter-free statement.C3 has the same type signature as a composition of  and ?@ but provides an optimization by preparing the statement with  and then traversing a  container with 9. The temporary prepared statement is then deallocated.D is a flipped CE is like C but works on  containers and returns unit.F is a flipped E.G lets you lift actions from LibPQ- that require a connection into your monad.5To define an instance, you can minimally define only ?, C, E and G,. Monad transformers get a default instance.Hsqueal-postgresqlAn  (https://bentnib.org/paramnotions-jfp.pdfAtkey indexed monad is a   /https://ncatlab.org/nlab/show/enriched+categoryenriched category-. An indexed monad transformer transforms a  into an indexed monad. And, HA is a class for indexed monad transformers that support running s using O7 and embedding a computation in a larger schema using N.Isqueal-postgresqlindexed analog of Jsqueal-postgresqlindexed analog of Ksqueal-postgresqlindexed analog of Lsqueal-postgresqlindexed analog of flipped Msqueal-postgresqlindexed analog of Nsqueal-postgresql.Safely embed a computation in a larger schema.Osqueal-postgresqlRun a  with $, we expect that libpq obeys the law Sdefine statement1 & pqThen (define statement2) = define (statement1 >>> statement2)Psqueal-postgresqlKWe keep track of the schema via an Atkey indexed state monad transformer, P.Ssqueal-postgresql.Makes a new connection to the database server.bThis function opens a new database connection using the parameters taken from the string conninfo.The passed string can be empty to use all default parameters, or it can contain one or more parameter settings separated by whitespace. Each parameter setting is in the form keyword = value. Spaces around the equal sign are optional. To write an empty value or a value containing spaces, surround it with single quotes, e.g., keyword = 'a value'. Single quotes and backslashes within the value must be escaped with a backslash, i.e., ' and .ETo specify the schema you wish to connect with, use type application.:set -XDataKinds:set -XPolyKinds:set -XTypeOperatorsHtype Schema = '["tab" ::: '[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint2]]:set -XTypeApplications:set -XOverloadedStringsEconn <- connectdb @Schema "host=localhost port=5432 dbname=exampledb"^Note that, for now, squeal doesn't offer any protection from connecting with the wrong schema!Tsqueal-postgresql$Closes the connection to the server.Usqueal-postgresqlDo S and T before and after a computation.Vsqueal-postgresqlSafely V to a smaller schema.Wsqueal-postgresqlRun a P and keep the result and the  Connection.Xsqueal-postgresql Execute a P% and discard the result but keep the  Connection.Ysqueal-postgresql Evaluate a P and discard the  Connection but keep the result.Zsqueal-postgresqlHelper function in defining  instance for P.[squeal-postgresql5Get a row corresponding to a given row number from a <, throwing an exception if the row number is out of bounds.\squeal-postgresql:Intended to be used for unfolding in streaming libraries, \8 takes a total number of rows (which can be found with ` ) and a 2 and given a row number if it's too large returns >, otherwise returning the row along with the next row number.]squeal-postgresqlGet all rows from a .^squeal-postgresql%Get the first row if possible from a ._squeal-postgresqlLifts actions on results from LibPQ.`squeal-postgresql8Returns the number of rows (tuples) in the query result.asqueal-postgresql)Returns the result status of the command.bsqueal-postgresqlUReturns the error message most recently generated by an operation on the connection.csqueal-postgresqlRReturns the error code most recently generated by an operation on the connection. Ehttps://www.postgresql.org/docs/current/static/errcodes-appendix.htmldsqueal-postgresqlCatch 6s.esqueal-postgresqlHandle 6s.?squeal-postgresqlV, ^ or `Asqueal-postgresql and friendsBsqueal-postgresql and friendsCsqueal-postgresqlV, ^, or ` , and friendsDsqueal-postgresqlV, ^ or `Esqueal-postgresqlV, ^ or `Fsqueal-postgresqlV, ^ or `Ssqueal-postgresqlconninfo[squeal-postgresql row numbersqueal-postgresqlresult\squeal-postgresqltotal number of rowssqueal-postgresqlresultsqueal-postgresql row number]squeal-postgresqlresult^squeal-postgresqlresultdsqueal-postgresqlhandleresqueal-postgresqlhandler> 6897:;<=>?C@ABDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcde>STUVPQRWXYHIJKLMNO>?C@ABDEFG=Z`[]\^_ abc6897:;<dePooled connections(c) Eitan Chatav, 2017eitan@morphism.tech experimentalNone,-3;<=>?FQTV6K ~squeal-postgresqlA snapshot of the state of a  computation.squeal-postgresql schema% should be a drop-in replacement for P  schema schema.4Typical use case would be to create your pool using < and run anything that requires the pool connection with it.Here's a simplified example: #type Schema = '[ "tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint2])] someQuery :: Manipulation Schema '[ 'NotNull 'PGint2] '[] someQuery = insertRow #tab (Set (param @1) `As` #col :* Nil) OnConflictDoNothing (Returning Nil) insertOne :: (MonadBaseControl IO m, MonadPQ Schema m) => m () insertOne = void $ manipulateParams someQuery . Only $ (1 :: Int16) insertOneInPool :: ByteString -> IO () insertOneInPool connectionString = do pool <- createConnectionPool connectionString 1 0.5 10 liftIO $ runPoolPQ (insertOne) poolsqueal-postgresqlCreate a striped pool of connections. Although the garbage collector will destroy all idle connections when the pool is garbage collected it's recommended to manually Y when you're done with the pool so that the connections are freed up as soon as possible.squeal-postgresqlHelper function in defining  instance for .squeal-postgresql instance for .squeal-postgresql> instance for .squeal-postgresql instance for .squeal-postgresql instance for .squeal-postgresql instance for .squeal-postgresql instance for .squeal-postgresqlThe passed string can be empty to use all default parameters, or it can contain one or more parameter settings separated by whitespace. Each parameter setting is in the form keyword = value. Spaces around the equal sign are optional. To write an empty value or a value containing spaces, surround it with single quotes, e.g., keyword = 'a value'. Single quotes and backslashes within the value must be escaped with a backslash, i.e., ' and .squeal-postgresql[The number of stripes (distinct sub-pools) to maintain. The smallest acceptable value is 1.squeal-postgresqlAmount of time for which an unused connection is kept open. The smallest acceptable value is 0.5 seconds. The elapsed time before destroying a connection may be a little longer than requested, as the reaper thread wakes at 1-second intervals.squeal-postgresqlMaximum number of connections to keep open per stripe. The smallest acceptable value is 1. Requests for connections will block if this limit is reached on a single stripe, even if other stripes have idle connections available.~~ #Squeal transaction control language(c) Eitan Chatav, 2017eitan@morphism.tech experimentalNone,-<F]wsqueal-postgresqlThe D transaction property has no effect unless the transaction is also  and . When all three of these properties are selected for a transaction, the transaction may block when first acquiring its snapshot, after which it is able to run without the normal overhead of a j transaction and without any risk of contributing to or being canceled by a serialization failure. This 4 is well suited for long-running reports or backups.squeal-postgresqlBThe transaction access mode determines whether the transaction is  or . ' is the default. When a transaction is /, the following SQL commands are disallowed: INSERT, UPDATE, DELETE, and  COPY FROMB if the table they would write to is not a temporary table; all CREATE, ALTER, and DROP commands; COMMENT, GRANT, REVOKE, TRUNCATE; and EXPLAIN ANALYZE and EXECUTEZ if the command they would execute is among those listed. This is a high-level notion of * that does not prevent all writes to disk.squeal-postgresqlSThe SQL standard defines four levels of transaction isolation. The most strict is h, which is defined by the standard in a paragraph which says that any concurrent execution of a set of ; transactions is guaranteed to produce the same effect as running them one at a time in some order. The other three levels are defined in terms of phenomena, resulting from interaction between concurrent transactions, which must not occur at each level. The phenomena which are prohibited at various levels are: Dirty readK: A transaction reads data written by a concurrent uncommitted transaction.Nonrepeatable read: A transaction re-reads data it has previously read and finds that data has been modified by another transaction (that committed since the initial read). Phantom read: A transaction re-executes a query returning a set of rows that satisfy a search condition and finds that the set of rows satisfying the condition has changed due to another recently-committed transaction.Serialization anomaly: The result of successfully committing a group of transactions is inconsistent with all possible orderings of running those transactions one at a time.In PostgreSQL, you can request any of the four standard transaction isolation levels, but internally only three distinct isolation levels are implemented, i.e. PostgreSQL's  mode behaves like . This is because it is the only sensible way to map the standard isolation levels to PostgreSQL's multiversion concurrency control architecture.squeal-postgresqlDirty read is not possible. Nonrepeatable read is not possible. Phantom read is not possible. Serialization anomaly is not possible.squeal-postgresqlDirty read is not possible. Nonrepeatable read is not possible. Phantom read is not possible. Serialization anomaly is possible.squeal-postgresql{Dirty read is not possible. Nonrepeatable read is possible. Phantom read is possible. Serialization anomaly is possible.squeal-postgresql{Dirty read is not possible. Nonrepeatable read is possible. Phantom read is possible. Serialization anomaly is possible.squeal-postgresql>The available transaction characteristics are the transaction , the transaction  ( or  ), and the .squeal-postgresql#Run a schema invariant computation .squeal-postgresql#Run a schema invariant computation  in .squeal-postgresqlBEGIN a transaction.squeal-postgresqlCOMMIT a schema invariant transaction.squeal-postgresqlROLLBACK a schema invariant transaction.squeal-postgresql"Run a schema changing computation .squeal-postgresql"Run a schema changing computation  in  DefaultMode.squeal-postgresql with a  ,   and  .squeal-postgresql with a  ,   and  @. This mode is well suited for long-running reports or backups.squeal-postgresql Render a .squeal-postgresql Render an .squeal-postgresql Render an .squeal-postgresql Render a .squeal-postgresqlrun inside a transactionsqueal-postgresqlrun inside a transaction&Squeel export module(c) Eitan Chatav, 2017eitan@morphism.tech experimentalNonez/N $%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnoqprstuvwxyz{|}~      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~      !"#$%&'()*+,-GHIJKLMNQPORSTUVWXYZ[\]^_`aijklmnopqrstuvwxyz{|}~6897:;<=>?C@ABDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcde Squeal migrations(c) Eitan Chatav, 2017eitan@morphism.tech experimentalNone &',-<FST]ci squeal-postgresqlThe l for a Squeal migration.squeal-postgresqlA $ should contain an inverse pair of  and  instructions and a unique .squeal-postgresqlThe  of a . Each  in a  should be unique.squeal-postgresqlThe  instruction of a .squeal-postgresqlThe  instruction of a .squeal-postgresqlRun s by creating the @ if it does not exist and then in a transaction, for each each  query to see if the ( is executed. If not, then execute the  and insert its row in the .squeal-postgresqlRewind s by creating the @ if it does not exist and then in a transaction, for each each  query to see if the ) is executed. If it is, then rewind the  and delete its row in the .squeal-postgresql Creates a  if it does not already exist.squeal-postgresql Inserts a  into the squeal-postgresql Deletes a  from the squeal-postgresql Selects a  from the /, returning the time at which it was executed.squeal-postgresqlmigrations to runsqueal-postgresqlmigrations to rewind  '()'(*'+,'-./01/02/0345645745845945:45;45<45=45>45?45@45A45B4CDEFGEFHIJKLMNOPQRSTUVWXYZ[\]^__`aabccdeefghhijklmnopqrstuvwxyz{|}~      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{ |}~!                                                          ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N OPQRSTUVWXYZ[\]^_`abcdefghhijklmnopqrstuvwxyz{|}~                                                '''''"''+// '45'45'45''''''''45   '  0squeal-postgresql-0.4.0.0-GuxxUOwtUmZB6qL3MLEXvbSqueal.PostgreSQL.SchemaSqueal.PostgreSQL.DefinitionSqueal.PostgreSQL.ExpressionSqueal.PostgreSQL.PQSqueal.PostgreSQL.PoolSqueal.PostgreSQL.RenderSqueal.PostgreSQL.QuerySqueal.PostgreSQL.ManipulationSqueal.PostgreSQL.BinarySqueal.PostgreSQL.TransactionSqueal.PostgreSQL.MigrationalterTableRename renameColumn alterTable alterColumn dropTable dropColumn createTable addColumn FromClause Data.Listelem ExpressiongroupTableExpressionSqueal.PostgreSQL.Manipulations ManipulationmanipulateParams queryParamstraversePreparedselect insertRowupdate Data.Maybe fromMaybeControl.Monad.State.Class MonadStateSqueal.PostgreSQLbaseGHC.OverloadedLabelsIsLabel fromLabelControl.Category>>> Data.Function&+generics-sop-0.3.2.0-5JX38dNigUk7e65oSELmomGenerics.SOP.NP:*NilNP/postgresql-libpq-0.9.4.1-HmQUg7WTong1815HjPkViUDatabase.PostgreSQL.LibPQResult SingleTuple FatalError NonfatalError BadResponseCopyBothCopyInCopyOutTuplesOk CommandOk EmptyQuery ExecStatusRow"Database.PostgreSQL.LibPQ.Internal Connection,resource-pool-0.2.3.2-3Rr84yej0EZEpb7PEm3Z9a Data.PooldestroyAllResourcesPool RenderSQL renderSQL parenthesized<+>commaSeparated doubleQuotedsingleQuotedTextsingleQuotedUtf8renderCommaSeparatedrenderCommaSeparatedMaybe renderNat renderSymbolprintSQL AlignedListDone:>> PGJsonType PGJsonKeyTuplePGNullPGRowPGLabelsPG Enumerated getEnumerated Composite getCompositeJsonbgetJsonbJsongetJsonPGPGlabel IsPGlabellabel SchemaType SchemumTypeTableViewTypedefLengthDropIfConstraintsInvolveRenameAlterDropCreateJoin NullifyFrom NullifyRow NullifyType NotAllNull AllNotNull SamePGTypePGTypeOf PGTextArray PGArrayOfPGArray PGIntegral PGFloatingPGNumInElem IsQualified!HasAllHas HasUnique AliasableasAliasedAsAlias GroupedByGrouping UngroupedGrouped TableToRowTableToColumnsFromTypeRowType TableTypeUniquelyTableConstraintsTableConstraintCheckUnique PrimaryKey ForeignKey ColumnsType ColumnTypeColumnConstraintDefNoDef::::=> NullityTypeNullNotNullHasOidoidPGTypePGboolPGint2PGint4PGint8 PGnumericPGfloat4PGfloat8PGchar PGvarcharPGtextPGbytea PGtimestamp PGtimestamptzPGdatePGtimePGtimetz PGintervalPGuuidPGinetPGjsonPGjsonb PGvararray PGfixarrayPGenum PGcomposite UnsafePGType renderAliasrenderAliasString renderAliasesrenderAliasedAs renderLabel renderLabelssingle$fHasOidPGjsonb$fHasOidPGjson$fHasOidPGinet$fHasOidPGuuid$fHasOidPGinterval$fHasOidPGtimetz$fHasOidPGtime$fHasOidPGdate$fHasOidPGtimestamptz$fHasOidPGtimestamp$fHasOidPGbytea$fHasOidPGtext$fHasOidPGvarchar$fHasOidPGchar$fHasOidPGfloat8$fHasOidPGfloat4$fHasOidPGnumeric$fHasOidPGint8$fHasOidPGint4$fHasOidPGint2$fHasOidPGbool$fGroupedBy[]tablecolumn:$fGroupedBy[]tablecolumn:0$fRenderSQLAlias$fIsLabelaliasNP$fIsLabelalias1Alias$fIsLabelalias0Aliased$fAliasablealiasexpressionNP!$fAliasablealiasexpressionAliased$fHaskindalias:field$fHaskindalias:field0$fHasAllk:fields:$fHasAllkind[]fields[]$fIsQualifiedtablecolumn(,)$fSamePGType(,)(,)$fIsPGlabellabelNP$fIsPGlabellabelPGlabel$fCategorykAlignedList $fEqAlias$fGenericAlias $fOrdAlias $fShowAlias $fNFDataAlias$fEqJson $fOrdJson $fShowJson $fReadJson $fGenericJson $fEqJsonb $fOrdJsonb $fShowJsonb $fReadJsonb$fGenericJsonb $fEqComposite$fOrdComposite$fShowComposite$fReadComposite$fGenericComposite$fEqEnumerated$fOrdEnumerated$fShowEnumerated$fReadEnumerated$fGenericEnumerated $fOrdAliased $fEqAliased $fShowAliasedPGTypedpgtypeTypeExpressionUnsafeTypeExpressionrenderTypeExpressionPGAvgavg avgDistinct Condition HasParameter parameterUnsafeExpressionrenderExpressionparamnull_notNullcoalescefromNullisNull isNotNull matchNullnullIfarrayindexrowfieldgreatestleastunsafeBinaryOp unsafeUnaryOpunsafeFunctionunsafeVariadicFunctionatan2_castquot_rem_truncround_ceiling_truefalsenot_.&&.||caseWhenThenElse ifThenElse.==./=.>=.<.<=.> currentDate currentTimecurrentTimestamp localTimelocalTimestamplowerupper charLengthlike.->.->>.#>.#>>.@>.<@.?.?|.?&.-.#-.jsonbLitjsonLittoJsontoJsonb arrayToJson rowToJsonjsonBuildArrayjsonbBuildArrayjsonBuildObjectjsonbBuildObject jsonObject jsonbObject jsonZipObjectjsonbZipObjectjsonArrayLengthjsonbArrayLengthjsonExtractPathjsonbExtractPathjsonExtractPathAsTextjsonbExtractPathAsText jsonTypeof jsonbTypeofjsonStripNullsjsonbStripNullsjsonbSet jsonbInsert jsonbPrettyunsafeAggregateunsafeAggregateDistinctsum_ sumDistinctbitAndbitOrbitAndDistinct bitOrDistinctboolAndboolOrboolAndDistinctboolOrDistinct countStarcount countDistinctevery everyDistinctmax_min_ maxDistinct minDistincttypedef typetabletypeviewboolint2smallintint4intintegerint8bigintnumericfloat4realfloat8doublePrecisiontextchar charactervarcharcharacterVaryingbytea timestamptimestampWithTimeZonedatetimetimeWithTimeZoneintervaluuidinetjsonjsonbvararrayfixarray$fSemigroupExpression$fMonoidExpression$fSemigroupExpression0$fIsStringExpression$fFloatingExpression$fFractionalExpression$fNumExpression$fMonoidExpression0$fSemigroupExpression1$fIsPGlabellabelExpression$fIsQualifiedtablecolumnNP$fIsQualifiedtablecolumnAliased"$fIsQualifiedtablecolumnExpression$fIsLabelcolumnNP$fIsLabelcolumnAliased$fIsLabelcolumnExpression$fIsQualifiedtablecolumnNP0 $fIsQualifiedtablecolumnAliased0#$fIsQualifiedtablecolumnExpression0$fIsLabelcolumnNP0$fIsLabelcolumnAliased0$fIsLabelcolumnExpression0$fRenderSQLExpression!$fPGAvgPGTypePGintervalPGinterval$fPGAvgPGTypePGfloat8PGfloat8$fPGAvgPGTypePGfloat4PGfloat8$fPGAvgPGTypePGnumericPGnumeric$fPGAvgPGTypePGint8PGnumeric$fPGAvgPGTypePGint4PGnumeric$fPGAvgPGTypePGint2PGnumeric$fHasParameternschema:ty$fHasParameter1schema:ty1$fPGTypedschemanullity$fPGTypedschemanullity0$fPGTypedschemanullity1$fPGTypedschemanullity2$fPGTypedschemanullity3$fPGTypedschemanullity4$fPGTypedschemanullity5$fPGTypedschemanullity6$fPGTypedschemanullity7$fPGTypedschemanullity8$fPGTypedschemanullity9$fPGTypedschemanullity10$fPGTypedschemanullity11$fPGTypedschemanullity12$fPGTypedschemanullity13$fPGTypedschemanullity14$fPGTypedschemanullity15$fPGTypedschemanullity16$fPGTypedschemanullity17$fPGTypedschemanullity18$fPGTypedschemanullity19$fPGTypedschemanullity20$fGenericExpression$fShowExpression$fEqExpression$fOrdExpression$fNFDataExpression$fGenericTypeExpression$fShowTypeExpression$fEqTypeExpression$fOrdTypeExpression$fNFDataTypeExpressionWithwithCommonTableExpressionSortExpressionAscDesc AscNullsFirst AscNullsLastDescNullsFirst DescNullsLast HavingClauseNoHavingHaving GroupByClauseNoGroupsGroupByBy1By2UnsafeFromClauserenderFromClause fromClause whereClause groupByClause havingClause orderByClause limitClause offsetClauseQuery UnsafeQuery renderQueryunionunionAll intersect intersectAllexcept exceptAllselectDistinct selectStarselectDistinctStar selectDotStarselectDistinctDotStarvaluesvalues_renderTableExpressionfromwhere_groupByhavingorderBylimitoffsetjsonEach jsonbEachjsonEachAsTextjsonbEachAsTextjsonObjectKeysjsonbObjectKeysjsonPopulateRecordjsonbPopulateRecordjsonPopulateRecordSetjsonbPopulateRecordSet jsonToRecord jsonbToRecordjsonToRecordSetjsonbToRecordSettablesubqueryview crossJoin innerJoin leftOuterJoinrightOuterJoin fullOuterJoinrenderByrenderGroupByClauserenderHavingClauserenderSortExpressionin_rowIneqAllrowEqAlleqAnyrowEqAnyneqAll rowNeqAllneqAny rowNeqAnyallLtrowLtAllltAnyrowLtAnylteAll rowLteAlllteAny rowLteAnygtAllrowGtAllgtAnyrowGtAnygteAll rowGteAllgteAny rowGteAnyrenderCommonTableExpressionrenderCommonTableExpressions$fRenderSQLQuery$fIsQualifiedrelcolNP$fIsQualifiedrelcolBy$fIsLabelcolNP$fIsLabelcolBy$$fAliasablealiasstatementAlignedList.$fAliasablealiasstatementCommonTableExpression $fWithQuery$fGenericQuery $fShowQuery $fEqQuery $fOrdQuery $fNFDataQuery$fGenericFromClause$fShowFromClause$fEqFromClause$fOrdFromClause$fNFDataFromClause$fShowSortExpression$fOrdHavingClause$fEqHavingClause$fShowHavingClause$fOrdBy$fEqBy$fShowByConflictClauseOnConflictDoRaiseOnConflictDoNothingOnConflictDoUpdateReturningClause ReturningStar Returning ColumnValueSameDefaultSetUnsafeManipulationrenderManipulationqueryStatement insertRows insertRows_ insertRow_ insertQuery insertQuery_renderReturningClauserenderConflictClauseupdate_ deleteFrom deleteFrom_$fWithManipulation$fRenderSQLManipulation$fGenericManipulation$fShowManipulation$fEqManipulation$fOrdManipulation$fNFDataManipulationColumnTypeExpressionUnsafeColumnTypeExpressionrenderColumnTypeExpression AlterColumnUnsafeAlterColumnrenderAlterColumn AddColumn AlterTableUnsafeAlterTablerenderAlterTableOnUpdateClauseOnUpdateNoActionOnUpdateRestrictOnUpdateCascadeOnDeleteClauseOnDeleteNoActionOnDeleteRestrictOnDeleteCascade ForeignKeyedTableConstraintExpressionUnsafeTableConstraintExpressionrenderTableConstraintExpression DefinitionUnsafeDefinitionrenderDefinitioncreateTableIfNotExistscheckunique primaryKey foreignKeyrenderOnDeleteClauserenderOnUpdateClause addConstraintdropConstraint setDefault dropDefault setNotNull dropNotNull alterType createViewdropViewcreateTypeEnumcreateTypeEnumFromcreateTypeCompositecreateTypeCompositeFromdropTypenullable notNullabledefault_serial2 smallserialserial4serialserial8 bigserial$fCategory[]Definition$fRenderSQLDefinition$fNFDataOnDeleteClause$fNFDataOnUpdateClause$fFieldTypedschema(,)$fAddColumn(,)$fAddColumn(,)0$fGenericDefinition$fShowDefinition$fEqDefinition$fOrdDefinition$fNFDataDefinition"$fGenericTableConstraintExpression$fShowTableConstraintExpression$fEqTableConstraintExpression$fOrdTableConstraintExpression!$fNFDataTableConstraintExpression$fGenericOnDeleteClause$fShowOnDeleteClause$fEqOnDeleteClause$fOrdOnDeleteClause$fGenericOnUpdateClause$fShowOnUpdateClause$fEqOnUpdateClause$fOrdOnUpdateClause$fGenericAlterTable$fShowAlterTable$fEqAlterTable$fOrdAlterTable$fNFDataAlterTable$fGenericAlterColumn$fShowAlterColumn$fEqAlterColumn$fOrdAlterColumn$fNFDataAlterColumn$fGenericColumnTypeExpression$fShowColumnTypeExpression$fEqColumnTypeExpression$fOrdColumnTypeExpression$fNFDataColumnTypeExpressionOnlyfromOnlyFromRowfromRow FromValue fromValueToParamstoParamsToParamtoParam$fToParamEnumeratedPGenum$fToParamJsonbPGjsonb$fToParamJsonPGjson$fToParamValuePGjsonb$fToParamValuePGjson$fToParamDiffTimePGinterval$fToParamUTCTimePGtimestamptz$fToParamLocalTimePGtimestamp$fToParam(,)PGtimetz$fToParamTimeOfDayPGtime$fToParamDayPGdate$fToParamByteStringPGbytea$fToParamByteStringPGbytea0$fToParam[]PGtext$fToParamTextPGtext$fToParamTextPGtext0$fToParamCharPGchar$fToParamNetAddrPGinet$fToParamUUIDPGuuid$fToParamScientificPGnumeric$fToParamDoublePGfloat8$fToParamFloatPGfloat4$fToParamWord64PGint8$fToParamInt64PGint8$fToParamWord32PGint4$fToParamInt32PGint4$fToParamWord16PGint2$fToParamInt16PGint2$fToParamBoolPGbool$fHasAliasedOid(,)$fToNullityParamMaybeNull$fToNullityParamxNotNull$fToField(,)(,)$fToParamCompositePGcomposite$fToArrayMaybeNull$fToArrayproductNotNull$fToArrayMaybeNull0$fToArrayVectorNotNull$fToArrayMaybeNull1$fToArrayxNotNull$fToParamxPGfixarray$fToParamxPGvararray$fToParamsxtys$fFromValuePGenumEnumerated$fFromValuePGjsonbJsonb$fFromValuePGjsonJson$fFromValuePGjsonbValue$fFromValuePGjsonValue$fFromValuePGintervalDiffTime$fFromValuePGtimestamptzUTCTime$fFromValuePGtimestampLocalTime$fFromValuePGtimetz(,)$fFromValuePGtimeTimeOfDay$fFromValuePGdateDay$fFromValuePGbyteaByteString$fFromValuePGbyteaByteString0$fFromValuePGtext[]$fFromValuePGtextText$fFromValuePGtextText0$fFromValuePGcharChar$fFromValuePGinetNetAddr$fFromValuePGuuidUUID$fFromValuePGnumericScientific$fFromValuePGfloat8Double$fFromValuePGfloat4Float$fFromValuePGint8Int64$fFromValuePGint4Int32$fFromValuePGint2Int16$fFromValuePGboolBool$fFromField(,)(,)$fFromField(,)(,)0$fFromArrayNullMaybe$fFromArrayNotNullproduct$fFromArrayNullMaybe0$fFromArrayNotNullVector$fFromArrayNullMaybe1$fFromArrayNotNully$fFromValuePGfixarrayy$fFromValuePGvararrayy$fFromRowresulty$fFromValuePGcompositeComposite$fHasDatatypeInfoOnly $fGenericOnly $fFunctorOnly$fFoldableOnly$fTraversableOnly$fEqOnly $fOrdOnly $fReadOnly $fShowOnly$fGenericOnly0SquealException PQExceptionResultExceptionParseException sqlExecStatus sqlStateCodesqlErrorMessagePQRunMonadPQ manipulaterunQueryParamsrunQuery forPreparedtraversePrepared_ forPrepared_liftPQIndexedMonadTransPQpqAppqJoinpqBindpqThen pqAndThenpqEmbeddefinePQunPQ connectdbfinishwithConnectionlowerConnectionrunPQexecPQevalPQ pqliftWithgetRownextRowgetRowsfirstRow liftResultntuples resultStatusresultErrorMessageresultErrorCode catchSqueal handleSqueal$fMonadBaseControlbPQ$fMonadBasebPQ $fMMonadPQ$fMonadTransPQ$fMFunctorTYPEPQ $fFunctorPQ $fMonadPQ$fApplicativePQ$fMonadPQschemaContT$fMonadPQschemaRWST$fMonadPQschemaRWST0$fMonadPQschemaExceptT$fMonadPQschemaMaybeT$fMonadPQschemaWriterT$fMonadPQschemaWriterT0$fMonadPQschemaStateT$fMonadPQschemaStateT0$fMonadPQschemaReaderT$fMonadPQschemaIdentityT$fExceptionSquealException$fMonadPQschemaPQ$fIndexedMonadTransPQPQ$fEqSquealException$fShowSquealException PoolPQRunPoolPQ runPoolPQcreateConnectionPoolpoolpqliftWith$fMonadBaseControlbPoolPQ$fMonadPQschemaPoolPQ$fMonadBasebPoolPQ$fMonadTransPoolPQ $fMonadPoolPQ$fApplicativePoolPQ$fFunctorPoolPQDeferrableMode Deferrable NotDeferrable AccessMode ReadWriteReadOnlyIsolationLevel SerializableRepeatableRead ReadCommittedReadUncommittedTransactionModeisolationLevel accessModedeferrableModetransactionallytransactionally_begincommitrollbacktransactionallySchematransactionallySchema_ defaultModelongRunningModerenderIsolationLevelrenderAccessModerenderDeferrableMode$fShowIsolationLevel$fEqIsolationLevel$fShowAccessMode$fEqAccessMode$fShowDeferrableMode$fEqDeferrableMode$fShowTransactionMode$fEqTransactionModeMigrationsTable Migrationnameupdown migrateUp migrateDowncreateMigrationsinsertMigrationdeleteMigrationselectMigrationbytestring-0.10.8.2Data.ByteString.Internal ByteString text-1.2.3.0Data.Text.InternalTextGHC.BaseMaybeNothingghc-prim GHC.TypesNatSymbolConstructorNamesOfConstructorNameOfConstructorsOfConstraintInvolves++ Placeholder ColumnsToRowJustmaybe GHC.Classesmin GHC.TypeNats+CategoryrenderCreationTypeGenerics.SOP.UniverseGenericHasDatatypeInfo FromField GHC.Exception Exception execParamsData.Traversabletraverseprepare Traversable execPrepared Data.FoldableFoldableFunctorMonad<*>join=<<>> Control.Monad<=<exec,monad-control-1.0.2.3-IPrpWAjYxOt1opqDMU7GN2Control.Monad.Trans.ControlMonadBaseControl0transformers-base-0.4.5.2-9baFU7phiuIKF7KTSSI06QControl.Monad.Base MonadBasetransformers-0.5.5.0Control.Monad.Trans.Class MonadTrans ApplicativerenderTransactionMode