Postmodern Examples Table of Contents Delete
Note that you should get a warning that CREATE TABLE / PRIMARY KEY will create implicate index "country_pkey" for table "country".
With respect to types, in the above, we created slots with col-type of integer, string, numeric,float and double-float. That translated into integer, text, numeric, real and double-precision.
You may also notice that the col-type for sovereign was declared (or db-null string) and inhabitants was declared (or db-null numeric), which translated to having a DEFAULT NULL whereas the other slots were provided with a definition of NOT NULL.
If you use a type that postgresql does not understand, for example, defining a slot with a :col-type list, executing the definition will throw a syntax error that the type "list" does not exist. You may leave out the :col-type your-special-type-here from the slot definition and the table will be created without that slot. Using insert-dao on an instance of your class would insert all the data except the data that you did not provide a valid :col-type. Thus, if your class did have slots containing lists of items, you would need to handle those slots separately.
Assume you have defined a dao class named quantico. You can then create a table with various constraints, foreign keys etc. As an example:
The !foreign function takes the parameters: [target table][single or list of columns in the current class] optionally [single or list of columns in the target table] and then the key parameters :on-update and :on-delete.
The possible values for :on-update and :on-delete are: :restrict :set-null :set-default :cascade or :no-action
You can always create tables without a dao class as well. The example I used at the beginning of the page is:
Note the additional items passed here: id is declared as the primary key, name is declared as unique. Region-id is called out as a foreign key to the id field in the regions table. Foreign key constraints can be added to the actual column definition using the keyword :references.
One inconsistency here is that the :foreign-key looks first for the current table column, then the target table and target table column. The deftable version looks for the target table, then the current column then the target table column.
One interesting bit to notice. The name of the table works whether it is in double quotes or not. It cannot, however, be a symbol.
Postmodern examples >