Domanda

I am working on a legacy project where tables and columns have been through multiple naming conventions and it is a little difficult to find what is relevant.

I wish I could create aliases on the columns so that we can start to implement good practice for new development, while not impacting the old development.

Ideally, if I have table customer which has customer_key and fname, i could alias the first one to id and when i run

SELECT * FROM customer WHERE customer_key = 1 

or

SELECT * FROM customer WHERE id = 1 

I get the same name.

I use both PostgreSQL and Informix, but this is more relevant to PostgreSQL here.

È stato utile?

Soluzione

You can create views on problem tables, like that:

create view customers as
  select customer_key as id, 
         -- ... some other fields 
         fname as name 
    from customer 
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top