grails postgres Message: ERROR: column this_.id does not exist - postgresql

grails with postgres for User domain.
Message: ERROR: column this_.id does not exist

Got the issue.
For User domain, I've postgres table as "user". So by default when it is trying to query user table, its not querying with "user.id". There is something wrong with postgres for "user" table.
So I updated my "user" table to "myapp_user" table. The problem got solved.

The word 'user' may be reserved by dbms.
static mapping = {
table '`User`'
password column: '`password`'
}

I think it's because table name user already occupied by defalut by Postgres. Try query w/ schema (public by default) like in phpPgAdmin:
SELECT * FROM "public"."user"

Related

Npgsql.PostgresException (0x80004005): 42703: column {schema} of relation {table} does not exist

I am trying to update a table in postgresql from C# .NET. getting error column {schema} of relation {table} does not exist, but at the same time I can able to select the table.
the user given the access other than super user. could you please help here?
I tried , direct execute of update in pgadmin tool for the same table and it is successful

Node Postgres (pg) library can't find relation of table

I have a Postgres DB that I need to modify. It is in my localhost. I am trying to use Node Postgres for it, but I am missing something out from the document.
const client = new Client({
user: 'postgreadmin',
host: 'localhost',
database: 'testdb',
password: 'somepassword',
port: 5433,
})
client.query('SELECT * FROM User', function(err, result) {
console.log
(result);
client.end();
});
The result shows return 'postgreadmin' as the user. Which is somewhat confusing. My database users should contain users like 'peter', 'mary' etc. The query seems to be running on the Postgres' configuration, and not on the db tables itself.
I tried other tables and the error is "no relation Merchant found'. I am not sure how to connect to the tables. My tables are under the schema call 'public'. So my question is do i need to specify the in pg's configuration to connect to the schema 'public'?
user is a function that returns the current database user, so select user will return the database user (and select * from user will as well).
If you did create a table with that name you need to use double quotes:
SELECT * FROM "User"
Note that quoted identifiers are case-sensitive. "User" is a different name than "user" or "USER". Check your database for the correct spelling. The same is probably true for "Merchant"
I strongly recommend you rename the table to something that is not a reserved keyword and does not collide with any internal function name.
For more details, see the manual:
https://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS

Fully qualified table name in postgreSQL select query

Simple question, however google can't help in reasonable time.
Ok, I have user table in my_db database with id column.
I want to run very simple query
SELECT id FROM user;
but it fails.
ERROR: column "id" does not exist LINE 1: SELECT id FROM user;
Can you imagine?
Ok, Running
SELECT * FROM user;
outputs the list of internal postgresql database users, which is nothing to do with my users, it's data from completely another [internal] database.
However, connection with my_db was established.
user is an internal function (and a reserved word) returning the currently logged in user.
To use that as your own identifier, you need to quote it:
select id
from "user"
or
select id
from public."user".
But you should really avoid reserved words as table names (or any name that requires quoting the identifier)
The following query can be rewritten as
SELECT id FROM my_db.public.user;
Where id is column, my_db is database, user is table name, public - is the schema. More about schemas:
http://www.postgresql.org/docs/9.1/static/ddl-schemas.html
So you don't have to rename the table name.

Problems while Using postgres_fdw

I m getting some problem while using postgres_fdw.
CREATE SERVER foreign_server
FOREIGN DATA WRAPPER postgres_fdw
OPTIONS (host '192.162.0.1', port '5432', dbname 'Test');
CREATE USER MAPPING FOR postgres
SERVER foreign_server
OPTIONS (user 'foreign_user', password 'password');
CREATE FOREIGN TABLE foreign_table (
id serial NOT NULL,
data text)SERVER foreign_server
OPTIONS (schema_name 'public', table_name 'employee');
select * from employee where user ='foreign_user'
Now I can see entries are made to pg_foreign_data_wrapper, pg_foreign_server and pg_foreign_table tables.
But how do I access employee table of remote system.
I mean select * from employee where user ='foreign_user' doesn't give any result. Though it has data in Employee table of remote system.
Any idea please?
But How do I access employee table of remote system.
You just need to access the foreign table, say "SELECT * FROM foreign_table;".
The procedure seems fine, but your foreign table doesn't have a column named "user", so your query must cause an error.
It would be better to show what has happened actually. Showing actual query and error messages helps us understand where the problem is.

How to include schema inf while using dblink in PostgreSQL?

All
I am trying to use dblink in PostgreSQL to run query on different databases. The following works if the table "user" is under the public schema:
select * from dblink(
'hostaddr=1.2.3.4 port=5434 dbname=dbname user=username password=password',
'select id from user')
as t1(
id bigint
);
However, I need to run the query on some other defined schemas. Does anyone know how to add the schema information in the above query? I can't figure it out from the PostgreSQL docs.
When you write SQL query like
SELECT id FROM user
PostgreSQL will resolve table name like user into fully qualified name like schema.tablename using schema search path, which by default is set to "$user",public.
In other words, user will resolve into public.user unless you tweaked server configuration.
However, you can specify schema explicitly in your statement, like this:
SELECT id FROM otherschema.user