Reputation: 1428
In Excel we can create reference cell (e.g. A2 = A1 + 1). Or we create a reference cell on other sheet.
On postgres I would like create a reference cell to another table. Is it possible? How could I achieve that?
Thanks in advance
Upvotes: 1
Views: 211
Reputation: 22905
RDBMS uses a different approach. There are queries and data. When you query something, it is natural to perform extra calculations on the data. In your case this is a simple arythmetic function.
Say, you have a table:
CREATE TABLE tab (
id integer PRIMARY KEY,
a1 integer
);
Now, to achieve your case you can do the following:
SELECT id,
a1,
a1+1 AS a2
FROM tab;
As you can see, I'm using existing columns in the formula and assign the result a new alias a2
.
I really recommend you to read the Tutorial and SQL Basics from the official PostgreSQL documentation, along with some SQL introduction book.
Upvotes: 1