Visibility of data from table inherits function

2022-01-02 Thread ourdiaspora
Recipients,

A table was created:

CREATE TABLE exampletable (
name varchar(200)
);

Table 'exampletable' _already_ contains data, e.g. 'Jane Bloggs'

A new table was created with inheritance of 'exampletable':

CREATE TABLE exampletablechild (dates DATE) INHERITS (exampletable);
SET DATESTYLE TO 'SQL, EUROPEAN';

\d exampletablechild

"
...
Inherits: exampletable
"

SELECT name FROM exampletablechild;
"
name
--
(0 rows)
"

SELECT name FROM exampletable;

"
name
--
 jane bloggs
"

Please could someone explain why the data in the table 'exampletable' is not 
visible from the query using the child table?

Does not 'INHERIT' function apply to the data of the precedent parent table?






Re: Visibility of data from table inherits function

2022-01-02 Thread David G. Johnston
On Sunday, January 2, 2022, ourdiaspora  wrote:

>
>
> Please could someone explain why the data in the table 'exampletable' is
> not visible from the query using the child table?
>
> Does not 'INHERIT' function apply to the data of the precedent parent
> table?
>
>
Apparently not…and you can readily confirm this yourself by reading the
relevant documentation.

David J.


Re: Visibility of data from table inherits function

2022-01-02 Thread Francisco Olarte
On Sun, 2 Jan 2022 at 13:23, ourdiaspora  wrote:
> CREATE TABLE exampletable (
> name varchar(200)
> );
...
> CREATE TABLE exampletablechild (dates DATE) INHERITS (exampletable);
...
> Please could someone explain why the data in the table 'exampletable' is not 
> visible from the query using the child table?
> Does not 'INHERIT' function apply to the data of the precedent parent table?

No, it works the other way round, somehow like OO inheritance.

When you query a table you will see its data and all of the tables
that inherit from it.

Take a look at https://www.postgresql.org/docs/14/tutorial-inheritance.html
. Ii is not shown there, but you canot see cities through capitals
because they do not have state, so they do not match the structure,
but you can see capitals through cities.

Inherits does not copy things. LIKE on creation does, but AFAIK it can
copy nearly everything except data.

Francisco Olarte.




Re: Visibility of data from table inherits function

2022-01-02 Thread ourdiaspora
On Sunday, January 2nd, 2022 at 3:54 PM, Francisco Olarte 
 wrote:
>
> Inherits does not copy things. LIKE on creation does, but AFAIK it can
>
> copy nearly everything except data.
>

Thanks, had read that part of the documentation.

So far it seems that functions 'joins' may be used to view data, whilst the 
functions 'views' is unable to be used with data entry.

Please, any suggestions of an alternative function to use?






Re: Visibility of data from table inherits function

2022-01-02 Thread Adrian Klaver

On 1/2/22 11:41, ourdiaspora wrote:

On Sunday, January 2nd, 2022 at 3:54 PM, Francisco Olarte 
 wrote:


Inherits does not copy things. LIKE on creation does, but AFAIK it can

copy nearly everything except data.



Thanks, had read that part of the documentation.

So far it seems that functions 'joins' may be used to view data, whilst the 
functions 'views' is unable to be used with data entry.


They are not functions. A join is a clause in a query. A view is an 
object that can be created and then used like a table.


Views can be used for data entry, see:

https://www.postgresql.org/docs/current/sql-createview.html

Search for section:

Updatable Views



Please, any suggestions of an alternative function to use?







--
Adrian Klaver
adrian.kla...@aklaver.com




Re: Visibility of data from table inherits function

2022-01-02 Thread Achilleas Mantzios

Στις 2/1/22 2:23 μ.μ., ο/η ourdiaspora έγραψε:


Recipients,

A table was created:

CREATE TABLE exampletable (
name varchar(200)
);

Table 'exampletable' _already_ contains data, e.g. 'Jane Bloggs'

A new table was created with inheritance of 'exampletable':


Please could someone explain why the data in the table 'exampletable' is not 
visible from the query using the child table?

Does not 'INHERIT' function apply to the data of the precedent parent table?
Think of it as a list of Numbers in java. Assume you are looking for 
Double's, then you transverse the list looking for only Doubles, then 
for Integers and you get only Integers, then for Numbers and you get the 
whole list. This is the same concept in pgsql inheritance.  A row of 
"type"  exampletablechild is a row of "type" exampletable, but not vice 
versa: A row of exampletable is NOT a row of exampletablechild. 
Selecting directly from exampletablechild it should return to you only 
exampletablechild and below.