简体   繁体   English

我怎样才能让我的Postgresql SELECT从具有相同名称的列中返回数据?

[英]How can I have my Postgresql SELECT return data from columns with the same name?

In a SELECT call we are returning two different timestamps, but because each column is each called 'timetag' we cannot differentiate between them in the results. 在SELECT调用中,我们返回两个不同的时间戳,但是由于每一列都被称为“时间戳”,因此我们无法在结果中区分它们。 The obvious solution of renaming one of the columns will result in a large amount of refactoring which we want to avoid. 重命名其中一列的明显解决方案将导致大量重构,而我们希望避免这种重构。 Our query looks something like this: 我们的查询如下所示:

DECLARE
     p_cursor refcursor;

BEGIN

    OPEN p_cursor FOR


  SELECT table1.name,
         table1.timetag,
         table1.status,
        table2.timetag,
        table2.description

    FROM myFirstTable table1 LEFT OUTER JOIN mySecondTable table2 ON (<data's ids>),   
    ( 
<query details>
         );
    WHERE
<more query details>

  RETURN p_cursor;

END;

PS. PS。 excuse me if I have messed up the terms, I'm very new to databases. 请问,如果我弄乱了条款,对数据库我是新手。

Use the AS clause to "rename" some column just from the point of view of the results you receive (won't alter the DB) -- eg 仅从收到的结果的角度来看,使用AS子句“重命名”某些列(不会更改数据库)-例如

 SELECT table1.name,
         table1.timetag,
         table1.status,
        table2.timetag AS theothertimetag,
        table2.description

    FROM

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果所有元素都具有相同的名称,如何从XML检索数据? - How can I retrieve data from XML if all elements have the same name? 如何使用名称以相同前缀开头的 select 列? - How to select columns that have name beginning with same prefix? ADO - 如何从xls文件中选择两列或多列具有相同名称的列? - ADO - how to select column from xls file where two or more columns have the same name? 如何在数据网格中显示来自联接表和表1的数据,并且两个具有相同名称的列 - how to display data in data grid that is from joined tables and table 1 and two have columns with the same name 当所有列都具有相同名称时选择INTO - Select INTO when all columns have the same name 如何在 PostgreSQL 中从 WITH 中返回 EXCLUDED? - How can I return EXCLUDED from WITH in PostgreSQL? 如何在PostgreSQL中命名具有相同引用的不同列? - How to name different columns with the same reference in PostgreSQL? 如何从相同的数据和计算比率构造 2 列? - How can I construct 2 columns from the same data and compute ratio? 如何在我的表中指定我不能使用唯一或其他命令在 3 列中具有两个相同的值? - How Can I specify in my Table that I cannot have two same values in 3 columns with unique or other commands? 当我有2条具有相同ID的行时,如何选择具有特定数据的行? - How can I select lines with specific data when I have 2 lines with the same ID?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM