Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The most important part of this is the definition of mytableid:

  • serial tells it isn't a real datatype.  It's just a signal to do this:
    • use an integer for storage
    • create a SEQUENCE called mytable_mytableid_seq
    • set the default value for the field as nextval('mytable_mytableid_seq')
    • set the sequence attribute of the field to match
    • associate the SEQUENCE with the TABLE (so it's dropped if the table is dropped)
  • PRIMARY KEY tells it to create a primary key constraint called mytable_pkey with mytableid as the only component

Here are the resulting attributes of mytableid inside pgAdmin:

Image Added

The helpful thing here is that the connection between the field and the sequence provides an more descriptive syntax for retrieving the recently assigned sequence (rather than remembering that it's "tablename_columnname_seq", which could change in the future):

...

  • The Owner Name contains the SQL Connection String.  In my example I hard coded it, but usually I use a global variable that's used for all tables.  The value is set once when the program begins.  Although Clarion doesn't currently support Unicode, it's recommended that you use the Unicode driver.  (If you're using UTF-8 encoding, then most of the western character set is the same as with ANSI.)  The curly braces can be omitted.  The server in this case is called closet (which is also its address), the default port for PostgreSQL is 5432, the database is called test, the user is usr, and the password is pwd:
        Driver={PostgreSQL UnicodeUNICODE};Server=closet;Port=5432;Database=test;Uid=usr;Pwd=pwd;

...