Missing SELECT INTO ... DEFAULT VALUES in plpgsql for composite t ypes

From: "Passynkov, Vadim" <Vadim(dot)Passynkov(at)pathcom(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Missing SELECT INTO ... DEFAULT VALUES in plpgsql for composite t ypes
Date: 2004-11-22 16:43:44
Message-ID: C8C8E7457059D5119E4700D0B765DCB8016AA914@sinope.inside.pathcom.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi all

Just self-explanatory code below

-- var1 with default value.
CREATE DOMAIN var1_type AS pg_catalog.text
DEFAULT 'udp'::pg_catalog.text
CONSTRAINT "var1_const"
CHECK ( VALUE IS NOT NULL AND ( VALUE = 'tcp'::pg_catalog.text OR VALUE =
'udp'::pg_catalog.text ) );

-- var2 without default
CREATE DOMAIN var2_type AS pg_catalog.int4
CONSTRAINT "var2_const"
CHECK ( VALUE IS NOT NULL AND VALUE > 0 );

-- Let's create composite type foo
CREATE TABLE foo (
var1 var1_type,
var2 var2_type
);

-- and let's create constructor for it
CREATE OR REPLACE FUNCTION foo ( int4 ) RETURNS foo AS '
DECLARE
this foo;
BEGIN
/*
* I dont want hard coded default
* value for this.var1 here
* but SELECT INTO this DEFAULT VALUES not possible in plpgsql
*/
-- SELECT INTO this DEFAULT VALUES;
this.var2 := $1;
RETURN this;
END;
' LANGUAGE 'plpgsql' IMMUTABLE STRICT;

SELECT * from foo ( 2 );
var1 | var2
------+------
| 2
(1 row)

but I want
var1 | var2
------+------
udp | 2
(1 row)

Is anybody know any solution for this?

--
Vadim Passynkov

Browse pgsql-sql by date

  From Date Subject
Next Message Mike Rylander 2004-11-22 16:54:30 Re: Recursive SETOF function
Previous Message Richard Rowell 2004-11-22 15:18:13 Recursive SETOF function