Lists: | pgsql-hackers |
---|
From: | Itagaki Takahiro <itagaki(dot)takahiro(at)gmail(dot)com> |
---|---|
To: | PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | How to rename each field in ROW expression? |
Date: | 2010-11-15 10:27:25 |
Message-ID: | AANLkTikYqoC1VzjmdSM4hvnHoXDRexG7ZOajp6=P6f9G@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
We can rename each field in VALUES clause:
=# SELECT * FROM (VALUES(123, 'ABC', NULL)) AS t(a,b,c);
a | b | c
-----+-----+---
123 | ABC |
(1 row)
But I cannot find ways for ROW expression to do the same thing:
=# SELECT ROW(123, 'ABC', NULL) AS (a,b,c);
ERROR: syntax error at or near "("
LINE 1: SELECT ROW(123, 'ABC', NULL) AS (a,b,c);
^
=# SELECT (ROW(123, 'ABC', NULL)).*;
ERROR: record type has not been registered
Is it possible to change names fields in ROW?
We can use CREATE TYPE AS on ahead, but I'd like to
change names of ROW expression in ad-hoc queries.
--
Itagaki Takahiro
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Itagaki Takahiro <itagaki(dot)takahiro(at)gmail(dot)com> |
Cc: | PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: How to rename each field in ROW expression? |
Date: | 2010-11-15 15:18:48 |
Message-ID: | 13938.1289834328@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Itagaki Takahiro <itagaki(dot)takahiro(at)gmail(dot)com> writes:
> Is it possible to change names fields in ROW?
> We can use CREATE TYPE AS on ahead, but I'd like to
> change names of ROW expression in ad-hoc queries.
Why? It's an anonymous type, you shouldn't care about names.
If you do, make a real named rowtype.
regards, tom lane
From: | Itagaki Takahiro <itagaki(dot)takahiro(at)gmail(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: How to rename each field in ROW expression? |
Date: | 2010-11-15 23:41:55 |
Message-ID: | AANLkTim1n3skp9u0hu_F8sQKEjaXdDgfzxsSd5QrnRRG@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On Tue, Nov 16, 2010 at 00:18, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Why? It's an anonymous type, you shouldn't care about names.
> If you do, make a real named rowtype.
If so, we cannot extract any fields in an anonymous type, right?
We cannot lookup fields with (an anonymous type).name because
the fields have no names.
=# SELECT (ROW(123, 'ABC', NULL)).*;
ERROR: record type has not been registered
--
Itagaki Takahiro