-
-
Notifications
You must be signed in to change notification settings - Fork 1k
-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Non-null domain types that have a default value are coerced to null #2840
Comments
Note that:
The final query looks like this: WITH pgrst_source AS (WITH pgrst_payload AS (SELECT $1 AS json_data), pgrst_body AS ( SELECT CASE WHEN json_typeof(json_data) = 'array' THEN json_data ELSE json_build_array(json_data) END AS val FROM pgrst_payload) INSERT INTO \"public\".\"people\"(\"name\") SELECT \"name\" FROM json_populate_recordset (null::\"public\".\"people\", (SELECT val FROM pgrst_body)) _ RETURNING \"public\".\"people\".*) SELECT '' AS total_result_set, pg_catalog.count(_postgrest_t) AS page_total, array[]::text[] AS header, coalesce((json_agg(_postgrest_t)->0)::text, 'null') AS body, nullif(current_setting('response.headers', true), '') AS response_headers, nullif(current_setting('response.status', true), '') AS response_status FROM (SELECT \"people\".* FROM \"pgrst_source\" AS \"people\" ) _postgrest_t |
CREATE DOMAIN uint AS int
DEFAULT 0
NOT NULL
CHECK (VALUE >= 0);
CREATE TABLE people (
id int GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
name text,
count uint
); Using https://postgrest.org/en/stable/references/api/tables_views.html#bulk-insert-with-default-values. curl 'localhost:3000/people?columns=name,count' -H "Content-Type:application/json" \
-H "Prefer: missing=default, return=representation" \
-d '{"name": "x"}'
{"code":"23502","details":null,"hint":null,"message":"domain uint does not allow null values"} So I guess you'd expect the
Please try to isolate the problem to SQL plus http(curl) calls for next time 🙏. Otherwise it's hard to reproduce the issue. |
As a workaround, you can set the DEFAULT in the table instead: CREATE DOMAIN uint AS int
NOT NULL
CHECK (VALUE >= 0);
CREATE TABLE people (
id int GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
name text,
count uint DEFAULT 0
); curl 'localhost:3000/people?columns=name,count' -H "Content-Type:application/json" \
-H "Prefer: missing=default, return=representation" \
-d '{"name": "x"}'
[{"id":1,"name":"x","count":0}] |
Btw, what error did you got there? It should work as you're not doing a bulk insert. |
Hi, @steve-chavez. Thanks for taking your time and looking at the issue closely.
Right. Whatever the default value is set to.
Same as you: The |
FYI, this one will also get fixed on #2740. |
Thanks a lot, @steve-chavez! |
Environment
Server
header readscloudflare
)Description of issue
Domain constraints should be respected but they aren't.
json_to_recordset()
fills remaining columns with nulls, thus violating the non-null constraint.https://stackblitz.com/edit/stackblitz-starters-6sexes?file=pages%2Findex.js
The text was updated successfully, but these errors were encountered: