Skip site navigation (1) Skip section navigation (2)

Missing SELECT INTO ... DEFAULT VALUES in plpgsql for composite types

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 types
Date: 2004-11-22 16:43:44
Message-ID: C8C8E7457059D5119E4700D0B765DCB8016AA914@sinope.inside.pathcom.com (view raw or flat)
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

pgsql-sql by date

Next:From: Mike RylanderDate: 2004-11-22 16:54:30
Subject: Re: Recursive SETOF function
Previous:From: Richard RowellDate: 2004-11-22 15:18:13
Subject: Recursive SETOF function

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group