Skip to content

Error: PostgresSQL create table default value for integer column  #12267

Closed
@Ridlsan

Description

@Ridlsan

Phalcon 3.0.1

If setting default value 0 for integer column, phalcon escapes it as string and postgres complains as column "0" not exists.

Change its behavior in https://github.com/phalcon/cphalcon/blob/master/phalcon/db/dialect/postgresql.zep#L382

Just add check - if INTEGER so not escape value. Phalcon already has check for BOOLEAN

        if column->hasDefault() {
                let defaultValue = column->getDefault();
                if memstr(strtoupper(columnDefinition), "BOOLEAN") {
                    let sql .= " DEFAULT " . (defaultValue ? "true" : "false");
                } elseif memstr(strtoupper(defaultValue), "CURRENT_TIMESTAMP") {
                    let columnLine .= " DEFAULT CURRENT_TIMESTAMP";
                } else {
                    let columnLine .= " DEFAULT \"" . addcslashes(defaultValue, "\"") . "\"";
                }
        }

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions