sqlx icon indicating copy to clipboard operation
sqlx copied to clipboard

feat(Postgres): support nested domain types

Open joeydewaal opened this issue 1 year ago • 2 comments

This PR adds support for nested domain types. When comparing a PgType by Oid it compares the Oid of the base type when it is a domain.

joeydewaal avatar Dec 16 '24 21:12 joeydewaal

Does this PR only address DOMAINs that are transitively based on a "primitive" (e.g., a DOMAIN of a DOMAIN of integer)? If not, then there should be a test added for the case where you have a composite type that has a DOMAIN field that is based on a composite type that has a "primitive" field. For example a test that fetches the row in buzz based on the below query:

BEGIN;
    CREATE TYPE foo AS (x integer);
    CREATE DOMAIN bar AS foo NOT NULL;
    CREATE TYPE fizz AS (y bar);
    CREATE TABLE buzz(z fizz NOT NULL);
    INSERT INTO buzz VALUES (ROW(ROW(1)));
COMMIT;

There is a bug in how FromSql is derived in postgres_types that was not triggered until such a test was added. If this PR does not intend to support such situations, then it may make sense to rename the PR to make it clear that only transitive "primitive" DOMAIN support is being added.

zacknewman avatar Feb 06 '25 19:02 zacknewman

Thanks for the comment, it did not support all nested domain types. I updated the PR and added the unit test from the mentioned PR.

joeydewaal avatar Mar 03 '25 20:03 joeydewaal

@joeydewaal merge conflicts here.

abonander avatar Jul 06 '25 04:07 abonander

All done!

joeydewaal avatar Jul 06 '25 08:07 joeydewaal