Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ SELECT urlencode('my special string''s & things?');
URL encode a JSON associative array.

```sql
SELECT urlencode(jsonb_build_object('name','Colin & James','rate','50%'));
SELECT urlencode(jsonb_build_object('name','Colin & James','rate','50%')::text);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, this isn't right... when URL encoding an associative array one wants the keys and values encoded independently, just like the example output shows

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. Okay, let me revert that. Although, the command still doesn't work with no type cast and also when I try with ::jsonb. It returns ERROR: function urlencode(jsonb) does not exist. I took a look at the code, but C confuses me.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps you have an older version installed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, interesting!

postgres=# select version();
                                                           version
-----------------------------------------------------------------------------------------------------------------------------
 PostgreSQL 14.5 (Debian 14.5-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
(1 row)

postgres=# SELECT *
FROM pg_extension;
  oid  | extname | extowner | extnamespace | extrelocatable | extversion | extconfig | extcondition
-------+---------+----------+--------------+----------------+------------+-----------+--------------
 13743 | plpgsql |       10 |           11 | f              | 1.0        |           |
 16384 | pg_trgm |       10 |         2200 | t              | 1.6        |           |
 16465 | http    |       10 |         2200 | t              | 1.3        |           |
 16510 | plv8    |       10 |           11 | f              | 3.0alpha   |           |
(4 rows)

postgres=# SELECT urlencode(jsonb_build_object('name','Colin & James','rate','50%'));
ERROR:  function urlencode(jsonb) does not exist
LINE 1: SELECT urlencode(jsonb_build_object('name','Colin & James','...
               ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

Anything look strange? I am using the Supabase Postgres Docker image so maybe something is wrong there.

Anyway, thanks for taking a look!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, 1.4 adds the url encoding of jsonb. heh heh.

```
```
urlencode
-------------------------------------
name=Colin+%26+James&rate=50%25
%7B%22name%22%3A+%22Colin+%26+James%22%2C+%22rate%22%3A+%2250%25%22%7D
(1 row)
```

Expand All @@ -43,7 +43,7 @@ SELECT content
```
content
-----------------------------
{"origin":"24.69.186.43"} +
{"origin":"24.69.186.43"}
(1 row)
```

Expand All @@ -57,7 +57,7 @@ SELECT content::json->'headers'->>'Authorization'
ARRAY[http_header('Authorization','Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9')],
NULL,
NULL
)::http_request)
)::http_request);
```
```
content
Expand Down