https://github.com/qbart/pg-misc
Miscellaneous stuff for PostgreSQL like custom functions, aggregates etc.
https://github.com/qbart/pg-misc
Last synced: 5 months ago
JSON representation
Miscellaneous stuff for PostgreSQL like custom functions, aggregates etc.
- Host: GitHub
- URL: https://github.com/qbart/pg-misc
- Owner: qbart
- License: mit
- Created: 2019-05-11T19:14:34.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-05-11T22:26:28.000Z (about 7 years ago)
- Last Synced: 2025-10-07T14:48:43.919Z (9 months ago)
- Language: PLpgSQL
- Size: 6.84 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pg-miscs
Miscellaneous stuff for PostgreSQL like custom functions, aggregates etc.
## interval
```sql
SELECT seconds('1 day'::interval);
```
| bigint |
| - |
| 86400 |
## timestamp
```sql
SELECT now_utc();
```
| timestamp without time zone |
| - |
| 2019-05-11 19:52:33.840088 |
## jsonb
```sql
SELECT
tags.group_id,
jsonb_count(tags.val)
FROM (
VALUES
(1, 'a'),
(1, 'a'),
(1, 'b'),
(1, 'c'),
(2, 'a'),
(2, 'b'),
(2, null)
) AS tags(group_id, val)
GROUP BY tags.group_id;
```
| integer | jsonb |
| - | - |
| 1 | {"a": 2, "b": 1, "c": 1} |
| 2 | {"a": 1, "b": 1} |