Why does a PostgreSQL SELECT query return different results when a schema name is specified? -


i have postgresql database table 4 columns - labeled column_a, column_b, etc. want query table simple select query:

select * table_name; 

i handful of results looking like:

column_a | column_b ---------+--------- 'a value'|'b_value' 

but when use query:

select * schema_name.table_name; 

i full result:

column_a | column_b | column_c | column_d ---------+----------+----------+--------- 'a value'|'b value' |'c value' |'d_value'  

columns c , d added @ later date, after initial table creation. question is: why database ignore later columns when schema name left out of select query?

table names not unique within database in postgres. there can number of tables named 'table_name' in different schemas - including temporary schema, comes first unless explicitly list after other schemas in search_path. obviously, there multiple tables named table_name. must understand role of search_path interpret correctly:

the first table lives in schema comes before schema_name in search_path (or schema_name not listed there @ all). unqualified table name resolved table (or view). check list of tables named 'table_name' current role has access in database:

select *   information_schema.tables   table_name = 'table_name'; 

views special tables attached rule internally. play same role regular table , included in above query. details:


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -