diff --git a/doc/s-sql.html b/doc/s-sql.html index ae6a9f9..f41c060 100644 --- a/doc/s-sql.html +++ b/doc/s-sql.html @@ -1,7 +1,7 @@ - + S-SQL Reference Manual @@ -449,12 +449,12 @@

Table of Contents

is all that is needed to produce the final SQL query.

-
-

Interface

+
+

Interface

-
-

macro sql (form)

+
+

macro sql (form)

→ string @@ -485,8 +485,8 @@

-

function sql-compile (form)

+
+

function sql-compile (form)

→ string @@ -518,8 +518,8 @@

-

function sql-template (form)

+
+

function sql-template (form)

In cases where you do need to build the query at run time, yet you do not @@ -532,8 +532,8 @@

-

function enable-s-sql-syntax (&optional (char #\Q))

+
+

function enable-s-sql-syntax (&optional (char #\Q))

Modifies the current readtable to add a #Q syntax that is read as (sql …). @@ -541,8 +541,8 @@

-

function sql-escape-string (string)

+
+

function sql-escape-string (string)

→ string @@ -561,8 +561,8 @@

-

method sql-escape (value)

+
+

method sql-escape (value)

→ string @@ -588,16 +588,16 @@

-

variable downcase-symbols

+
+

variable downcase-symbols

When converting symbols to strings, whether to downcase the symbols is set here. The default is to downcase symbols.

-
-

variable standard-sql-strings

+
+

variable standard-sql-strings

Used to configure whether S-SQL will use standard SQL strings (just replace #\' with ''), or backslash-style escaping. Setting this to NIL is always safe, but when the server is configured to allow standard strings (compile-time parameter 'standard_conforming_strings' is 'on', which will become the default in future versions of PostgreSQL), the noise in queries can be reduced by setting this to T. @@ -605,8 +605,8 @@

-

variable postgres-reserved-words hashtable

+
+

variable postgres-reserved-words hashtable

A set of all Postgresql's reserved words, for automatic escaping. Probably not a good idea to use these words as identifiers anyway. @@ -625,8 +625,8 @@

-

variable escape-sql-names-p

+
+

variable escape-sql-names-p

Determines whether double quotes are added around column, table, and ** function names in @@ -653,8 +653,8 @@

-

function sql-type-name (type)

+
+

function sql-type-name (type)

→ string @@ -666,8 +666,8 @@

-

function to-sql-name (name &optional (escape-p escape-sql-names-p)(ignore-reserved-words nil)

+
+

function to-sql-name (name &optional (escape-p escape-sql-names-p)(ignore-reserved-words nil)

→ string @@ -683,8 +683,8 @@

-

function from-sql-name (string)

+
+

function from-sql-name (string)

→ keyword @@ -697,8 +697,8 @@

-

macro register-sql-operators (arity &rest names)

+
+

macro register-sql-operators (arity &rest names)

Define simple SQL operators. Arity is one of :unary (like 'not'), :unary-postfix @@ -712,8 +712,8 @@

-

SQL Types

+
+

SQL Types

S-SQL knows the SQL equivalents to a number of Lisp types, and defines some @@ -833,8 +833,8 @@

-

type db-null

+
+

type db-null

This is a type of which only the keyword :null is a member. It is used to represent @@ -844,8 +844,8 @@

-

SQL Syntax

+
+

SQL Syntax

An S-SQL form is converted to a query through the following rules: @@ -866,8 +866,8 @@

-

sql-op :select (&rest args)

+
+

sql-op :select (&rest args)

Creates a select query. The arguments are split on the keywords found among @@ -914,12 +914,12 @@

-

Joins

+
+

Joins

-
-

Cross Join

+
+

Cross Join

From the postgresql documentation: "For every possible combination of rows from T1 and T2 (i.e., a Cartesian product), the joined table will contain a row consisting of all columns in T1 followed by all columns in T2. If the tables have N and M rows respectively, the joined table will have N * M rows." @@ -931,8 +931,8 @@

Cross Join<

-
-

Inner Join

+
+

Inner Join

An inner join looks at two tables and creates a new result consisting of the selected elements in the rows from the two tables that match the specified conditions. You can simplistically think of it as the intersection of the two sets. In reality, it is creating a new set consisting of certain elements of the intersecting rows. An inner join is the default and need not be specified. @@ -1001,8 +1001,8 @@

Inner Join<

-
-

Outer Join

+
+

Outer Join

An outer join not only generates an inner join, it also joins the rows from one table that matches the conditions and adds null values for the joined columns from the second table (which obviously did not match the condition.) Under Postgresql, a "left join", "right join" or "full join" all imply an outer join. @@ -1014,8 +1014,8 @@

Outer Join<

-
-

Left Join

+
+

Left Join

Example: Here we assume two tables. A countries table and a many-to-many linking table named countries-topics. (There is an implicit third table named topics.) We are looking for records from the countries table which do not have a match in the countries-topics table. In other words, where do we have a note, but not matched it to a topic? @@ -1050,16 +1050,16 @@

Left Join

-
-

Defined Operators

+
+

Defined Operators

The following operators are defined:

-
-

sql-op :+, :*, :%, :&, :|, :||, :and, :or, :=, :/, :!=, :<, :>, :<=, :>=, :^, :union, :union-all, :intersect, :intersect-all, :except, :except-all (&rest args)

+
+

sql-op :+, :*, :%, :&, :|, :||, :and, :or, :=, :/, :!=, :<, :>, :<=, :>=, :^, :union, :union-all, :intersect, :intersect-all, :except, :except-all (&rest args)

These are expanded as infix operators. When meaningful, they allow more than @@ -1075,8 +1075,8 @@

-

sql-op :or

+
+

sql-op :or

(query (:select 'countries.name
@@ -1102,8 +1102,8 @@ 

sql-op :or<

-
-

sql-op :intersect

+
+

sql-op :intersect

Intersect produces a result contain rows that appear on all the sub-selects. @@ -1120,8 +1120,8 @@

sql-op :int

-
-

sql-op :union, :union-all

+
+

sql-op :union, :union-all

The union operation generally eliminates what it thinks are duplicate rows. The union-all operation preserves duplicate rows. The examples below use the union-all operator, but the syntax would be the same with union. @@ -1156,8 +1156,8 @@

sql-op :uni

-
-

sql-op :except, :except-all

+
+

sql-op :except, :except-all

:except removes all matches. :except-all is slightly different. @@ -1179,8 +1179,8 @@

sql-op :exc

-
-

sql-op :~, :not (arg)

+
+

sql-op :~, :not (arg)

Unary operators for bitwise and logical negation. @@ -1196,8 +1196,8 @@

-

sql-op :any, :any*

+
+

sql-op :any, :any*

Any needs to be considered as a special case. Quoting Marijn Haverbeke here,"Postgres has both a function-call-style any and an infix any, and S-SQL's syntax doesn't allow them to be distinguished." As a result, postmodern has a regular :any sql-op and a :any* sql-op, which expand slightly differently. @@ -1305,8 +1305,8 @@

sql-op :any

-
-

sql-op :function (name (&rest arg-types) return-type stability body)

+
+

sql-op :function (name (&rest arg-types) return-type stability body)

Create a stored procedure. The argument and return types are interpreted as @@ -1321,8 +1321,8 @@

-

sql-op :~, :~*, :!~, :!~* (string pattern)

+
+

sql-op :~, :~*, :!~, :!~* (string pattern)

Regular expression matching operators. The exclamation mark means 'does not match', @@ -1368,8 +1368,8 @@

-

sql-op :like, :ilike (string pattern)

+
+

sql-op :like, :ilike (string pattern)

Simple SQL string matching operators (:ilike is case-insensitive). @@ -1382,8 +1382,8 @@

-

sql-op :@@

+
+

sql-op :@@

Fast Text Search match operator. @@ -1391,8 +1391,8 @@

-

sql-op :desc (column)

+
+

sql-op :desc (column)

Used to invert the meaning of an operator in an :order-by clause. @@ -1407,8 +1407,8 @@

-

sql-op :nulls-first, :nulls-last (column)

+
+

sql-op :nulls-first, :nulls-last (column)

Used to determine where :null values appear in an :order-by clause. @@ -1416,8 +1416,8 @@

-

sql-op :as (form name &rest fields)

+
+

sql-op :as (form name &rest fields)

Also known in some explanations as "alias". This assigns a name to a column or @@ -1472,8 +1472,8 @@

-

sql-op :cast (query)

+
+

sql-op :cast (query)

The CAST operator. Takes a query as an argument, and returns the result @@ -1502,8 +1502,8 @@

-

sql-op :type (query)

+
+

sql-op :type (query)

Is similar to cast but uses the postgresql :: formating. Unlike cast it will not @@ -1521,8 +1521,8 @@

-

sql-op :create-composite-type (type-name &rest args)

+
+

sql-op :create-composite-type (type-name &rest args)

Creates a composite type with a type-name and two or more columns. E.g. @@ -1533,8 +1533,8 @@

-

sql-op :exists (query)

+
+

sql-op :exists (query)

The EXISTS operator. Takes a query as an argument, and returns true or false @@ -1554,8 +1554,8 @@

-

sql-op :is-null (arg)

+
+

sql-op :is-null (arg)

Test whether a value is null. @@ -1566,8 +1566,8 @@

-

sql-op :not-null (arg)

+
+

sql-op :not-null (arg)

Test whether a value is not null. @@ -1578,8 +1578,8 @@

-

sql-op :in (value set)

+
+

sql-op :in (value set)

Test whether a value is in a set of values. @@ -1599,8 +1599,8 @@

-

sql-op :not-in (value set)

+
+

sql-op :not-in (value set)

Inverse of the above. @@ -1608,8 +1608,8 @@

-

sql-op :set (&rest elements)

+
+

sql-op :set (&rest elements)

Denote a set of values. This operator has two interfaces. When @@ -1684,8 +1684,8 @@

-

sql-op :array (query)

+
+

sql-op :array (query)

This is used when calling a select query into an array. See array-notes.html @@ -1710,8 +1710,8 @@

-

sql-op :array[] (&rest args)

+
+

sql-op :array[] (&rest args)

This is the general operator for arrays. It also handles statements that include @@ -1732,8 +1732,8 @@

-

sql-op :[] (form start &optional end)

+
+

sql-op :[] (form start &optional end)

Dereference an array value. If end is provided, extract a slice of the array. @@ -1749,8 +1749,8 @@

-

sql-op :extract (unit form)

+
+

sql-op :extract (unit form)

Extract a field from a date/time value. For example, (:extract :month (:now)). @@ -1769,8 +1769,8 @@

-

sql-op :case (&rest clauses)

+
+

sql-op :case (&rest clauses)

A conditional expression. Clauses should take the form (test value). If @@ -1785,8 +1785,8 @@

-

sql-op :between (n start end)

+
+

sql-op :between (n start end)

Test whether a value lies between two other values. @@ -1800,8 +1800,8 @@

-

sql-op :between-symmetric (n start end)

+
+

sql-op :between-symmetric (n start end)

Works like :between, except that the start value is not required to be @@ -1810,8 +1810,8 @@

-

sql-op :dot (&rest names)

+
+

sql-op :dot (&rest names)

Can be used to combine multiple names into a name of the form A.B to @@ -1821,8 +1821,8 @@

-

sql-op :type (form type)

+
+

sql-op :type (form type)

Add a type declaration to a value, as in in "4.3::real". The second @@ -1835,8 +1835,8 @@

-

sql-op :raw (string)

+
+

sql-op :raw (string)

Insert a string as-is into the query. This can be useful for doing things @@ -1853,8 +1853,8 @@

-

sql-op :fetch (form amount &optional offset)

+
+

sql-op :fetch (form amount &optional offset)

Fetch is a more efficient way to do pagination instead of using limit and @@ -1881,8 +1881,8 @@

-

sql-op :limit (query amount &optional offset)

+
+

sql-op :limit (query amount &optional offset)

In S-SQL limit is not part of the select operator, but an extra @@ -1898,8 +1898,8 @@

-

sql-op :order-by (query &rest exprs)

+
+

sql-op :order-by (query &rest exprs)

Order the results of a query by the given expressions. See :desc for @@ -1916,8 +1916,8 @@

-

sql-op :values

+
+

sql-op :values

Values computes a row value or set of row values for use in a specific @@ -1952,8 +1952,8 @@

-

sql-op :empty-set

+
+

sql-op :empty-set

This is a fudge. It returns a string "()" where something like '() @@ -1969,8 +1969,8 @@

-

sql-op :group-by

+
+

sql-op :group-by

https://www.postgresql.org/docs/current/static/queries-table-expressions.html#QUERIES-GROUPING-SETS @@ -1995,8 +1995,8 @@

-

sql-op :grouping-sets

+
+

sql-op :grouping-sets

https://www.postgresql.org/docs/current/static/queries-table-expressions.html#QUERIES-GROUPING-SETS @@ -2016,20 +2016,20 @@

-

Time, Date and Interval Operators

+
+

Time, Date and Interval Operators

-
-

sql-op :interval (arg)

+
+

sql-op :interval (arg)

Creates an interval data type, generally represented in postmodern as an alist

-
-

sql-op :current-date ()

+
+

sql-op :current-date ()

(query (:select (:current-date)) :single)
@@ -2037,33 +2037,33 @@ 

-

sql-op :current-time ()

+
+

sql-op :current-time ()

-
-

sql-op :current-timestamp ()

+
+

sql-op :current-timestamp ()

-
-

sql-op :timestamp (arg)

+
+

sql-op :timestamp (arg)

-
-

sql-op :age (&rest args)

+
+

sql-op :age (&rest args)

-
-

sql-op :date (arg)

+
+

sql-op :date (arg)

-
-

sql-op :make-interval (&rest args)

+
+

sql-op :make-interval (&rest args)

Takes lists of (time-unit value) and returns a timestamp type. Example: @@ -2076,8 +2076,8 @@

-

sql-op :make-timestamp (&rest args)

+
+

sql-op :make-timestamp (&rest args)

Takes lists of (time-unit value) and returns a timestamptz type. Example: @@ -2091,8 +2091,8 @@

-

sql-op :make-timestamptz (&rest args)

+
+

sql-op :make-timestamptz (&rest args)

Takes lists of (time-unit value) and returns a timestamptz type. Example: @@ -2108,12 +2108,12 @@

-

Aggregation Operators

+
+

Aggregation Operators

-
-

sql-op :count (&rest args)

+
+

sql-op :count (&rest args)

Count returns the number of rows for which the expression is not null. @@ -2166,8 +2166,8 @@

-

sql-op :avg (&rest rest args)

+
+

sql-op :avg (&rest rest args)

Avg calculates the average value of a list of values. Note that if the @@ -2182,8 +2182,8 @@

-

sql-op :sum (&rest rest args)

+
+

sql-op :sum (&rest rest args)

Sum calculates the total of a list of values. Note that if the keyword filter @@ -2200,8 +2200,8 @@

-

sql-op ::max (&rest args)

+
+

sql-op ::max (&rest args)

max returns the maximum value of a set of values. Note that if the filter @@ -2218,8 +2218,8 @@

-

sql-op ::min (&rest args)

+
+

sql-op ::min (&rest args)

min returns the minimum value of a set of values. Note that if the filter @@ -2236,8 +2236,8 @@

-

sql-op ::every (&rest args)

+
+

sql-op ::every (&rest args)

Every returns true if all input values are true, otherwise false. Note @@ -2255,8 +2255,8 @@

-

sql-op :percentile-cont (&rest args)

+
+

sql-op :percentile-cont (&rest args)

Requires Postgresql 9.4 or higher. Percentile-cont returns a value @@ -2280,8 +2280,8 @@

-

sql-op :percentile-dist (&rest args)

+
+

sql-op :percentile-dist (&rest args)

Requires Postgresql 9.4 or higher. There are two required keyword parameters @@ -2306,8 +2306,8 @@

-

sql-op :corr (y x)

+
+

sql-op :corr (y x)

The corr function returns the correlation coefficient between a set of @@ -2321,8 +2321,8 @@

-

sql-op :covar-pop (y x)

+
+

sql-op :covar-pop (y x)

The covar-pop function returns the population covariance between a set of @@ -2336,8 +2336,8 @@

-

sql-op :covar-samp (y x)

+
+

sql-op :covar-samp (y x)

(query (:select (:covar-samp 'height 'weight)
@@ -2351,8 +2351,8 @@ 

-

sql-op :string-agg (&rest args)

+
+

sql-op :string-agg (&rest args)

String-agg allows you to concatenate strings using different types of @@ -2377,8 +2377,8 @@

-

sql-op :array-agg (&rest args)

+
+

sql-op :array-agg (&rest args)

Array-agg returns a list of values concatenated into an arrays. @@ -2408,8 +2408,8 @@

-

sql-op :mode (&rest args)

+
+

sql-op :mode (&rest args)

Mode is used to find the most frequent input value in a group. @@ -2424,8 +2424,8 @@

-

sql-op :regr_avgx (y x)

+
+

sql-op :regr_avgx (y x)

The regr_avgx function returns the average of the independent variable @@ -2439,8 +2439,8 @@

-

sql-op :regr_avgy (y x)

+
+

sql-op :regr_avgy (y x)

The regr_avgy function returns the average of the dependent variable @@ -2456,8 +2456,8 @@

-

sql-op :regr_count (y x)

+
+

sql-op :regr_count (y x)

The regr_count function returns the number of input rows in which both @@ -2471,8 +2471,8 @@

-

sql-op :regr_intercept (y x)

+
+

sql-op :regr_intercept (y x)

The regr_intercept function returns the y-intercept of the least-squares-fit @@ -2486,8 +2486,8 @@

-

sql-op :regr_r2 (y x)

+
+

sql-op :regr_r2 (y x)

The regr_r2 function returns the square of the correlation coefficient. Example: @@ -2500,8 +2500,8 @@

-

sql-op :regr_slope (y x)

+
+

sql-op :regr_slope (y x)

The regr_slope function returns the slope of the least-squares-fit linear @@ -2515,8 +2515,8 @@

-

sql-op :regr_sxx (y x)

+
+

sql-op :regr_sxx (y x)

The regr_sxx function returns the sum(X^2) - sum(X)^2/N (“sum of squares” of @@ -2530,8 +2530,8 @@

-

sql-op :regr_sxy (y x)

+
+

sql-op :regr_sxy (y x)

The regr_sxy function returns the sum(X*Y) - sum(X) * sum(Y)/N (“sum of products” @@ -2545,8 +2545,8 @@

-

sql-op :regr_syy (y x)

+
+

sql-op :regr_syy (y x)

The regr_syy function returns the sum(Y^2) - sum(Y)^2/N (“sum of squares” @@ -2560,8 +2560,8 @@

-

sql-op :stddev (&rest args)

+
+

sql-op :stddev (&rest args)

The stddev function returns the the sample standard deviation of the input @@ -2575,8 +2575,8 @@

-

sql-op :stddev-pop (&rest args)

+
+

sql-op :stddev-pop (&rest args)

The stddev-pop function returns the population standard deviation of the @@ -2590,8 +2590,8 @@

-

sql-op :stddev-samp (&rest args)

+
+

sql-op :stddev-samp (&rest args)

The stddev-samp function returns the sample standard deviation of the @@ -2605,8 +2605,8 @@

-

sql-op :variance (&rest args)

+
+

sql-op :variance (&rest args)

Variance is a historical alias for var_samp. The variance function returns @@ -2621,8 +2621,8 @@

-

sql-op :var-pop (&rest args)

+
+

sql-op :var-pop (&rest args)

The var-pop function returns the population variance of the input values @@ -2637,8 +2637,8 @@

-

sql-op :var-samp (&rest args)

+
+

sql-op :var-samp (&rest args)

The var-samp function returns the sample variance of the input values @@ -2656,8 +2656,8 @@

-

sql-op :over (form &rest args)

+
+

sql-op :over (form &rest args)

Over, partition-by and window are so-called window functions. A window @@ -2672,8 +2672,8 @@

-

sql-op :partition-by (&rest args)

+
+

sql-op :partition-by (&rest args)

Args is a list of one or more columns to partition by, optionally @@ -2701,8 +2701,8 @@

-

sql-op :window (form)

+
+

sql-op :window (form)

(query (:select (:over (:sum 'salary) 'w)
@@ -2714,8 +2714,8 @@ 

-

sql-op :with (&rest args)

+
+

sql-op :with (&rest args)

With provides a way to write auxillary statements for use in a larger query, @@ -2738,8 +2738,8 @@

-

sql-op :with-recursive (&rest args)

+
+

sql-op :with-recursive (&rest args)

Recursive modifier to a WITH statement, allowing the query to refer to its own output. @@ -2797,12 +2797,12 @@

-

Table Functions

+
+

Table Functions

-
-

sql-op :for-update (query &key of nowait)

+
+

sql-op :for-update (query &key of nowait)

Locks the selected rows against concurrent updates. This will prevent the @@ -2821,8 +2821,8 @@

-

sql-op :for-share (query &key of nowait)

+
+

sql-op :for-share (query &key of nowait)

Similar to :for-update, except it acquires a shared lock on the table, @@ -2832,8 +2832,8 @@

-

sql-op :insert-into (table &rest rest)

+
+

sql-op :insert-into (table &rest rest)

Insert a row into a table. When the second argument is :set, the other @@ -2872,8 +2872,8 @@

-

sql-op :insert-rows-into (table &rest rest)

+
+

sql-op :insert-rows-into (table &rest rest)

Insert multiple rows into a table. Specify the columns first with the @@ -2898,8 +2898,8 @@

-

sql-op :update (table &rest rest)

+
+

sql-op :update (table &rest rest)

Update values in a table. After the table name there should follow the @@ -2913,8 +2913,8 @@

-

sql-op :delete-from (table &rest rest)

+
+

sql-op :delete-from (table &rest rest)

Delete rows from the named table. Can be given a :where argument followed @@ -2927,8 +2927,8 @@

-

sql-op :create-table (name (&rest columns) &rest options)

+
+

sql-op :create-table (name (&rest columns) &rest options)

-
-

sql-op :drop-table (name)

+
+

sql-op :drop-table (name)

Drops the named table. You may optionally pass :if-exists before the name @@ -3207,8 +3231,8 @@

-

sql-op :truncate (&rest args)

+
+

sql-op :truncate (&rest args)

Truncates one or more tables, deleting all the rows. Optional keyword arguments are @@ -3242,8 +3266,8 @@

-

sql-op :create-index (name &rest args)

+
+

sql-op :create-index (name &rest args)

Create an index on a table. After the name of the index the keyword :on should @@ -3262,8 +3286,8 @@

-

sql-op :create-unique-index (name &rest args)

+
+

sql-op :create-unique-index (name &rest args)

Works like :create-index, except that the index created is unique. @@ -3271,8 +3295,8 @@

-

sql-op :drop-index (name)

+
+

sql-op :drop-index (name)

Drop an index. Takes :if-exists and/or :cascade arguments like :drop-table. @@ -3290,8 +3314,8 @@

-

sql-op :create-sequence (name &key increment min-value max-value start cache cycle)

+
+

sql-op :create-sequence (name &key increment min-value max-value start cache cycle)

Create a sequence with the given name. The rest of the arguments control @@ -3300,8 +3324,8 @@

-

sql-op :alter-sequence (name)

+
+

sql-op :alter-sequence (name)

Alters a sequence. See Postgresql documentation for parameters. @@ -3341,8 +3365,8 @@

-

sql-op :drop-sequence (name)

+
+

sql-op :drop-sequence (name)

Drop a sequence. Takes :if-exists and/or :cascade arguments like :drop-table. @@ -3357,8 +3381,8 @@

-

sql-op :create-view (name query)

+
+

sql-op :create-view (name query)

Create a view from an S-SQL-style query. @@ -3366,8 +3390,8 @@

-

sql-op :drop-view (name)

+
+

sql-op :drop-view (name)

Drop a view. Takes optional :if-exists argument. @@ -3375,8 +3399,8 @@

-

sql-op :set-constraints (state &rest constraints)

+
+

sql-op :set-constraints (state &rest constraints)

Configure whether deferrable constraints should be checked when a statement @@ -3389,8 +3413,8 @@

-

sql-op :listen (channel)

+
+

sql-op :listen (channel)

Tell the server to listen for notification events on channel channel, @@ -3399,8 +3423,8 @@

-

sql-op :unlisten (channel)

+
+

sql-op :unlisten (channel)

Stop listening for events on channel. @@ -3408,8 +3432,8 @@

-

sql-op :notify (channel &optional payload)

+
+

sql-op :notify (channel &optional payload)

Signal a notification event on channel channel, a string. The optional @@ -3418,8 +3442,8 @@

-

sql-op :create-role (role &rest args)

+
+

sql-op :create-role (role &rest args)

Create a new role (user). Following the role name are optional keywords @@ -3496,8 +3520,8 @@

-

sql-op :create-database (name)

+
+

sql-op :create-database (name)

Create a new database with the given name. @@ -3505,8 +3529,8 @@

-

sql-op :drop-database (name)

+
+

sql-op :drop-database (name)

Drops the named database. You may optionally pass :if-exists before the @@ -3521,8 +3545,8 @@

-

sql-op :copy (table &rest args)

+
+

sql-op :copy (table &rest args)

Move data between Postgres tables and filesystem files. Table name is required @@ -3552,13 +3576,13 @@

-

Dynamic Queries, Composition and Parameterized Queries

+
+

Dynamic Queries, Composition and Parameterized Queries

-
-

Overview

+
+

Overview

The question gets asked how to build dynamic or composable queries in @@ -3568,8 +3592,8 @@

-

Programmer Built Queries

+
+

Programmer Built Queries

The question gets asked how to build dynamic or composable queries in @@ -3630,12 +3654,12 @@

-
  • Approach #1 Using symbols in variables
    +
  • Approach #1 Using symbols in variables
      -
    • Select Statements
      -
      +
    • Select Statements
      +

      Consider the following two toy examples where we determine the table and columns to be selected using symbols (either keyword or quoted) inside variables. @@ -3659,8 +3683,8 @@

      Update Statements
      -
      +
    • Update Statements
      +

      This works with update statements as well

      @@ -3673,8 +3697,8 @@

      Insert Statements
      -
      +
    • Insert Statements
      +

      This works with insert-into statements as well

      @@ -3695,8 +3719,8 @@

      Delete Statements
      -
      +
    • Delete Statements
      +

      This works with delete statements as well

      @@ -3709,8 +3733,8 @@

      -

      Approach #2 Use sql-compile

      +
      +

      Approach #2 Use sql-compile

      Sql-compile does a run-time compilation of an s-sql expression. In the @@ -3874,8 +3898,8 @@

      Approach #2

      -
      -

      Approach #3 Use :raw

      +
      +

      Approach #3 Use :raw

      To quote Marijn, the :raw keyword takes a string and inserts it straight @@ -3890,8 +3914,8 @@

      Approach #3

      -
      -

      Queries with User Input

      +
      +

      Queries with User Input

      In any of the above approaches to building queries you will need to diff --git a/doc/s-sql.org b/doc/s-sql.org index c78b55b..170746b 100644 --- a/doc/s-sql.org +++ b/doc/s-sql.org @@ -2179,20 +2179,41 @@ The meaning of args depends on action: - :add-column Adds column to table. args should be a column in the same form as for :create-table. +#+BEGIN_SRC lisp +(query (:alter-table "packages" :add-column 'system-data-p :type (or boolean db-null))) +#+END_SRC + +- :set-default + +Adds or changes a default value for a column +#+BEGIN_SRC lisp +(query (:alter-table 'countries :alter-column 'updated-at :set-default (:now))) +#+END_SRC - :drop-column Drops a column from the table. +#+BEGIN_SRC lisp +(query (:alter-table "test-uniq" :drop-column 'address)) +#+END_SRC - :add-constraint Adds a named constraint to the table. +#+BEGIN_SRC lisp +(query (:alter-table "test-uniq" :add-constraint silly-key :primary-key 'code 'title)) + +(query (:alter-table enemy :add-constraint enemy-age-check :check (:> 'age 21))) +#+END_SRC - :drop-constraint Drops constraint. First of args should name a constraint to be dropped; second, optional argument specifies behaviour regarding objects dependent on the constraint and it may equal :cascade or :restrict. +#+BEGIN_SRC lisp +(query (alter-table enemy :drop-constraint enemy-age-check)) +#+END_SRC - :add @@ -2207,12 +2228,8 @@ Adds the ability to rename a table. - :rename-column Adds the ability to rename a column of a table. - -Here is an example using the table defined above: -#+BEGIN_SRC lsip -(query (alter-table enemy :drop-constraint enemy-age-check)) - -(query (:alter-table enemy :add-constraint enemy-age-check :check (:> 'age 21))) +#+BEGIN_SRC lisp +(query (:alter-table "test-uniq" :rename-column 'address 'city)) #+END_SRC ** sql-op :drop-table (name) diff --git a/postmodern/package.lisp b/postmodern/package.lisp index 7f6694e..c6e5a14 100644 --- a/postmodern/package.lisp +++ b/postmodern/package.lisp @@ -100,6 +100,7 @@ #:sql-error #:from-sql-name #:to-sql-name + #:db-null ;; Condition type from cl-postgres #:database-error