Skip to content

Commit 1b624ae

Browse files
committed
refactor: remove strict and parallel safe attrs
Closes #172. Remove strict as explained on #172. A test is added on a previous commit to ensure the behavior is maintained. Also, remove PARALLEL SAFE since these functions are really PARALLEL UNSAFE, as mentioned on the docs: "Functions and aggregates must be marked PARALLEL UNSAFE if they write to the database," https://www.postgresql.org/docs/current/parallel-safety.html Also remove VOLATILE since it's implicit.
1 parent b449d38 commit 1b624ae

File tree

4 files changed

+25
-23
lines changed

4 files changed

+25
-23
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ __pycache__/
77
.deployment.nixops*
88
valgrindlog
99
nix/nginx/logs/nginx.pid
10-
pg_net--*.sql
1110
.history
1211
*.o
1312
*.bc

sql/pg_net--0.15.0--new.sql

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
alter function net._await_response(bigint) parallel unsafe called on null input;
2+
3+
alter function net._urlencode_string(varchar) called on null input;
4+
5+
alter function net._encode_url_with_params_array(text, text[]) called on null input;
6+
7+
alter function net._await_response(bigint) parallel unsafe called on null input;
8+
9+
alter function net.http_get(text, jsonb , jsonb , int) parallel unsafe called on null input;
10+
11+
alter function net.http_post(text, jsonb , jsonb , jsonb, int) parallel unsafe;
12+
13+
alter function net.http_delete(text, jsonb , jsonb, int, jsonb) parallel unsafe;
14+
15+
alter function net._http_collect_response(bigint, bool) parallel unsafe called on null input;
16+
17+
alter function net.http_collect_response(bigint, bool) parallel unsafe called on null input;

sql/pg_net.sql

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ create or replace function net._await_response(
5151
request_id bigint
5252
)
5353
returns bool
54-
volatile
55-
parallel safe
56-
strict
5754
language plpgsql
5855
as $$
5956
declare
@@ -81,17 +78,14 @@ $$;
8178
create or replace function net._urlencode_string(string varchar)
8279
-- url encoded string
8380
returns text
84-
8581
language 'c'
8682
immutable
87-
strict
8883
as 'pg_net';
8984

9085
-- API: Private
9186
create or replace function net._encode_url_with_params_array(url text, params_array text[])
9287
-- url encoded string
9388
returns text
94-
strict
9589
language 'c'
9690
immutable
9791
as 'pg_net';
@@ -115,9 +109,6 @@ create or replace function net.http_get(
115109
)
116110
-- request_id reference
117111
returns bigint
118-
strict
119-
volatile
120-
parallel safe
121112
language plpgsql
122113
as $$
123114
declare
@@ -159,8 +150,6 @@ create or replace function net.http_post(
159150
)
160151
-- request_id reference
161152
returns bigint
162-
volatile
163-
parallel safe
164153
language plpgsql
165154
as $$
166155
declare
@@ -229,8 +218,6 @@ create or replace function net.http_delete(
229218
)
230219
-- request_id reference
231220
returns bigint
232-
volatile
233-
parallel safe
234221
language plpgsql
235222
as $$
236223
declare
@@ -289,9 +276,6 @@ create or replace function net._http_collect_response(
289276
)
290277
-- http response composite wrapped in a result type
291278
returns net.http_response_result
292-
strict
293-
volatile
294-
parallel safe
295279
language plpgsql
296280
as $$
297281
declare
@@ -343,9 +327,6 @@ create or replace function net.http_collect_response(
343327
)
344328
-- http response composite wrapped in a result type
345329
returns net.http_response_result
346-
strict
347-
volatile
348-
parallel safe
349330
language plpgsql
350331
as $$
351332
begin

src/util.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ PG_FUNCTION_INFO_V1(_urlencode_string);
66
PG_FUNCTION_INFO_V1(_encode_url_with_params_array);
77

88
Datum _urlencode_string(PG_FUNCTION_ARGS) {
9+
if(PG_GETARG_POINTER(0) == NULL)
10+
PG_RETURN_NULL();
11+
912
char *str = text_to_cstring(PG_GETARG_TEXT_P(0));
1013
char *urlencoded_str = NULL;
1114

@@ -17,19 +20,21 @@ Datum _urlencode_string(PG_FUNCTION_ARGS) {
1720
}
1821

1922
Datum _encode_url_with_params_array(PG_FUNCTION_ARGS) {
20-
CURLU *h = curl_url();
21-
CURLUcode rc;
23+
if(PG_GETARG_POINTER(0) == NULL || PG_GETARG_POINTER(1) == NULL)
24+
PG_RETURN_NULL();
2225

2326
char *url = text_to_cstring(PG_GETARG_TEXT_P(0));
2427
ArrayType *params = PG_GETARG_ARRAYTYPE_P(1);
28+
2529
char *full_url = NULL;
2630

2731
ArrayIterator iterator;
2832
Datum value;
2933
bool isnull;
3034
char *param;
3135

32-
rc = curl_url_set(h, CURLUPART_URL, url, 0);
36+
CURLU *h = curl_url();
37+
CURLUcode rc = curl_url_set(h, CURLUPART_URL, url, 0);
3338
if (rc != CURLUE_OK) {
3439
// TODO: Use curl_url_strerror once released.
3540
elog(ERROR, "%s", curl_easy_strerror((CURLcode)rc));

0 commit comments

Comments
 (0)