目标是在PostgreSQL中导入和使用过程(通过pgAdmin和Shell)。我的任务以任务结束,错误screen of mistake here。
代码示例(来自教程):
CREATE OR REPLACE FUNCTION add_event(
title text,
starts TIMESTAMP,
ends TIMESTAMP,
venue text,
postal VARCHAR(9),
country CHAR(2)
)
RETURNS BOOLEAN
AS $$
DECLARE
did_insert BOOLEAN := FALSE;
found_count INTEGER;
the_venue_id INTEGER;
BEGIN
SELECT venue_id INTO the_venue_id
FROM venues v
WHERE v.postal_code=postal
AND v.country_code=country
AND v.name LIKE venue
LIMIT 1;
IF the_venue_id IS NULL THEN
INSERT INTO venues (name, postal_code, country_code)
VALUES (venue, postal, country)
RETURNING venue_id INTO the_venue_id;
did_insert := TRUE;
END IF;
RAISE NOTICE ‘Venue found %’, the_venue_id;
INSERT INTO events (title, starts, ends, venue_id)
VALUES (title, starts, ends, the_venue_id);
RETURN did_insert;
END;
$$ LANGUAGE plpgsql;