Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Negative length for a character varying field displayed (PostgreSQL) #21507

Open
paul-at opened this issue Feb 21, 2024 · 1 comment
Open

Negative length for a character varying field displayed (PostgreSQL) #21507

paul-at opened this issue Feb 21, 2024 · 1 comment

Comments

@paul-at
Copy link

paul-at commented Feb 21, 2024

Describe the Bug

Directus displays a negative length for a character varying field:
image

pg_dump describes the schema as follows:

CREATE TABLE public.services (
    id bigint NOT NULL,
    name character varying NOT NULL,
    stack_tag character varying,

Directus 10.9.2, PostgreSQL 14.10

To Reproduce

  1. Create a database table with a character varying field
  2. Attempt to edit the field in Directus

Directus Version

v10.9.2

Hosting Strategy

Self-Hosted (Custom)

@azrikahar
Copy link
Contributor

Seems like this bug originates from here:

CASE
WHEN att.atttypid IN (1042, 1043) THEN (att.atttypmod - 4)::int4
WHEN att.atttypid IN (1560, 1562) THEN (att.atttypmod)::int4
ELSE NULL
END AS max_length,

where a character varying field without length defined would have att.atttypemod of -1, which then based on the first case, turns into (-1 - 4), resulting in -5 as shown in OP's screenshot.

Adding a similar WHEN atttypmod = -1 THEN NULL logic as used in numeric_precision and numeric_scale as well does seem to technically fix this, but the length is returned as 255, which might be slightly misleading since it's technically unlimited, except maybe the technical size limit outlined in Postgres' docs:

In any case, the longest possible character string that can be stored is about 1 GB

Above quote from https://www.postgresql.org/docs/current/datatype-character.html

The solution used for Postgres dialect should also be propagated to CockroachDB as it contains the same logic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants