Before going much further, it is important to understand the difference between the external form of a value and the internal form.
The external form of a data type defines how the user enters a value and how a value is displayed to the user. For example, if you enter a numeric value, you might enter the characters 7218942. If you enter these characters from a client that uses an ASCII encoding, you have entered the character values 37, 32, 31, 38, 39, 34, and 32 (in hexadecimal notation). The external form of a data type is used to interact with the user.
The internal form of a data type defines how a value is represented inside the database. The preceding numeric value form might be translated from the string 7218942 into the four-byte integer value 00 6E 26 FE (again in hexadecimal notation). The internal form of a data type is used within the database.
Why have two forms? Most programming languages can deal with numeric values implicitly (that is, without requiring the programmer to implement simple arithmetic operations). For example, the C programming language defines a built-in data type named int. An int value can store integer (that is, whole) numbers within some range determined by the compiler. The C compiler knows how to add, subtract, multiply, and divide int values. A C programmer is not required to perform the bit manipulations himself; the compiler emits the code required to perform the arithmetic.
Most programmers share a common understanding of what it means to add two integer values. When you add two integer values, you expect the result to be the arithmetic sum of the values. Another way to state this is to say that the + operator, when applied to two integer operands, should return the arithmetic sum of the operands, most likely in the form of an integer.
What would you expect the result to be if you applied the + operator to two string values? If each string contained only a sequence of one or more digits, such as '1' + '34', you might expect the result to be the string '35'. What would happen if you tried adding '1' + 'red'? That's pretty hard to predict. Because it is difficult to come up with a good arithmetic definition of the + operator when applied to strings, many programming languages define + to mean concatenation when applied to string operands. So, the expression '1' + 'red' would evaluate to the string '1red'.
So, to summarize a bit, the external form of a numeric value is a string of numeric digits, sign characters, and a radix point. When you choose the internal form for a numeric value, you want to choose a representation that makes it easy to define and implement mathematical operations.
You've already seen the external and internal form of the TEXT data type. The external form of a TEXT value is a string of characters enclosed in single quotes (the quotes are not part of the value; they just mark the boundaries of the value). If you need to include single quotes in a TEXT value, the external form defines a set of rules for doing so. The internal form of a TEXT value is defined by the TEXT data type. The TEXT structure contains a length and an array of characters.
Part I: General PostgreSQL Use
Introduction to PostgreSQL and SQL
Working with Data in PostgreSQL
PostgreSQL SQL Syntax and Use
Part II: Programming with PostgreSQL
Introduction to PostgreSQL Programming
The PostgreSQL C APIlibpq
A Simpler C APIlibpgeasy
The New PostgreSQL C++ APIlibpqxx
Embedding SQL Commands in C Programsecpg
Using PostgreSQL from an ODBC Client Application
Using PostgreSQL from a Java Client Application
Using PostgreSQL with Perl
Using PostgreSQL with PHP
Using PostgreSQL with Tcl and Tcl/Tk
Using PostgreSQL with Python
Npgsql: The .NET Data Provider
Other Useful Programming Tools
Part III: PostgreSQL Administration
Introduction to PostgreSQL Administration
Internationalization and Localization
Replicating PostgreSQL Data with Slony