I have a table called assignments. I would like to be able to read/write to all the columns in this table using either assignments.column or homework.column, how can I do this?
I know this is not something you would normally do. I need to be able to do this to provide backwards compatibility for a short period of time.
We have an iOS app that currently does direct postgresql queries against the DB. We're updating all of our apps to use an API. In the process of building the API the developer decided to change the name of the tables because we (foolishly) thought we didn't need backwards compatibility.
Now, V1.0 and the API both need to be able to write to this table so I don't have to do some voodoo later to transfer/combine data later... We're using Ruby on Rails for the API.
Column AliasSELECT column_name AS alias_name FROM table; or, SELECT column_name alias_name FROM table; Below Syntax is for column alias used with expressions: SELECT expression alias_name FROM table; The primary use of column alias is to make the output of a query more meaningful.
In PostgreSQL, an alias is a temporary alternative name for columns, tables, views, materialized views, etc. in a query. Aliases are assigned during query execution and aren't stored in the database or on disk. By using column aliases, the query output can become more meaningful.
To create column aliases: Type: SELECT column1 [AS] alias1, column2 [AS] alias2, ... columnN [AS] aliasN FROM table; column1, column2, ..., columnN are column names; alias1, alias2, ..., aliasN are their corresponding column aliases; and table is the name of the table that contains column1, column2, ....
To rename a table, the PostgreSQL ALTER TABLE syntax is: ALTER TABLE table_name RENAME TO new_table_name; table_name. The table to rename.
With Postgres 9.3 the following should be enough:
CREATE VIEW homework AS SELECT * FROM assignments;
It works because simple views are automatically updatable (see docs).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With