is there a command for "AS" in postgres?

12,300

Solution 1

Yes. It's a reserved SQL key word in PostgreSQL. See Table C-1 at the linked documentation page.

It's typically used with column labels.

The AS keyword is optional, but only if the new column name does not match any PostgreSQL keyword (see Appendix C).

Solution 2

CREATE TABLE new_table AS SELECT subj, user FROM table_name

So, you new table will be ready.

Solution 3

1st: develop your query (SELECT field AS new_field FROM table WHERE etc....); 2nd: If it's run ok, copy it; 3rd: Go to VIEW and do that (CREATE OR REPLACE VIEW new_view AS (paste the query here)); 4th: Save the view and use it as table. 5th: enjoy it.

Solution 4

If you don't want to leave any changes in the schema, you can do something like this-

select new.* from (  
  select foo, bar from old  
) as new

Solution 5

"I want to make a select statement and store it as a new table name" --

CREATE VIEW view_name AS
SELECT subj, user AS "new" FROM table_name;
Share:
12,300
locoboy
Author by

locoboy

Love any kind of something that is about engineering

Updated on June 15, 2022

Comments

  • locoboy
    locoboy about 2 years

    I'm wondering if there is a command like AS for postgres. Does anyone know if postges has this ability? I've tried to google it but it's a very difficult question to google :P I want to make a select statement and store it as a new table name. I want to say something like:

    select subj, user as 'new' from table_name;