pg_graphql
pg_graphql copied to clipboard
Cannot filter queries on columns of type CHAR
Describe the bug
Attempting to perform a query over columns of type CHAR / CHAR(n) returns empty results.
Changing field type to VARCHAR fixes the filtering.
To Reproduce Steps to reproduce the behavior:
- Create a table schema with a field of type
CHAR, e.g."iso2" CHAR(2) NOT NULL UNIQUE. - Populate database with data
- Make a query to verify that data is present.
- Attempt to add filter to above query
- See empty results
Sample table schema
CREATE TABLE IF NOT EXISTS states (
"name" VARCHAR(255) NOT NULL,
"iso2" CHAR(2) NOT NULL UNIQUE,
PRIMARY KEY ("iso2")
);
Expected behavior Matching rows are returned.
Screenshots
Verify that data is present

Empty results when attempting to filter above data

that you for reporting, I was able to reproduce the issue
When casting inputs from GraphQL types to PostgreSQL types pg type modifiers are ignored (except for arrays). That is not usually an issue because e.g. varchar can handle anything that varchar(200) can.
In the char case, the casting rule is unusual
select 'GB'::char -- 'G'
to resolve this, we'll need to retain the modifiers when casting.
Your solution of using a varchar is a good choice