fix: missing=default error msg on generated column
This commit is contained in:
committed by
Steve Chavez
parent
c63786733a
commit
887948d259
@@ -13,7 +13,8 @@ import Text.Heredoc
|
||||
|
||||
import PostgREST.Config.PgVersion (PgVersion, pgVersion100,
|
||||
pgVersion110, pgVersion112,
|
||||
pgVersion130)
|
||||
pgVersion120, pgVersion130,
|
||||
pgVersion140)
|
||||
|
||||
import Protolude hiding (get)
|
||||
import SpecHelper
|
||||
@@ -496,7 +497,7 @@ spec actualPgVersion = do
|
||||
}
|
||||
|
||||
when (actualPgVersion >= pgVersion100) $
|
||||
it "inserts a default on a generated by default as identity column" $ do
|
||||
it "inserts a default on a generated by default as identity column" $
|
||||
request methodPost "/channels?columns=id,data,slug&select=data,slug" [("Prefer", "return=representation"), ("Prefer", "missing=default")]
|
||||
[json| { "slug": "foo" } |]
|
||||
`shouldRespondWith`
|
||||
@@ -505,6 +506,29 @@ spec actualPgVersion = do
|
||||
, matchHeaders = ["Preference-Applied" <:> "missing=default"]
|
||||
}
|
||||
|
||||
when (actualPgVersion >= pgVersion120) $
|
||||
it "fails with a good error message on generated always columns" $
|
||||
request methodPost "/foo?columns=a,b" [("Prefer", "return=representation"), ("Prefer", "missing=default")]
|
||||
[json| [
|
||||
{"a": "val"},
|
||||
{"a": "val", "b": "val"}
|
||||
]|]
|
||||
`shouldRespondWith`
|
||||
(if actualPgVersion < pgVersion140
|
||||
then [json| {
|
||||
"code": "42601",
|
||||
"details": "Column \"b\" is a generated column.",
|
||||
"hint": null,
|
||||
"message": "cannot insert into column \"b\""
|
||||
}|]
|
||||
else [json| {
|
||||
"code": "428C9",
|
||||
"details": "Column \"b\" is a generated column.",
|
||||
"hint": null,
|
||||
"message": "cannot insert a non-DEFAULT value into column \"b\""
|
||||
}|])
|
||||
{ matchStatus = 400 }
|
||||
|
||||
it "inserts json that has duplicate keys" $ do
|
||||
request methodPost "/tbl_w_json" [("Prefer", "return=representation")]
|
||||
[json| { "data": { "a": 1, "a": 2 }, "id": 3 } |]
|
||||
|
||||
Vendored
+16
@@ -3128,3 +3128,19 @@ LANGUAGE sql
|
||||
AS $$
|
||||
select current_setting('is_superuser')::boolean;
|
||||
$$;
|
||||
|
||||
DO $do$
|
||||
BEGIN
|
||||
IF current_setting('server_version_num')::INT >= 120000 THEN
|
||||
CREATE TABLE test.foo (
|
||||
a text,
|
||||
b text GENERATED ALWAYS AS (
|
||||
case WHEN a = 'telegram' THEN 'im'
|
||||
WHEN a = 'proton' THEN 'email'
|
||||
WHEN a = 'infinity' THEN 'idea'
|
||||
ELSE 'bad idea'
|
||||
end) stored
|
||||
);
|
||||
END IF;
|
||||
END
|
||||
$do$;
|
||||
|
||||
Reference in New Issue
Block a user