From: serviciotdf <serviciotdf@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Translate Function PL/pgSQL to SQL92
Date: Wed, 15 Dec 2010 22:22:12 -0300
Message-ID: <4D0969C4.5050205@gmail.com> (raw)
Hello,
I have a Function in PL/pgSQL and I need to translate it to SQL92, but
I'm stuck.
###
CREATE OR REPLACE FUNCTION pruebas(varchar, varchar, integer)
RETURNS SETOF personal AS
$delimiter$
BEGIN
PERFORM id from documentos WHERE descripcion = $1;
IF NOT FOUND THEN
INSERT INTO documentos(descripcion) VALUES($1);
END IF;
INSERT INTO personal(nombre,idtipodocumento,numdoc)
VALUES($2, (SELECT id from documentos WHERE descripcion = $1), $3);
END;
$delimiter$
LANGUAGE plpgsql;
###
Tables
CREATE TABLE documentos
id serial NOT NULL,
descripcion character varying(60),
CONSTRAINT pkdocumentos PRIMARY KEY (id)
CREATE TABLE personal
id serial NOT NULL,
nombre character varying(60),
idtipodocumento smallint NOT NULL,
numdoc integer,
CONSTRAINT pkpersonal PRIMARY KEY (id),
CONSTRAINT fkpdoc FOREIGN KEY (idtipodocumento)
REFERENCES documentos (id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE NO ACTION,
CONSTRAINT unqnumdoc UNIQUE (idtipodocumento, numdoc)
Thanks and greetings for all
Marcelo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: serviciotdf@gmail.com
Subject: Re: Translate Function PL/pgSQL to SQL92
In-Reply-To: <4D0969C4.5050205@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox