{"id":22535782,"url":"https://github.com/ik5/example_pgx_with_complext_oid","last_synced_at":"2025-03-28T06:21:23.864Z","repository":{"id":221686554,"uuid":"755081198","full_name":"ik5/example_pgx_with_complext_oid","owner":"ik5","description":"Example on how to use complex domain using golang and pgx","archived":false,"fork":false,"pushed_at":"2024-02-09T12:27:21.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-02T07:14:03.606Z","etag":null,"topics":["example","golang","pgx","pgxpool","poc","postgresql"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ik5.png","metadata":{"files":{"readme":"README.markdown","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-02-09T12:05:21.000Z","updated_at":"2024-02-09T12:07:30.000Z","dependencies_parsed_at":"2024-02-09T14:06:37.838Z","dependency_job_id":null,"html_url":"https://github.com/ik5/example_pgx_with_complext_oid","commit_stats":null,"previous_names":["ik5/example_pgx_with_complext_oid"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ik5%2Fexample_pgx_with_complext_oid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ik5%2Fexample_pgx_with_complext_oid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ik5%2Fexample_pgx_with_complext_oid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ik5%2Fexample_pgx_with_complext_oid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ik5","download_url":"https://codeload.github.com/ik5/example_pgx_with_complext_oid/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245979198,"owners_count":20703889,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["example","golang","pgx","pgxpool","poc","postgresql"],"created_at":"2024-12-07T10:08:31.025Z","updated_at":"2025-03-28T06:21:23.830Z","avatar_url":"https://github.com/ik5.png","language":"Go","readme":"The following code helps me to understand how to use complex domain in PostgreSQL using [pgx v5](https://github.com/jackc/pgx).\n\nIn this case I used an array of another domain:\n\n```SQL\nCREATE DOMAIN public.http_client_error_code AS smallint\n\tCONSTRAINT http_client_error_code_check CHECK (VALUE = 0 OR VALUE \u003e= 400 AND VALUE \u003c= 499);\n```\n\nThe above domain is a simple integer with a constraint.\n\n```SQL\nCREATE DOMAIN public.http_client_error_code_list AS http_client_error_code[];\n```\n\nThe above domain is an array of the first domain (`http_client_error_code`).\n\nWhen trying to scan or assign it using pgx an error will be raised:\n\n```\npanic: failed to encode args[0]: unable to encode main.HTTPClientErrorCodeList{400} into text format for unknown type (OID 32783): cannot find encode plan\n```\n\nThe issue is that `pgx` does not understand how to convert the slice into `http_client_error_code_list`.\n\nBy telling `pgx` to look for that domain (and given OID), it know how to `scan` and `value` the Go's data type.\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fik5%2Fexample_pgx_with_complext_oid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fik5%2Fexample_pgx_with_complext_oid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fik5%2Fexample_pgx_with_complext_oid/lists"}