Skip to content
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

Fix typo in README #153

Merged
merged 2 commits into from
Apr 19, 2023
Merged

Fix typo in README #153

merged 2 commits into from
Apr 19, 2023

Conversation

craigpastro
Copy link
Contributor

👋 Hello! This PR fixes a couple of small typos I found when trying out some of the examples. I am not sure that adding the ::text type cast to the urlencode of the json_build_object is the best way, but it is the only way I found it would work.

Thanks!

README.md Outdated
@@ -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.

@pramsey
Copy link
Owner

pramsey commented Apr 19, 2023

Works 100% for me:

http=# SELECT urlencode(jsonb_build_object('name','Colin & James','rate','50%'));
            urlencode            
---------------------------------
 name=Colin+%26+James&rate=50%25
(1 row)

@pramsey pramsey merged commit 6577b26 into pramsey:master Apr 19, 2023
@craigpastro craigpastro deleted the patch-1 branch April 19, 2023 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants