question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enum type not working in postgres

See original GitHub issue

Issue type:

[ ] question [x] bug report [ ] feature request [ ] documentation issue

Database system/driver:

[ ] cordova [ ] mongodb [ ] mssql [ ] mysql / mariadb [ ] oracle [x] postgres [ ] sqlite [ ] sqljs [ ] react-native

TypeORM version:

[x] latest [ ] @next [ ] 0.2.0 (or put your version here)

Steps to reproduce or a small repository showing the problem:

type Action =
    'add' |
    'update' |
    'delete';
@Entity()
export class DatasourceAction {

    @PrimaryColumn()
    id: string;

    @Column({ name: 'name', type: 'text', unique: true })
    name: string;

    @Column({ name: 'action', type: 'enum', enum: ['add', 'update', 'delete'] })
    action: Action;
}

The SQL quarries executed are as follows

CREATE TYPE "test"."datasource_action_action_enum" AS ENUM('add', 'update', 'delete')
ALTER TABLE "test"."datasource_action" ADD "action" "datasource_action_action_enum" NOT NUL

and it errors with type “datasource_action_action_enum” does not exist

I think the the ALTER TABLE query should have been as follows. ALTER TABLE “test”.“datasource_action” ADD “action” “test”.“datasource_action_action_enum” NOT NUL

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:21
  • Comments:17 (9 by maintainers)

github_iconTop GitHub Comments

14reactions
nolazybitscommented, May 1, 2018

I hit the same problem

    @Column({
        type: "enum",
        enum: Gender,
        default: Gender.NotAvailable,
    })
    public gender!: Gender;

Gender enum class

export enum Gender
{
    Male = "male",
    Female = "female",
    Other = "other",
    NotAvailable = "n/a",
}
4reactions
evik42commented, Oct 30, 2018

@pleerock I added all the previous enum tests with external schema as part of the PR, I also used this by manually patching typeorm in prod, let me know how I can assist to move this forward.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation: 15: 8.7. Enumerated Types - PostgreSQL
Enumerated (enum) types are data types that comprise a static, ordered set of values. They are equivalent to the enum types supported in...
Read more >
Postgres ENUM data type or CHECK CONSTRAINT?
Disadvantages are, the ENUM type is stored in system catalogs, so a query as above is required to view its definition. These values...
Read more >
Dealing with Enum Type in PostgreSQL - DEV Community ‍ ‍
The workaround is the same as above: rename old type, create new and correct type, and delete old type.
Read more >
PostgreSQL Data Types: ENUM
When using PostgreSQL, each ENUM type is registered in the system catalogs and can be used anywhere PostgreSQL expects a type name. Internally, ......
Read more >
How enum works in PostgreSQL? (Examples) - eduCBA
PostgreSQL enum is the data type that was used in PostgreSQL to stored same type of values in column field, we can store...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found