Hi,
This is my postgresql functuion that I created using help on stackoverflow:
Now I am moving my database to Mysql and I can't find out how to convert this function from postgresql to mysql. I have found two different things:
First option:
Second option:
Using Sqlfiddle I can't get either one to work as I want it to, or even just not throw out syntax errors. What I am trying to do is take the "id" from the "job" table and stick a letter on the front, in this case "A" to give me a "solrid" which is geenrated on the fly and not stored. Here is an example:
Job Table (id): 123
Solrid: A123
Can anyone help me on this please? I'm not very good with databases and feel a bit out of my depth.
This is my postgresql functuion that I created using help on stackoverflow:
Code:
-- Setup Solrid Function
CREATE OR REPLACE FUNCTION solrid(IN local_id INTEGER, OUT result TEXT) AS $$
DECLARE
database_id TEXT := 'A';
BEGIN
result := database_id || local_id::TEXT;
END;
$$ LANGUAGE PLPGSQL;
First option:
Code:
CREATE OR REPLACE FUNCTION solrid(integer) RETURNS text AS $$ SELECT 'A'||$1; $$ LANGUAGE SQL
Code:
DELIMITER //
DROP FUNCTION IF EXISTS solrid //
CREATE FUNCTION solrid(local_id INTEGER) RETURNS TEXT
BEGIN
DECLARE database_id TEXT;
SET database_id = 'A';
RETURN CONCAT(database_id, CAST(local_id AS CHAR));
END //
DELIMITER ;
Job Table (id): 123
Solrid: A123
Can anyone help me on this please? I'm not very good with databases and feel a bit out of my depth.