I am not able to query the contents of the Notification_log table.
The table is in a Postgres 9.2 instance that stores my hive metadata.
hive=# SELECT table_catalog, table_schema, table_name
FROM information_schema.columns where table_name = 'NOTIFICATION_LOG';
table_catalog | table_schema | table_name
---------------+--------------+------------------
hive | public | NOTIFICATION_LOG
hive | public | NOTIFICATION_LOG
hive | public | NOTIFICATION_LOG
hive | public | NOTIFICATION_LOG
hive | public | NOTIFICATION_LOG
hive | public | NOTIFICATION_LOG
hive | public | NOTIFICATION_LOG
hive | public | NOTIFICATION_LOG
hive | public | NOTIFICATION_LOG
(9 rows)
hive=# select * from NOTIFICATION_LOG;
ERROR: relation "notification_log" does not exist
LINE 1: select * from NOTIFICATION_LOG;
^
hive=# show search_path;
search_path
-------------
public
(1 row)
hive=#
PostgreSQL names are case sensitive. You need to surround that table name in quotes. This should work:
select * from "NOTIFICATION_LOG"
Related
I took postgresql dump and restore it in another db. I am trying to change the permission of the table in the secondary db. But I am not change the permission can't evn view individual table.
Whenever I list all the tables in a Scheme I can get the results but when i search for individual tables getting below error.
select \* from pg_tables where schemaname='testing';
schemaname | tablename | tableowner | tablespace | hasindexes | hasrules | hastriggers | rowsecurity
\------------+-----------------+------------+------------+------------+----------+-------------+-------------
testing | chatting | postgres | | t | f | t | f
testing | report | postgres | | t | f | f | f
select chatting from pg_tables where schemaname='testing';
ERROR: column "chatting" does not exist
LINE 1: select channel from pg_tables where schemaname='testing';
Can someone help me on this? I would like to change the owner of all the tables in this schema to a different user.
Note: I haven't create the tables, it is part of the pg_dump.
The query that you should run is
select * from pg_tables where schemaname='testing' and tablename = 'chatting';
Newbie to Postgres so naive question here -
what is the difference between schemaname and tableowner?
https://www.postgresql.org/docs/8.3/view-pg-tables.html
schemaname -> Name of schema containing table
tableowner -> Name of table's owner
schemaname | tablename | tableowner
------------+---------------------+------------
admcdba | class_dim | postgres
admcdba | product_dim | postgres
admcdba | exch_84041_84057 | postgres
admcdba | exch_84041_84061 | postgres
admcdba | part_maint_log | postgres
(5 rows)
in above output schemaname and tableowner are different and hence trying to understand.
Appreciate your response in advance.
I'm trying to programatically generate code using jooq 3.12.3 with the following code, but the program runs successfully and no code is generated.
Configuration configuration =
new Configuration()
.withJdbc(
new Jdbc()
.withDriver("org.postgresql.Driver")
.withUrl("jdbc:postgresql://127.0.0.1:6666/postgres")
.withUser("<username>")
.withPassword("<correct password>"))
.withGenerator(
new Generator()
.withDatabase(
new Database()
.withName("org.jooq.meta.postgres.PostgresDatabase")
.withIncludes(".*")
.withExcludes("")
.withInputSchema("public"))
.withGenerate(
new Generate()
.withDaos(true)
.withDeprecated(false)
.withImmutablePojos(false)
.withPojosEqualsAndHashCode(true)
.withValidationAnnotations(true)
.withVarargSetters(false))
.withTarget(
new Target()
.withPackageName("com.package.data.jooq")
.withDirectory("src/main/java")));
GenerationTool.generate(configuration);
Some debugging info
\dt
List of relations
Schema | Name | Type | Owner
--------+-------------------+-------+----------
public | django_migrations | table | postgres
public | table1 | table | postgres
public | table2 | table | postgres
,
\l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
---------------+-------------------+----------+------------+------------+-----------------------------------------
cloudsqladmin | cloudsqladmin | UTF8 | en_US.UTF8 | en_US.UTF8 |
postgres | cloudsqlsuperuser | UTF8 | en_US.UTF8 | en_US.UTF8 |
,
SELECT table_catalog, table_schema, table_name
FROM information_schema.tables;
doesn't show public under table_schema
What could be the problem?
The problem was with permissions..
GRANT SELECT ON TABLE public.table1 TO user;
GRANT SELECT ON TABLE public.table2 TO user;
Solved the problem. After this the tables started showing up in
SELECT table_catalog, table_schema, table_name
FROM information_schema.tables;
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?
In Postgres, i created a UDT as follows
CREATE TYPE MY_TYPE AS ENUM ('FAILED', 'SUCCESS');
and in postgres cli, i can retrieve the UDT value back like
\dT+ MY_TYPE
which lists the details of the UDT, including its enum values under the 'Elements' column
EDIT: added result of "\dT+" command
postgres=# \dT+ status_type
List of data types
Schema | Name | Internal name | Size | Elements | Owner | Access privileges | Description
--------+-------------+---------------+------+----------+----------+-------------------+-------------
public | status_type | status_type | 4 | WAITING +| Postgres | |
| | | | STARTED +| | |
| | | | PAUSED +| | |
| | | | SUCCESS +| | |
| | | | FAILED | | |
Now, I am using JOOQ in a spring project, and want to get that UDT's value using JOOQ. Can anyone help me on how to get that done?
NOTE: I know that JOOQ generates the ENUM types when generating classes, But is that the only way to get the information i need?
Thanks!
I'm assuming you want to get a listing of all the enum literals from the database, dynamically. The SQL query that the jOOQ code generator uses for this similar to this:
SELECT n.nspname, t.typname, e.enumlabel, e.enumsortorder
FROM pg_enum e
JOIN pg_type t ON e.enumtypid = t.oid
JOIN pg_namespace n ON t.typnamespace = n.oid
ORDER BY n.nspname, t.typname, e.enumsortorder
Now, just run this query using jOOQ like any other query to get something like this (from the Sakila database):
nspname |typname |enumlabel |enumsortorder |
--------|------------|----------|--------------|
public |mpaa_rating |G |1 |
public |mpaa_rating |PG |2 |
public |mpaa_rating |PG-13 |3 |
public |mpaa_rating |R |4 |
public |mpaa_rating |NC-17 |5 |