[英]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.