composite type insert

From: Ron Peterson <ron(dot)peterson(at)yellowbank(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: composite type insert
Date: 2006-11-19 02:21:32
Message-ID: 20061119022132.GA18326@yellowbank.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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/

Responses

Browse pgsql-general by date

  From Date Subject
Next Message John Meyer 2006-11-19 02:38:10 phpPgAdmin, cannot connect to server
Previous Message Josh Berkus 2006-11-18 23:34:31 Re: [GENERAL] Allowing SYSDATE to Work