Skip to content

Commit

Permalink
Merge pull request #3754 from mathesar-foundation/records_delete_bugfix
Browse files Browse the repository at this point in the history
Records delete bugfix
  • Loading branch information
seancolsen authored Aug 13, 2024
2 parents 7f76d7a + c078a44 commit c6ba8de
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
13 changes: 8 additions & 5 deletions db/sql/00_msar.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3353,6 +3353,7 @@ INSERT INTO msar.expr_templates VALUES
-- json(b) filters and expressions
('json_array_length', 'jsonb_array_length((%s)::jsonb)'),
('json_array_contains', '(%s)::jsonb @> (%s)::jsonb'),
('element_in_json_array_untyped', '(%s)::text IN (SELECT jsonb_array_elements_text(%s))'),
('convert_to_json', 'to_jsonb(%s)'),
-- date part extractors
('truncate_to_year', 'to_char((%s)::date, ''YYYY AD'')'),
Expand All @@ -3362,7 +3363,9 @@ INSERT INTO msar.expr_templates VALUES
('uri_scheme', 'mathesar_types.uri_scheme(%s)'),
('uri_authority', 'mathesar_types.uri_authority(%s)'),
-- Email part getters
('email_domain', 'mathesar_types.email_domain_name(%s)')
('email_domain', 'mathesar_types.email_domain_name(%s)'),
-- Data formatter which is sometimes useful in comparison
('format_data', 'msar.format_data(%s)')
;

CREATE OR REPLACE FUNCTION msar.build_expr(rel_id oid, tree jsonb) RETURNS text AS $$
Expand Down Expand Up @@ -3816,13 +3819,13 @@ BEGIN
msar.get_relation_name(tab_id),
msar.build_where_clause(
tab_id, jsonb_build_object(
'type', 'json_array_contains', 'args', jsonb_build_array(
jsonb_build_object('type', 'literal', 'value', rec_ids),
'type', 'element_in_json_array_untyped', 'args', jsonb_build_array(
jsonb_build_object(
'type', 'convert_to_json', 'args', jsonb_build_array(
'type', 'format_data', 'args', jsonb_build_array(
jsonb_build_object('type', 'attnum', 'value', msar.get_pk_column(tab_id))
)
)
),
jsonb_build_object('type', 'literal', 'value', rec_ids)
)
)
)
Expand Down
20 changes: 20 additions & 0 deletions db/sql/test_00_msar.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3900,6 +3900,26 @@ END;
$$ LANGUAGE plpgsql;


CREATE OR REPLACE FUNCTION test_delete_records_from_table_stringy_pkey() RETURNS SETOF TEXT AS $$
DECLARE
rel_id oid;
delete_result integer;
BEGIN
PERFORM __setup_list_records_table();
rel_id := 'atable'::regclass::oid;
delete_result := msar.delete_records_from_table(
rel_id,
'["1", "2"]'
);
RETURN NEXT is(delete_result, 2);
RETURN NEXT results_eq(
'SELECT id FROM atable ORDER BY id',
$v$VALUES ('3'::integer)$v$
);
END;
$$ LANGUAGE plpgsql;


CREATE OR REPLACE FUNCTION __setup_add_record_table() RETURNS SETOF TEXT AS $$
BEGIN
PERFORM __setup_list_records_table();
Expand Down

0 comments on commit c6ba8de

Please sign in to comment.