Same column names in a subresult table

From: Durumdara <durumdara(at)gmail(dot)com>
To: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Same column names in a subresult table
Date: 2021-05-14 11:28:40
Message-ID: CAEcMXhkvRDM3eGqgA4jH6TCE3gELYTeRP+72nWYG2KUwxb-MQQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello!

I have a big "WITH QUERY", with many subqueries.

I have a date field, named "XDate".

In the middle I duplicated this field:

...
midqry1 as (
select coalesce(XDate , '0001-01-01'), * from prevqry
),
midqry2 as (
select ArtID, max(XDate) as Max_XDate from midqry1
where acq = True
group by ArtID
)
...

Result: ERROR: column reference "XDate" is ambiguous

As I remember, InterBase simply renamed the second XDate to XDate_1 or
XDate1.
But as I see the PGSQL keeps the first and second too (which comes with an
asterisk "*").

So in midqry1 I have two XDate columns.

If the two XDates came from different tables, I can use the table prefix.

But now they are in one table.

Is there any way to suppress the original field?

Or say to PGSQL to skip the first XDate field?

Like select t.* (EXCEPT XDate) from t

Or can I reference them by the order?

Ok, I can solve this problem by renaming the new first XDate, but I want to
know is there any solution to this problem?

Thank you for any help, info, example!

Best regards
dd

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Rory Campbell-Lange 2021-05-14 11:57:12 Re: Same column names in a subresult table
Previous Message Ron 2021-05-14 09:01:27 Re: Question about integer out of range in function