[BUG] Postgres - Default Value for TEXT or VARCHAR (without length) shows up as issue, unable to specify empty string as default
- Dominant language
- JavaScript
- Stars
- 39.5k
- Forks
- 3.2k
- Avg merge
- 10h 46m
- Merged PRs (30d)
- 16
Description
**Describe the bug**
Table field default values for TEXT or VARCHAR (without length) shows up as an issue but produces valid PostgreSQL schema. Wrapping the default value in quotes just adds those quotes to the default value.
Adding a length value back for VARCHAR makes the issue disappear.
Furthermore, I would expect entering two double or single quotes into the defaults field to produce `DEFAULT ''`, but this is not the case. It shows up as `DEFAULT '""'` instead. This was apparently fixed with #10 but I don't understand how the code in the referenced commits actually would do that, and it apparently doesn't.
**To Reproduce**
Steps to reproduce the behavior:
1. Create new Diagram with Postgres, create a new Table
2. Add a field with type TEXT or VARCHAR (remove length)
3. Type in anything into the default value field
4. See it show up in issues
**Expected behavior**
Anything entered into the default value field for any text type should not produce an issue, since it clearly isn't one. There should be a way to specify an empty string as a default value.
**Screenshots**
This is the only way to specify a default value for a TEXT/VARCHAR field. Removing `255` or using TEXT as type results in the issue. Also entering `""` into default results in unexprected SQL schema, see below.
**Desktop (please complete the following information):**
- OS: Linux
- Browser: Firefox
- DrawDB: Docker Image (ghcr.io/drawdb-io/drawdb:v1.8.1)
**Additional context**
The exported SQL for the table:
```sql
CREATE TABLE IF NOT EXISTS "text_test" (
"id" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"text" TEXT NOT NULL DEFAULT 'test',
"varchar" VARCHAR NOT NULL DEFAULT 'test',
"varchar255" VARCHAR(255) NOT NULL DEFAULT 'test',
"empty_string" VARCHAR(255) NOT NULL DEFAULT '""',
PRIMARY KEY("id")
);
```
Contributor guide
Research direction
Reproduce the issue in a PostgreSQL diagram using TEXT, VARCHAR without a length, and an empty-string default, then inspect the default-value validation and PostgreSQL SQL export entry points. Done means valid text defaults no longer appear as issues and an empty string exports as DEFAULT ''. Run the reproduction steps again and verify the generated schema.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, postgresql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100