# PostgreSQL Sequences and Array Column Types

DevFeed: [PostgreSQL Sequences and Array Column Types](<https://devfeed.tech/articles/postgresql-sequences-and-array-column-types-20367.md>)

Original publisher: [Read original article](<https://blog.sensible.io/2013/08/24/postgresql-sequences-and-array-column-types.html>)

Author: sensible.io team

Published: 2013-08-24T14:21:00Z

Content type: tutorial

Language: en

Sources: [Sensible](<https://devfeed.tech/sources/sensible.md>)

Topics: [PostgreSQL](<https://devfeed.tech/topics/postgresql.md>), [Databases](<https://devfeed.tech/topics/databases.md>), [web applications](<https://devfeed.tech/topics/web-applications.md>), [Rails](<https://devfeed.tech/topics/rails.md>)

Tags: [arrays](<https://devfeed.tech/tags/arrays.md>), [database](<https://devfeed.tech/tags/database.md>), [postgresql](<https://devfeed.tech/tags/postgresql.md>), [rails](<https://devfeed.tech/tags/rails.md>), [web-applications](<https://devfeed.tech/tags/web-applications.md>)

## AI overview

This tutorial explains PostgreSQL sequences and array column types. It demonstrates creating a posts table with an array column for tags and querying posts by tag, while also discussing PostgreSQL sequences for generated identifiers.

## Source excerpt

This article is a sequel to our PostgreSQL series, which is aimed to teach you how to get the most out of your database. You might have been led by Active Record (or Rails in general) that it is a good idea to completely abstract away the database, but that it's hardly ever possible. If you plan on switching databases on any larger-than-small application, you're going to have to do some manual work anyway. Every database is special and you should use it as such, instead of just settling for the lowest common denominator. There are many features in PostgreSQL that can help you develop web applications, such as the array & json column types, hstore, PostGIS and much more. In this article we're going to take a look at arrays. Every one of us remembers the moment when you first learned about databases and you were told that if you want to store multiple values in one column you have to split that in a 1:N relationship, because each column can only hold one value. Well, that's not true in the world of PostgreSQL. You are free to create array columns with arbitrary length. You can even perform array-like queries on them. But first we need to start by creating a table. We'll do this with the most obvious example - posts with multiple tags. Each post has a title, content and an arbitrary number of tags. We also want to be able to select all posts with a specific tag. Let's first create a new database so that we can play around and drop it at the end of out session, keeping our machine clean. $ psql -U darth postgres postgres=# CREATE DATABASE test TEMPLATE template0; CREATE DATABASE postgres=# \c test; Now we can create our posts table. CREATE TABLE posts ( id SERIAL PRIMARY KEY, title VARCHAR(255) NOT NULL, content TEXT NOT NULL, tags VARCHAR(255)[] DEFAULT '{}' ); test=# \d posts Table "public.posts" Column | Type | Modifiers ---------+--------------------------+---------------------------------------------------- id | integer | not null default nextval('posts_id_seq'::re