Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: CI
on: [push, pull_request]
jobs:
test:
strategy:
matrix:
pg: [17, 16, 15, 14, 13, 12, 11, 10]
name: 🐘 PostgreSQL ${{ matrix.pg }}
runs-on: ubuntu-latest
container: pgxn/pgxn-tools
steps:
- name: Start PostgreSQL ${{ matrix.pg }}
run: pg-start ${{ matrix.pg }}
- name: Check out the repo
uses: actions/checkout@v4
- name: Test on PostgreSQL ${{ matrix.pg }}
run: pg-build-test
4 changes: 2 additions & 2 deletions META.in.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"name": "count_nulls",

"X_comment": "REQUIRED. Version of the distribution. http://pgxn.org/spec/#version",
"version": "0.9.7",
"version": "1.0.0",

"X_comment": "REQUIRED. Short description of distribution.",
"abstract": "Count the number of null arguments",
Expand All @@ -43,7 +43,7 @@
"file": "sql/count_nulls.sql",

"X_comment": "REQUIRED. Version the extension is at.",
"version": "0.9.6",
"version": "1.0.0",

"X_comment": "Optional: \"abstract\": Description of the extension.",
"abstract": "Count the number of null arguments",
Expand Down
4 changes: 2 additions & 2 deletions META.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"name": "count_nulls",

"X_comment": "REQUIRED. Version of the distribution. http://pgxn.org/spec/#version",
"version": "0.9.7",
"version": "1.0.0",

"X_comment": "REQUIRED. Short description of distribution.",
"abstract": "Count the number of null arguments",
Expand All @@ -43,7 +43,7 @@
"file": "sql/count_nulls.sql",

"X_comment": "REQUIRED. Version the extension is at.",
"version": "0.9.6",
"version": "1.0.0",

"X_comment": "Optional: \"abstract\": Description of the extension.",
"abstract": "Count the number of null arguments",
Expand Down
2 changes: 1 addition & 1 deletion count_nulls.control
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# count_nulls extension
comment = 'Count the number of null arguments'
default_version = '0.9.6'
default_version = '1.0.0'
relocatable = false
1 change: 1 addition & 0 deletions sql/count_nulls--0.9.6--1.0.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- No actual SQL changes to this version bump
89 changes: 89 additions & 0 deletions sql/count_nulls--1.0.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/* DO NOT EDIT - AUTO-GENERATED FILE */
SET client_min_messages = WARNING;

CREATE OR REPLACE FUNCTION null_count(
VARIADIC argument anyarray
) RETURNS int LANGUAGE sql IMMUTABLE AS $body$
SELECT sum( CASE WHEN a IS NULL THEN 1 ELSE 0 END )::int
FROM unnest( $1 ) a
$body$;

CREATE OR REPLACE FUNCTION null_count(
argument jsonb
) RETURNS int LANGUAGE sql IMMUTABLE AS $body$
SELECT count(*)::int
FROM jsonb_each_text( $1 ) a
WHERE value IS NULL
$body$;
CREATE OR REPLACE FUNCTION null_count(
argument json
) RETURNS int LANGUAGE sql IMMUTABLE AS 'SELECT @extschema@.null_count($1::jsonb)';

CREATE OR REPLACE FUNCTION null_count_trigger(
) RETURNS trigger LANGUAGE plpgsql IMMUTABLE AS $body$
DECLARE
c_msg CONSTANT text := coalesce(
nullif( TG_ARGV[1], 'null' )
, format( '%s must contain %s NULL fields', TG_RELID::regclass, TG_ARGV[0] )
);
BEGIN
IF TG_NARGS NOT BETWEEN 1 AND 2 THEN
RAISE '% usage: number of NULL columns[, error message]', TG_NAME;
END IF;
-- Casing intentional for cut/paste/replace/
IF nullif(TG_ARGV[0], 'null') IS null THEN
RAISE '%: first argument must not be null', TG_NAME;
END IF;

IF @extschema@.null_count( row_to_json(NEW) ) <> TG_ARGV[0]::int THEN
RAISE '%', c_msg;
END IF;

RETURN NEW;
END
$body$;


CREATE OR REPLACE FUNCTION not_null_count(
VARIADIC argument anyarray
) RETURNS int LANGUAGE sql IMMUTABLE AS $body$
SELECT sum( CASE WHEN a IS NOT NULL THEN 1 ELSE 0 END )::int
FROM unnest( $1 ) a
$body$;

CREATE OR REPLACE FUNCTION not_null_count(
argument jsonb
) RETURNS int LANGUAGE sql IMMUTABLE AS $body$
SELECT count(*)::int
FROM jsonb_each_text( $1 ) a
WHERE value IS NOT NULL
$body$;
CREATE OR REPLACE FUNCTION not_null_count(
argument json
) RETURNS int LANGUAGE sql IMMUTABLE AS 'SELECT @extschema@.not_null_count($1::jsonb)';

CREATE OR REPLACE FUNCTION not_null_count_trigger(
) RETURNS trigger LANGUAGE plpgsql IMMUTABLE AS $body$
DECLARE
c_msg CONSTANT text := coalesce(
nullif( TG_ARGV[1], 'null' )
, format( '%s must contain %s NOT NULL fields', TG_RELID::regclass, TG_ARGV[0] )
);
BEGIN
IF TG_NARGS NOT BETWEEN 1 AND 2 THEN
RAISE '% usage: number of NOT NULL columns[, error message]', TG_NAME;
END IF;
-- Casing intentional for cut/paste/replace/
IF nullif(TG_ARGV[0], 'null') IS null THEN
RAISE '%: first argument must not be null', TG_NAME;
END IF;

IF @extschema@.not_null_count( row_to_json(NEW) ) <> TG_ARGV[0]::int THEN
RAISE '%', c_msg;
END IF;

RETURN NEW;
END
$body$;

-- vi: expandtab sw=2 ts=2
Loading