Skip to content

Commit

Permalink
adapt
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Jul 5, 2024
1 parent d5aa485 commit d526b63
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions test/demo_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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 ! --
);
Expand Down
4 changes: 2 additions & 2 deletions test/test_simple_inheritance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit d526b63

Please sign in to comment.