pgAdmin error - relation "[name of function/Views/Trigger Functions]" does not exist - postgresql

I'm just new to pgAdmin, so I don't really know what causes these errors:
ERROR: relation "ongoingprojects" does not exist
LINE 1: SELECT * FROM ongoingProjects;
^
********** Error **********
ERROR: relation "ongoingprojects" does not exist
SQL state: 42P01
Character: 15
Even if the function/view exists in the schema. Why does it give that error? And what should I do to fix it?

Pay careful attention to the error message:
ERROR: relation "ongoingprojects" does not exist
Note that it is complaining about ongoingprojects when your SQL talks about ongoingProjects. You probably created the table with something like:
create table "ongoingProjects" ( ...
PostgreSQL folds all identifiers (table names, column names, ...) to lower case unless they are double quoted. Once you've created the table as "ongoingProjects", you'll have to double quote the name everywhere and exactly match that case:
select * from "ongoingProjects";
The usual practice with PostgreSQL is to create tables with unquoted names in lower case with word separated using underscores:
create table ongoing_projects ( ...
so that you don't have worry about quoting.
Here is the link to the relevant part of the manual

For me the issue was having a schema named differently than the database.
Two solutions:
1) Modify schema name to match db name
or
2) Prepend table in query with schema name, eg: SELECT * FROM my_schema.ongoingProjects;

Related

Issue with basic create statements in postgreSQL

I've used the psql module to create a new database using the following syntax:
CREATE DATABASE fish
I can open the database. However, when I try to create tables or columns it gives me a syntax error for the following message.
CREATE TABLE salmon;
this is the error message:
ERROR: syntax error at or near ";"
LINE 1: CREATE TABLE species;
I've checked a lot of online postgreSQL resources and they haven't been of much help. To the best of my knowledge, I haven't messed up the syntax. Thanks.
you can use this syntax for empty table:
create table salmon();
You must create atleast one column in a table:
CREATE TABLE salmon ( column_name data_type ...........);
Postgres create table link: https://www.postgresql.org/docs/9.1/static/sql-createtable.html
You can't create an empty table - it must have at least one column. E.g.:
CREATE TABLE salmon (name VARCHAR(10));
psql is not a module. Please read https://www.postgresql.org/docs/current/static/app-psql.html
you odn't open a database - you connect to it.
Establishes a new connection to a PostgreSQL server
https://www.postgresql.org/docs/current/static/sql-createtable.html
{ column_name | ( expression ) }
Either column list (create table a (a int);) or expression (create table b as select now() time_column) is obligatory part.

INSERT with alias name is not working on PostgreSQL

SQL Query on PostgreSQL:
insert into TOKEPOOLAMT (TOKEPOOLAMT.TOKEPOOLAMTID,TOKEPOOLAMT.TOKERULEID)
values (151, 176);
Giving error:
com.edb.util.PSQLException:
ERROR: column "tokepoolamt" of relation "tokepoolamt" does not exist
But:
insert into TOKEPOOLAMT (TOKEPOOLAMTID,TOKERULEID) values (151, 176);
is working fine.
Can anybody explain why alias name with column in insert statement not working?
There are no aliases involved here. Your error is that column names in the column list of an INSERT command cannot be table-qualified. #pozs already provided the fitting quote from the manual in his comment.
I don't think it's an issue of case. I tried with both the cases.
That's missing the point. In Postgres, identifiers are folded to lower case unless double-quoted. If you double-quoted a name at creation time you preserved a case sensitive spelling and need to double-quote for the rest of the object's life - unless it was a legal, lower-case name to begin with, then quoting won't make a difference. Details:
Are PostgreSQL column names case-sensitive?

How to rename a PostgreSQL table by prefixing an underscore?

I have a database which relies on a PostgreSQL system and I am maintaining it so I want to change tables and overall scheme. For this I thought of renaming the older tables so they have an underscore as a prefix. But this is not working:
DROP TABLE IF EXISTS _my_table; -- table does not exists, this does nothing
ALTER TABLE my_table
RENAME TO _my_table;
The result of the query is the following:
NOTICE: table "_my_table" does not exist, skipping ERROR:
type "_my_table" already exists
********** Error **********
ERROR: type "_my_table" already exists SQL state: 42710
The '_my_table' table is a fake name, but this error is reproduced by actually creating a '_my_table' table and running the same script above.
I am using pgAdmin III to access the database tables and making use of it's 'rename' operation results in the same error.
The postgresql documentation for the alter table method does not tell me explicitly about this particular problem: http://www.postgresql.org/docs/9.3/static/sql-altertable.html
Do I really need to use a prefix like 'backup' instead of '_' ? Or would it be possible to rename it, my only interest is to maintain the information in the table whilst having the minimal changes to the table name.
You cannot simply put an underscore in front of the existing table name because every table has an associated type that is... a leading underscore before the table name. You can verify this in the pg_catalog.pg_type table. Having a table name start with an underscore is not the problem, but the internal procedure is that a new table is created physically from the old table and only when the old table is no longer in use by other processes will the old table, and its associated type, be deleted. Hence the error referencing the type (and not the relation).
So if you really want to keep the old name with an underscore, you should first ALTER TABLE to some temp name and then ALTER TABLE to the underscore + original name. Or simply use another prefix...
ERROR: type "_my_table" already exists
Both tables and types are stored in the internal table pg_class. A unique name is required, that's why you get this error message.

Double quote in the name of table in select query of PostgreSQL

I am running following simple select query in PostgreSQL:
SELECT * FROM "INFORMATION_SCHEMA.KEY_COLUMN_USAGE"
It gives me following error report:
ERROR: relation "INFORMATION_SCHEMA.KEY_COLUMN_USAGE" does not exist
LINE 1: SELECT * FROM "INFORMATION_SCHEMA.KEY_COLUMN_USAGE"
^
********** Error **********
ERROR: relation "INFORMATION_SCHEMA.KEY_COLUMN_USAGE" does not exist
SQL state: 42P01
Character: 15
But when I am running the following query it runs successfully:
SELECT * FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
Again when I select from a table created by me the situation is reversed. Following one fails:
SELECT * FROM countryTable
while following one runs successfully.
SELECT * FROM "countryTable"
Why is it happening? What is the problem?
You probably created your table so:
CREATE TABLE "countryTable" (
id SERIAL NOT NULL,
country TEXT NOT NULL,
PRIMARY KEY(id)
);
Which create a tablespace wrapped in "", you shouldn't use double quote in general in postgres for table names or columns, try without double quotes:
CREATE TABLE countryTable (
id SERIAL NOT NULL,
country TEXT NOT NULL,
PRIMARY KEY(id)
);
An then you can use this query you already have SELECT * FROM countryTable
While my personal advice is to use legal, lower-case names exclusively and never use double-quote, it is no problem per se.
When you look at the table definition in psql (\d tbl), or at table names in the system catalog pg_class or column names in pg_attributes or any of the information schema views, you get identifiers in their correct spelling (and with all other oddities that may have been preserved by double-quoting them). You can use quote_ident() to quote such names automatically as needed - it only adds double quotes if necessary.
Postgres itself isn't foolish enough to use CaMeL case names. All objects in the information schema or in the system catalog are lower-cased (the names of the system tables and columns, not the names of user tables they carry as data).
Start at the basics, read the manual about identifiers.

The relation does not exist in postgresql

I am have big problem with Postgresql.
I'm trying to insert record to postgres.
But i had error:
The relation "member_orderinfo2" does not exist. But this table had exist when i'm insert record.
This is my query to insert
insert into "member_orderinfo2"(order_id,slim_code,order_date,customer_order_number,ship_date,deliver_company,deliver_number,deliver_address,product_code,product_name,amount,unit_price,total_cost,order_customer_name,ship_status) values
( '30059078','4170906','20131118','15754727-03直送','0','メーカー直送','','京都府綾部市味方町1京セラコミュニケーションシステム','0996381','RD151-50SN(ジユウリヨウダ','5','5120.00','25600','梶野様','入荷待' )
What is error ???
It looks like case sensitivity issue.
You used a double quotes for table name - "member_orderinfo2" - it means so table have to be named exactly member_orderinfo2 with only lower chars. Double quotes are used for case sensitive identifiers. Usually better don't use it when it is possible - are necessary when used identifier is keyword - so don't use case sensitive identifiers and don't use keywords as identifiers.