Skip to content

Commit 520ff8a

Browse files
committed
Change json datatype to jsonb, if available. Otherwise fall back to json or text.
Signed-off-by: Clemens Gruber <[email protected]>
1 parent e66a305 commit 520ff8a

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,10 @@ All configuration takes place in the form of environment vars. See [queue_classi
239239

240240
## JSON
241241

242-
If you are running PostgreSQL 9.2 or higher, queue_classic will use the [json](http://www.postgresql.org/docs/9.2/static/datatype-json.html) datatype for storing arguments. Versions 9.1 and lower will use the 'text' column. If you have installed queue_classic prior to version 2.1.4 and are running PostgreSQL >= 9.2, run the following to switch to using the json type:
242+
If you are running PostgreSQL 9.4 or higher, queue_classic will use the [jsonb](http://www.postgresql.org/docs/9.4/static/datatype-json.html) datatype for new tables. Versions 9.2 and 9.3 will use the `json` data type and versions 9.1 and lower will use the `text` data type.
243+
If you are updating queue_classic and are running PostgreSQL >= 9.4, run the following to switch to `jsonb`:
243244
```
244-
alter table queue_classic_jobs alter column args type json using (args::json);
245+
alter table queue_classic_jobs alter column args type jsonb using (args::jsonb);
245246
```
246247

247248
## Logging

changelog

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Unreleased
22
- Fixed a bug in the offset calculation of `.enqueue_at`.
3+
- Use the jsonb type for the args column from now on. If not available, fall back to json or text.
34

45
Version 3.0.0rc
56
- Improved signal handling

sql/create_table.sql

+6-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ CREATE TABLE queue_classic_jobs (
1111
scheduled_at timestamptz default now()
1212
);
1313

14-
-- If json type is available, use it for the args column.
15-
perform * from pg_type where typname = 'json';
16-
if found then
17-
alter table queue_classic_jobs alter column args type json using (args::json);
14+
-- If jsonb type is available, use it for the args column
15+
if exists (select 1 from pg_type where typname = 'jsonb') then
16+
alter table queue_classic_jobs alter column args type jsonb using args::jsonb;
17+
-- Otherwise, use json type for the args column if available
18+
elsif exists (select 1 from pg_type where typname = 'json') then
19+
alter table queue_classic_jobs alter column args type json using args::json;
1820
end if;
1921

2022
end $$ language plpgsql;

0 commit comments

Comments
 (0)