From d526b631622ba08534807a10b22c1ee09b7dc6a7 Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Fri, 5 Jul 2024 16:12:02 +0200 Subject: [PATCH] adapt --- test/demo_data.sql | 12 ++++++------ test/test_simple_inheritance.sh | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/demo_data.sql b/test/demo_data.sql index 561f7e9..577e279 100644 --- a/test/demo_data.sql +++ b/test/demo_data.sql @@ -6,18 +6,18 @@ CREATE SCHEMA pirogue_test; CREATE SEQUENCE pirogue_test.id_gen START 101; -CREATE OR REPLACE FUNCTION pirogue_test.generate_id(table_name text) +CREATE OR REPLACE FUNCTION pirogue_test.generate_id(number integer) RETURNS integer AS $BODY$ DECLARE BEGIN - RETURN 1000 + nextval('pirogue_test.id_gen'); + RETURN number + nextval('pirogue_test.id_gen'); END; $BODY$ LANGUAGE plpgsql; CREATE TABLE pirogue_test.animal ( - aid integer PRIMARY KEY default pirogue_test.generate_id('animal'), + aid integer PRIMARY KEY default pirogue_test.generate_id(1000), name text, year smallint); @@ -26,19 +26,19 @@ CREATE TABLE pirogue_test.dog_breed ( id integer PRIMARY KEY, breed_name text ); CREATE TABLE pirogue_test.vet ( id integer PRIMARY KEY, vet_name text ); CREATE TABLE pirogue_test.cat ( - cid integer REFERENCES pirogue_test.animal, + cid integer default pirogue_test.generate_id(2000) REFERENCES pirogue_test.animal, fk_breed integer REFERENCES pirogue_test.cat_breed, fk_vet integer REFERENCES pirogue_test.vet, eye_color text); -- not in top class, as some animals might not have eyes CREATE TABLE pirogue_test.dog ( - did integer REFERENCES pirogue_test.animal, + did integer default pirogue_test.generate_id(3000) REFERENCES pirogue_test.animal, fk_breed integer REFERENCES pirogue_test.dog_breed, eye_color text); -- ref col has same name as parent pkey column CREATE TABLE pirogue_test.aardvark ( - aid integer REFERENCES pirogue_test.animal, + aid integer default pirogue_test.generate_id(4000) REFERENCES pirogue_test.animal, father text -- ! if adding new fields here, complete the list on test_multiple_inheritance.test_merge_no_columns ! -- ); diff --git a/test/test_simple_inheritance.sh b/test/test_simple_inheritance.sh index 1f293a1..34b6b79 100755 --- a/test/test_simple_inheritance.sh +++ b/test/test_simple_inheritance.sh @@ -29,10 +29,10 @@ RESULT=$(psql ${PSQL_ARGS} -c "SELECT COUNT(*) FROM pirogue_test.vw_animal_cat;" EXPECTED=0 if [[ ${RESULT} =~ "${EXPECTED}" ]]; then echo "ok"; else echo "*** ERROR expected result: ${EXPECTED} got ${RESULT}" && ERROR=1; fi -echo "test insert without pkey value (getting default from parent table)" +echo "test insert without pkey value (getting default from child table)" psql --quiet -v ON_ERROR_STOP="on" -c "INSERT into pirogue_test.vw_animal_cat (fk_breed, eye_color, name, year) VALUES ('1', 'yellow', 'ninja', 1934);" RESULT=$(psql ${PSQL_ARGS} -c "SELECT cid FROM pirogue_test.vw_animal_cat") -EXPECTED=1101 +EXPECTED=2101 if [[ ${RESULT} =~ "${EXPECTED}" ]]; then echo "ok"; else echo "*** ERROR expected result: ${EXPECTED} got ${RESULT}" && ERROR=1; fi echo "test on table with same pkey/ref name"