Database Reference
In-Depth Information
• Create triggers in many languages to make related changes to other
tables, log the actions, or forbid the action to happen if it does not meet
certain criteria.
• Define new data types and operators in the database.
• Use the geography types defined in the PostGIS package.
• Add your own index access methods for either existing or new data types,
making some queries much more efficient.
What sort of things can you do with these features? There are limitless possibilities,
such as the ones listed as follows:
• Write data extractor functions to get just the interesting parts from struc-
tured data, such as XML or JSON, without needing to ship the whole,
possibly huge, document to the client application.
• Process events asynchronously, like sending mail without slowing down
the main application. You could create a mail queue for changes to user
info, populated by a trigger. A separate mail-sending process can con-
sume this data whenever it's notified by an application process.
The rest of this chapter is presented as a series of descriptions of common data
management tasks showing how they can be solved in a robust and elegant way via
server programming.
The samples in this chapter are all tested to work, but they come with minimal com-
mentary. They are here just to show you various things server programming can ac-
complish. The techniques described will be explained thoroughly in later chapters.
Why program in the server?
Developers program their code in a number of different languages and it could be
designed to run just about anywhere. When writing an application, some people fol-
low the philosophy that as much of the logic as possible for the application, should
be pushed to the client. We see this in the explosion of applications leveraging
JavaScript inside browsers. Others like to push the logic into the middle tier with an
application server handling the business rules. These are all valid ways to design an
application, so why would you want to program in the database server?
Search WWH ::




Custom Search