Home:ALL Converter>Join a Column with SELECT query in PostgreSQL

Join a Column with SELECT query in PostgreSQL

Ask Time:2012-12-06T21:24:35         Author:jacktrades

Json Formatter

Need this equivalent outcome on PostgreSQL on this MySQL query.

select id, 'ID1' from supportContacts

Idea is to Join a Column with table name and row values equals to ID1.

Executing the same query on PostgreSQL gives the desired row values but gives ?column? uknown as column name.

Which PostgreSQL query will give the exact output?

Author:jacktrades,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/13744580/join-a-column-with-select-query-in-postgresql
Erwin Brandstetter :

Add a column alias to assign a name of your choosing. Else the system applies defaults.\nTo assign a type, use an explicit cast. I cast to text here:\n\nSELECT id, 'ID1'::text AS \"ID1\" FROM supportContacts\n\n\nOr use the SQL standard cast() to make it portable:\n\nSELECT id, cast('ID1' AS varchar) AS \"ID1\" FROM \"supportContacts\"\n\n\nFor portability, make sure that MySQL runs with SET sql_mode = 'ANSI'.\n\nAlso, unquoted CaMeL-case names like supportContacts are cast to lower case in PostgreSQL. Use \"supportContacts\" or supportcontacts depending on the actual table name.\n\nStart by reading the excellent manual here for basics about identifiers.",
2012-12-06T13:33:11
yy