I use HSQLDB 2.3.2 and get a fancy error when trying to create a stored procedure.
My table addresses
:
CREATE TABLE IF NOT EXISTS addresses ( address_id INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1) NOT NULL PRIMARY KEY, address_line_1 NVARCHAR(500) NOT NULL, address_line_2 NVARCHAR(500), address_city NVARCHAR(100) NOT NULL, address_postal_code NVARCHAR(25) NOT NULL, CONSTRAINT uc_addresses UNIQUE (address_line_1, address_city) )
Insert for filling:
INSERT INTO addresses ( address_line_1, address_city, address_postal_code ) VALUES ( '123 Test Blvd.', 'Testville', '11111' )
And my good:
CREATE PROCEDURE sp_get_address_by_id( IN address_id INTEGER, OUT address_id INTEGER, OUT address_line_1 NVARCHAR(500), OUT address_line_2 NVARCHAR(500), OUT address_city NVARCHAR(100), OUT address_postal_code NVARCHAR(25)) READS SQL DATA BEGIN ATOMIC SELECT a.address_id, a.address_line_1, a.address_line_2, a.address_city, a.address_postal_code INTO address_id, address_line_1, address_line_2, address_city, address_postal_code FROM addresses a WHERE a.address_id = address_id; END
When I run this, I get:
Error: attempt to assign to non-updatable column SQLState: 0U000 ErrorCode: -2500
Questions:
- What is wrong with my proc (what causes this error)?
- I'm really looking for a
CREATE IF NOT EXISTS
-type declaration, so I can run this script over and over and the procedure will only be created once if it does not already exist. Will this happen or do I need to change the syntax to execute IF NOT EXISTS
?
source share