I use psql to connect to the PostgreSQL database on terminal. If I run a simple select query,
select count(*) from my_schema.my_table;
I get the error:
ERROR: syntax error at or near "clear"
LINE 1: clear
UPDATE:
I cannot even execute a simple select query like select * from my_schema.my_table; or select * from my_table;. It gives me the error:
ERROR: relation "my_table" does not exist
LINE 1: select * from my_table;
Did you login into right database.
The error 'relation "my_table" does not exist' seems cause by wrong database selection.
For example:
psql -h localhost -p 5435 -U myuser -W <>
Related
The field employeeData is of type json.
Consider the query:
select * FROM "employees" where employeeData::text like '%someSampleHere%'
When I'm running the query inside Postgres it works perfect and I get the rows that I'm asking for.
However when I use it with KubeCTL and running this query outside of the PG App
psql -d employess_db -U postgres -c 'select * FROM "employees" where employeeData::text like 'someSampleHere';'
PG throws
ERROR: syntax error at or near "%"
LINE 1: select * FROM "employees" where employeeData::text like %someSampleHere%;
How can we fix it ?
Sounds like a quoting problem to me. You neglected to show your actual kubectl command line in your question, but this works for me without any errors:
kubectl exec postgres-pod -- psql -U postgres -d employees_db \
-c "select * from \"employees\" where employeeData::text like '%someSampleHere%'"
I am trying to run the below command on the unix console :
env 'PGOPTIONS=-c search_path=admin -c client_min_messages=error' psql -h hostname -U user -p 1111 -d platform -c "CREATE TEMP TABLE admin.tmp_213 AS SELECT * FROM admin.file_status limit 0;\copy admin.tmp_213(feed_id,run_id,extracted_date,file_name,start_time,file_size,status,crypt_flag) FROM '/opt/temp/213/list.up' delimiter ',' csv;UPDATE admin.file_status SET file_size = admin.tmp_213.file_size FROM admin.tmp_213 A WHERE admin.file_status.feed_id = A.feed_id and admin.file_status.file_name = A.file_name;"
I am getting the below error:
ERROR: syntax error at or near "\"
LINE 1: ...* FROM admin.file_status limit 0;\copy admi...
If I use the above command without a backslash before COPY, it gives me the below error:
ERROR: cannot create temporary relation in non-temporary schema
I am doing the above to implement the solution as mentioned here:
How to update selected rows with values from a CSV file in Postgres?
Your first error is because metacommands like \copy cannot be combined in the same line as regular commands when given with -c. You can give two -c options, with one command in each instead.
The second error is self-explanatory. You don't get to decide what schema your temp table goes to. Just omit the schema.
In ubuntu 16.04 when i want to run pg_dump it doesn't work i got this error syntax error. What is wrong ?
postgres=# pg_dump db_name > db_name1.sql
postgres-#
postgres-# ;
ERROR: syntax error at or near "pg_dump"
LINE 1: pg_dump db_name > db_name1.sql
^
postgres=#
pg_dump is not an SQL command.
It is a stand-alone utility, so you cannot run it from SQL query.
Follow the link for more information.
For your case: type \q<Enter> to quit from SQL-client and repeat your command again using shell prompt.
Remember you should use your SQL-credentials.
I.e.:
$ pg_dump -U <postgres_user_name> db_name > db_name1.sql`
I am trying to run the following file.sql using psql command (Postgresql v8.4):
CREATE OR REPLACE VIEW my_view AS
SELECT * FROM MY_ORDER_TABLE;
This is the command that I use:
psql -d myDB -f file.sql
But I get the following error:
psql:file.sql:1: ERROR: syntax error at or near "CREATE"
LINE 1: CREATE OR REPLACE VIEW my_view AS
Any suggestions on how to fix this?
When I run an SQL script using psql.exe I am not getting error codes when an error occurs. Is there any way to get the psql error codes?
I tried setting VERBOSITY to 'verbose' like this, but no use:
\set VERBOSITY 'verbose'
I am using psql of version psql (PostgreSQL) 8.4.2.
Get rid of the quotes:
test=# \set VERBOSITY verbose
test=# select broken;
ERROR: 42703: column "broken" does not exist
LINE 1: select broken;
^
LOCATION: transformColumnRef, parse_expr.c:766