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

Handling domains created as custom types or other domains #41

Open
laurenceisla opened this issue Feb 9, 2024 · 1 comment
Open

Handling domains created as custom types or other domains #41

laurenceisla opened this issue Feb 9, 2024 · 1 comment

Comments

@laurenceisla
Copy link
Member

Right now, a domain created as a data type defined in pg_catalog returns the name of the base type. No problem there, since:

create domain mydomain as int;

will be shown in OpenAPI as an integer. The problem starts when the domain is created as a custom type or as another domain. Then, postgrest-openapi treats it as a string instead of the schema defined by the base type.

@laurenceisla
Copy link
Member Author

The recursive CTE to get the base_types of return types from functions could be useful here:

-- Recursively get the base types of domains
WITH
base_types AS (
WITH RECURSIVE
recurse AS (
SELECT
oid,
typbasetype,
COALESCE(NULLIF(typbasetype, 0), oid) AS base
FROM pg_type
UNION
SELECT
t.oid,
b.typbasetype,
COALESCE(NULLIF(b.typbasetype, 0), b.oid) AS base
FROM recurse t
JOIN pg_type b ON t.typbasetype = b.oid
)
SELECT
oid,
base
FROM recurse
WHERE typbasetype = 0
),

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

No branches or pull requests

1 participant