pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Passynkov, Vadim <Vadim.Passynkov@pathcom.com>
To: pgsql-sql@postgresql.org
Subject: Missing SELECT INTO ... DEFAULT VALUES in plpgsql for composite t ypes
Date: Mon, 22 Nov 2004 11:43:44 -0500
Message-ID: <C8C8E7457059D5119E4700D0B765DCB8016AA914@sinope.inside.pathcom.com> (raw)

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



Message-ID: <C8C8E7457059D5119E4700D0B765DCB8016AA914@sinope.inside.pathcom.com>
Permalink:  ../C8C8E7457059D5119E4700D0B765DCB8016AA914@sinope.inside.pathcom.com/
Also on:    postgresql.org/message-id/C8C8E7457059D5119E4700D0B765DCB8016AA914@sinope.inside.pathcom.com

 · 

reply

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: Vadim.Passynkov@pathcom.com
  Subject: Re: Missing SELECT INTO ... DEFAULT VALUES in plpgsql for composite t ypes
  In-Reply-To: <C8C8E7457059D5119E4700D0B765DCB8016AA914@sinope.inside.pathcom.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