Skip to content

columns.create rejects schema-qualified array types such as schema.type[] #1122

Description

@hsusul

Describe the bug

columns.create / columns.update quote schema-qualified array types as a single identifier. type: 'myschema.foo[]' becomes "myschema.foo"[], which Postgres rejects (type "myschema.foo[]" does not exist).

This shows up when adding array columns of types such as extensions.vector[] or a user type s.my_type[].

To Reproduce

create schema s;
create type s.my_type as enum ('a');
create table public.t();
await pgMeta.columns.create({
  table_id,
  name: 'c',
  type: 's.my_type[]',
})

Expected behavior

The column is created as type "s"."my_type"[] (an array of s.my_type).

Actual behavior

ERROR: type "s.my_type[]" does not exist
ALTER TABLE public.t ADD COLUMN c "s.my_type"[]

Root cause

typeIdent applies ident() to the whole schema.type string when the name ends with [], before splitting on .. Non-array schema-qualified types (s.my_type) were already left unquoted and still work.

Additional context

  • Library: @supabase/postgres-meta
  • Branch analyzed: master (641831e)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions