Create sequence for postgres

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

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)

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

Hello and welcome to our forums! :smiley:

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

I think sequences are included in ANSI SQL 2003.