# Create sequence for postgres

**URL:** <https://discourse.laminas.dev/t/create-sequence-for-postgres/2548>\
**Category:** Components & MVC\
**Tags:** laminas-db\
**Created:** [October 18, 2021, 7:49am UTC](https://discourse.laminas.dev/t/create-sequence-for-postgres/2548 "2021-10-18T07:49:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MatteoF](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MatteoF](https://discourse.laminas.dev/u/MatteoF)\
**Post date:** [October 18, 2021, 7:49am UTC](https://discourse.laminas.dev/t/create-sequence-for-postgres/2548/1 "2021-10-18T07:49:57Z")

</div>

Hello everyone!  
My purpouse is create a table with the first column having a default value taken from a sequence

This is the code i wrote so far to create the table

```auto
public function createTable() {
        $seqExpr = new \Laminas\Db\Sql\Expression('nextval(\'prodotti_polizze_id_seq\'::regclass)');
        $table = new Ddl\CreateTable($this->table_name);
        $table->addColumn(new Ddl\Column\Integer('id', false, $seqExpr));
        $table->addColumn(new Ddl\Column\Integer('compagnia', true));
        $table->addColumn(new Ddl\Column\Integer('ramo', false));
        $table->addColumn(new Ddl\Column\Integer('desc_ramo', false));
        $table->addColumn(new Ddl\Column\Varchar('cod_prodotto', null, false));
        $table->addConstraint(new Ddl\Constraint\PrimaryKey('cod_prodotto', 'cod_prodotto_pkey'));
        $table->addConstraint(new Ddl\Constraint\UniqueKey('cod_prodotto', 'cod_prodotto_ukey'));
        $table->addColumn(new Ddl\Column\Text('desc_prodotto'));

        $sql = new Sql($this->db);
        $this->db->query(
                $sql->buildSqlString($table),
                \Laminas\Db\Adapter\Adapter::QUERY_MODE_EXECUTE
        );
    }

```

but i couldnt find any instruction on the docs on how to create a sequence (in this case _prodotti\_polizze\_id\_seq_)

---

<div class="post-metadata">

**Author:** ![MatteoF](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MatteoF](https://discourse.laminas.dev/u/MatteoF)\
**Post date:** [October 18, 2021, 1:42pm UTC](https://discourse.laminas.dev/t/create-sequence-for-postgres/2548/2 "2021-10-18T13:42:29Z")

</div>

As a workaround at the moment im using  
`$this->db->query( 'CREATE SEQUENCE IF NOT EXISTS public.prodotti_polizze_id_seq', \Laminas\Db\Adapter\Adapter::QUERY_MODE_EXECUTE );`  
still looking for any other options

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [October 20, 2021, 7:08am UTC](https://discourse.laminas.dev/t/create-sequence-for-postgres/2548/3 "2021-10-20T07:08:42Z")

</div>

Hello and welcome to our forums! 😃

> [@MatteoF](#):
>
> but i couldnt find any instruction on the docs on how to create a sequence

Not all features are supported, see in the introduction of the “DDL Abstraction” chapter:

> The following platforms have platform specializations for DDL:
> 
> - MySQL
> - All databases compatible with ANSI SQL92

> **[DDL Abstraction - laminas-db - Laminas Docs](https://docs.laminas.dev/laminas-db/sql-ddl/)**
>
> Database abstraction layer, SQL abstraction, result set abstraction, and RowDataGateway and TableDataGateway implementations

I think sequences are included in ANSI SQL 2003.
