PostgreSQL: accessing relation with "public" schema name [duplicate] - postgresql

This question already has answers here:
I keep getting the error "relation [TABLE] does not exist"
(1 answer)
Cannot simply use PostgreSQL table name ("relation does not exist")
(18 answers)
Setting schema in PostgreSQL JDBC doesn't seem to work
(1 answer)
Closed 4 years ago.
Using PostgreSQL 9.6, I created new table using pgAdmin under public schema.
But to access the table, I can't use just the table name. If I use public."Book" then only the table is accessible.
thrillio=# show search_path;
search_path
-------------
public
(1 row)
\d+ shows all the tables..
thrillio=# \d+
List of relations
Schema | Name | Type | Owner | Size | Description
--------+-------------------+-------+----------+------------+-------------
public | Book | table | postgres | 8192 bytes |
public | KidFriendlyStatus | table | postgres | 0 bytes |
public | Movie | table | postgres | 8192 bytes |
public | User | table | postgres | 8192 bytes |
public | Weblink | table | postgres | 8192 bytes |
(5 rows)
thrillio=# select * from Book;
ERROR: relation "book" does not exist
LINE 1: select * from Book;
^
thrillio=# select * from public."Book";
id | title | profileUrl | publicationYear | publisher | authors | genre | amazonRating
----+-------+------------+-----------------+-----------+---------+-------+--------------
(0 rows)
is this expected? Anything I need to change the search_path to fix this?

Related

Postgresql difference between \dt+ and count rows

I'm running at now DMS (FULL LOAD, ONGOING REPLICATION) replication and I would like to check difference of rows between clusters A and B. and How B is delayed against A.
Database engine is postgresql 11(A) and postgresql14(B)
I run \dt+ on A:
List of relations
Schema | Name | Type | Owner | Persistence | Size | Description
--------+----------+-------+--------+-------------+-------+-------------
public | x | table | example | permanent | 73 GB |
(1 row)
and on B:
List of relations
Schema | Name | Type | Owner | Persistence | Access method | Size | Description
--------+----------+-------+--------+-------------+---------------+-------+-------------
public | x | table | example | permanent | heap | 14 GB |
I was surprised by the difference in size, which is huge, so I run the count on reader instance of this clusters:
reader A:
=> Select count(*) FROM X;
count
----------
47830564
(1 row)
reader B:
=> Select count(*) FROM X;
count
----------
47830564
(1 row)
And looks okay, but I don't understand why the difference in size is so big.
DMS is an aws service which is reinserting the rows in batches from A to B.

Using postgres table description

In postgres while listing the relation with \dt+ new columns 'size' and 'Description' column are added. As the name suggests Description can we use to store the description of the table, if yes how?
# \dt
List of relations
Schema | Name | Type | Owner
--------+---------+-------+-------
drs | Records | table | rho
drs | Reports | table | rho
(2 rows)
# \dt+
List of relations
Schema | Name | Type | Owner | Size | Description
--------+---------+-------+-------+------------+-------------
drs | Records | table | rho | 8192 bytes |
drs | Reports | table | rho | 0 bytes |
(2 rows)
This can be defined using the comment statement:
comment on table drs."Reports" is 'This table stores reports';

postgREST can find relation

I'm trying to set up postgREST. Have been following the tutorial at http://postgrest.org/en/v5.1/tutorials/tut0.html. Here is what I see. First, the schemas:
entercarlson=# \dn
List of schemas
Name | Owner
--------+---------
api | carlson
public | carlson
Then a table:
carlson=# \d api.todos
Table "api.todos"
Column | Type | Collation | Nullable | Default
--------+--------------------------+-----------+----------+---------------------------------------
id | integer | | not null | nextval('api.todos_id_seq'::regclass)
done | boolean | | not null | false
task | text | | not null |
due | timestamp with time zone | | |
Indexes:
"todos_pkey" PRIMARY KEY, btree (id)
Finally, some data:
carlson=# select * from api.todos;
id | done | task | due
----+------+-------------------+-----
1 | f | finish tutorial 0 |
2 | f | pat self on back |
(2 rows)
But then I get this:
$ curl http://localhost:3000/todos
{"hint":null,"details":null,"code":"42P01","message":"relation
\"api.todos\" does not exist"}
Which is consistent with this:
carlson=# \d
Did not find any relations.
What am I doing wrong?
PS. I don't see which database this schema belongs to
Seems you're targeting the wrong database, check the db-uri config value and make sure this uri contains the api.todos table through psql.
Also, want to clarify that the search_path is modified by PostgREST on each request, so if you ALTER your connection user search_path it'll have no effect on the schemas PostgREST searches.

Postgres: How to view contents of a table? [duplicate]

This question already has answers here:
Cannot simply use PostgreSQL table name ("relation does not exist")
(18 answers)
postgres - select * from existing table - psql says table does not exist
(3 answers)
currval Function in PostgreSQL complaining that "column does not exist"
(1 answer)
PostgreSQL "Column does not exist" but it actually does
(6 answers)
Error: Column does not exist
(1 answer)
Closed 5 years ago.
Here is what I have?
contacts=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+------------+------------+-----------------------
contacts | postgres | UTF8 | en_US.utf8 | en_US.utf8 |
postgres | postgres | UTF8 | en_US.utf8 | en_US.utf8 |
template0 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
contacts=# \d
List of relations
Schema | Name | Type | Owner
--------+---------------+-------+----------
public | SequelizeMeta | table | postgres
(1 row)
contacts=# select * from SequelizeMeta;
ERROR: relation "sequelizemeta" does not exist
LINE 1: select * from SequelizeMeta;
^
contacts=# contacts=# select * from public.SequelizeMeta;
ERROR: relation "public.sequelizemeta" does not exist
LINE 1: select * from public.SequelizeMeta;
^
How do I read the contents of SequelizeMeta?
Thanks
Based on wildplasser command, this is what I had to do. Thank you wildplasser
contacts=# select * from "SequelizeMeta";
name
------
(0 rows)

How can I get all roads/ways from an osm2pgsql shema?

I'm trying to create a list of every road in Germany (With latitude,longitude and Streetname).
So far I have imported the german osm file with the help of osm2pgsql into a postgres Database.
So what I am looking for is a query that allows me to query every road.
First of all I would suggest using the psql tool. So assuming your database is called gis enter the following command at the terminal:
psql gis
from within the psql tool you can query the database but first it is a g0od idea to get an idea of which tables were created by osm2psql, do this be entering:
\d
this should give you output like this:
List of relations
Schema | Name | Type | Owner
--------+--------------------+-------+----------
public | geography_columns | view | postgres
public | geometry_columns | table | gis
public | planet_osm_line | table | user
public | planet_osm_nodes | table | user
public | planet_osm_point | table | user
public | planet_osm_polygon | table | user
public | planet_osm_rels | table | user
public | planet_osm_roads | table | user
public | planet_osm_ways | table | user
public | spatial_ref_sys | table | gis
(10 rows)
There we can see a likely looking candidate in planet_osm_roads, enter:
\d planet_osm_roads
this will show you the structure of the roads table, which will look something like this:
Table "public.planet_osm_roads"
Column | Type | Modifiers
--------------------+----------+-----------
osm_id | bigint |
access | text |
addr:housename | text |
addr:housenumber | text |
addr:interpolation | text |
admin_level | text |
aerialway | text |
aeroway | text |
amenity | text |
....
waterway | text |
wetland | text |
width | text |
wood | text |
z_order | integer |
way_area | real |
way | geometry |
From there we can formulate our query. Something like:
SELECT osm_id,name,way FROM planet_osm_roads LIMIT 1;
will get you the first road in the list. The documentation at http://www.postgresql.org/docs/ will help you with decoding the way geometry string.