Go4Expert

Go4Expert (http://www.go4expert.com/)
-   PostgreSQL (http://www.go4expert.com/forums/postgresql-forum/)
-   -   PostgreSQL into MySQL (http://www.go4expert.com/forums/postgresql-into-mysql-t15580/)

Rama 23Dec2008 00:16

PostgreSQL into MySQL
 
Hi there,

I need to convert the following code from PostgreSQL into MySQL
Code:


CREATE TYPE type_name AS
(
field_id INTEGER,
field_name VARCHAR(50)
);
 
 
CREATE FUNCTION function_name()
RETURNS SETOF type_name LANGUAGE plpgsql AS $$
  DECLARE
    variable_name type_name;
  BEGIN
    FOR variable_name IN
      SELECT field_id, field_name
      FROM table_name
      ORDER BY field_id
    LOOP
      RETURN NEXT variable_name;
    END LOOP;
  END;
$$;
 
 
SELECT * FROM function_name();

Can anybody help?

Thanks in advance!

pete_bisby 9Apr2009 14:22

Re: PostgreSQL into MySQL
 
From what I can tell MySQL doesn't support Types like PostgreSQL.

However you can use the SET datatype. Have a look at the MySQL manual (http://dev.mysql.com/doc/refman/5.1/en/set.html) for more detail

Rama 10Apr2009 18:02

Re: PostgreSQL into MySQL
 
Thanks, but I found an alternative by creating mySQL procedures instead of functions.

Code:

CREATE PROCEDURE procedure_name()
BEGIN
SELECT fiend_id, field_name FROM table_name ORDER BY field_id;
END$$


Thanks anyway!

Rama 10Apr2009 18:04

Re: PostgreSQL into MySQL
 
...and called it this way:

$sql = 'CALL procedure_name()';


All times are GMT +5.5. The time now is 23:48.