composite type insert - Mailing list pgsql-general

From Ron Peterson
Subject composite type insert
Date
Msg-id 20061119022132.GA18326@yellowbank.com
Whole thread Raw
Responses Re: composite type insert  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
I'm trying to understand how to insert a composite type value.  I'm
having trouble with the last sql statement below.  It errors out with:

ERROR:  cannot cast type record to atype

How should I create a composite type value out of columns a and b in
table tt that I can insert into table atable?

CREATE TYPE atype AS (
  acol
    TEXT,
  bcol
    TEXT
);

CREATE TABLE atable (
  aval
    atype
);

CREATE TEMP TABLE
  tt
AS
  SELECT 'aaa'::text AS a, 'bbb'::text AS b;

INSERT INTO
  atable
SELECT
  ROW(a, b)
FROM
  tt;

Thanks as always.

--
Ron Peterson
https://www.yellowbank.com/

pgsql-general by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: User-defined-type in C crashing PostgreSQL server: What am I doing wrong?
Next
From: John Meyer
Date:
Subject: phpPgAdmin, cannot connect to server