Join Bill Weinman for an in-depth discussion in this video Understanding data types, part of PostgreSQL 9 with PHP Essential Training.
Postgres has a rich set of data types, and while you may never use most of them, it's a good idea to have an overview of what's available. Numeric types include three sizes of integers--2-byte, 4-byte, and 8-byte sizes-- decimal or numeric for fixed precision applications, like money, and note that while Postgres has a money type, this is depreciated so you should avoid using it. You should use decimal or numeric instead. Decimal and numeric are the same thing. It has real and double types for a floating point precision, and it has serial types for automatically incrementing unique identifiers.
Character types include the standard VARCHAR, or Character Variant for Variable Length Strings; CHAR for fixed length strings; and TEXT, which is actually equivalent to VARCHAR with no maximum length specified. It's useful to note that the fixed- length strings are actually less efficient in Postgres than the VARCHARs. The VARCHARs and the text are more efficient than the fixed-length character strings, although the fixed-length character strings can be more efficient with storage depending on the application.
So it's important to look at your application and understand what you are looking for: efficiency and speed, or storage space. And I think most of the time you will pick the text type or the VARCHAR type. It's also worth noting that with VARCHAR you can specify a maximum length, and this may be important in some applications, because that constraint gets imposed by the database, although in most cases where you are running your database from an application it may actually be more efficient for you to implement that constraint in your host language than in the database.
So again this is something to look at in terms of performance and convenience, but I think most of the time of you look at all these trade-offs you are going to select the text type for almost all text. Postgres also supports the standard date and time types: timestamp that stores both date and time, date for dates alone and time for time alone, and an interval type for a time intervals. Just a few other data types that are supported. There are binary types, and these are packed binary so you get one bit per binary value.
It's extremely efficient in storage space. Boolean types, now this is different than binary types. Boolean types are for logical Booleans, and this is basically true or false, and these take up one byte of storage per Boolean value. So they're not efficient on storage, but they are convenient for use. And there is enumerated types for enumerations. So Postgres has a rich set of data types available, and while you may never use most of them, it's a good idea to have an overview of what's available.
- Installing PostgreSQL
- Understanding database architecture
- Inserting, updating, and deleting data in a table
- Creating a database library
- Indexing ID fields
- Storing numbers, text, and Boolean values
- Reading data
- Using casts to force type
- Using mathematical functions
- Concatenating strings
- Working with date and time functions and operators
- Defining CRUD
- Using PHP to insert, read, update, and delete rows in a database
Skill Level Beginner
1. Quick Start
2. Creating a Database
3. Data Types
4. Storing and Reading Data
5. SQL Expressions
6. Mathematical Functions and Operators
Using math functions3m 2s
7. String Functions and Operators
8. Date and Time Functions and Operators
9. PHP Interfaces
10. Web Applications
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.