executing query from docker to psql db shows psql: warning: extra command-line argument "" ignored - postgresql

Hi I am in my docker console and trying to run shell script to connect to PSQL DB and execute queries.
#!/bin/sh
query = "select * from default$default."LightZone"";
#psql -U postgres -p postgres psql -e "$query";
This is my tablecreation.sh file and when I do ./tablecreation.sh
./tablecreation.sh: 5: ./tablecreation.sh: query: not found
psql: warning: extra command-line argument "" ignored
Password for user prisma:
psql (10.3 (Debian 10.3-1.pgdg90+1))
Type "help" for help.
The above message comes . But the same query is running from the psql command prompt.
can someone help me if i am missing something . I want to connect to postgres->prisma db >default$default schema > LightZone table and run some queries.

Escape the double quotes with \
query = "select * from default$default.\"LightZone\"";

Related

psql faild to restor file from network drive

i have a dump file on drive z (network drive)
im opening the psql from PgAdmin4
this is the command that im writeing:
psql -U postgres -d postgres -f Z:\DB_BU\md_20220729.sql
and this is the error that im getting:
Invalid command \DB_BU. Try \? for help.
when im doing this:
psql -U postgres -d postgres -f i\ Z:\DB_BU\md_20220729.sql
Invalid command \DB_BU. Try ? for help.
and when im doing this:
psql -U postgres -d postgres -f "Z:\DB_BU\md_20220729.sql"
im not getting any error but also its not restoring the file. how can i restor the file?
You're trying to call psql from within psql or PGAdmin. Since
psql is a standalone program, not an SQL command you can run in PGAdmin SQL window or psql's own, internal meta-command you're getting the error
Invalid command \DB_BU. Try \? for help
indicating that there was an attempt to interpret your entire command as a SQL query or an internal command and that this attempt failed.
You can open "psql tool" from within PGAdmin but your command won't work there either because it's trying to call psql itself, with some command-line options, which you cannot do when you're already inside an interactive psql session. The command
psql -U postgres -d postgres -f Z:\DB_BU\md_20220729.sql
can be used outside psql and PGAdmin, in your terminal, like zsh on Mac, sh/bash on Linux, cmd or PowerShell on Windows, where psql is installed and visible, along with your network path.
If you're able to open the psql tool window in PGAdmin, you can instead try and use an internal psql \i meta-command which is basically the same thing as the -f command-line option, but meant for use inside the psql session:
\i "Z:\DB_BU\md_20220729.sql"

PostgreSQL - using psql terminal to restore a dump - error: stdin is not a tty

On Windows 10, using psql with PostgreSQL 14 installed, I'm trying to restore a dump that is my_dump.sql.
I'm on Bash terminal currently.
I'm connected to psql server and I created a new database new_db, then a new superuser tobe.
Then I tried the command psql -d new_db < my_dump.sql but I'm getting the error stdin is not a tty
I tried the solution psql -U tobe -d new_db -f my_dump.sql from "stdin is not a tty" when populating Postgres database
because they mention the error but now I get a new error:
ERROR: syntax error at or near "ÿþ" LIGNE 1 : ÿþ
Are the two errors connected? Maybe the second error is only related to the command syntax. I'm not sure if I'm in the right direction.
Try
psql.exe -U tobe -d new_db -f my_dump.sql

PostgreSQL pg_dump syntax error in Ubuntu

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`

mysqldump command resulting in "error 1064 syntax error"

I’m in the MySQL command line client mysql monitor, trying to do a mysqldump command on the database with which I have an open connection. This is the command I’m using at the mysql> prompt:
mysqldump -u username -p password databasename > dumpfilename.sql\g.
I assume that the file dumpfilename.sql will be created when the dump is successful. I have tried it with and without pw, un, end-of-line semicolon, etc. I am getting
error 1064 syntax error
over and over again. What am I doing wrong?
mysqldump is a program, not a MySQL command. Exit the mysql client and enter the mysqldump -u username -p password databasename > dumpfilename.sql command at the shell prompt and it will work

Unable To Run PSQL

Whenever I try to run 'psql' I receieve the following error message:
ahcarpenter#ubuntu:~$ psql
psql: FATAL: role "ahcarpenter" does not exist
Any ideas on how to fix this?
That happens because
$ psql
is equivalent to
$ psql ahcarpenter -U ahcarpenter
As that user does not exist enter as user postgres
$ psql -U postgres
Once inside create the user and the database "ahcarpenter".
create user ahcarpenter;
create database ahcarpenter with owner ahcarpenter;
exit
\q
Reenter
$ psql