Error in executing SQL statement with PostgreSQL - sql

I create a new database 'sakila' with pgAdmin III in my local PostgreSQL database, then executed these sql statements:
sakila-schema.sql then sakila-data.sql
The first statement executed without error, however the second SQL did produced error when executed:
ERROR: syntax error at or near "1"
LINE 112: 1 PENELOPE GUINESS 2006-02-15 09:34:33
^
********** Error **********
ERROR: syntax error at or near "1"
SQL state: 42601
Character: 2511
How to fix this error?

You can't COPY FROM stdin with pgAdmin, you have to use psql tool, the problem is that pgAdmin is not a console application, there is no easily usable stdin so you can't COPY from Standard Input .

Related

Database Error: 001003 (42000): SQL compilation error

I am getting this error when using dbt cli 0.21.1 with Snowflake:
Encountered an error: Database Error 001003 (42000): SQL compilation error: syntax error line 1 at position 31 unexpected '<EOF>'. syntax error line 1 at position 30 unexpected '.'.
... when running "dbt build". I have stripped down my models to the minimum and get the same error whatever I do. I have done "dbt clean". The results of "dbt debug" and "dbt parse" look fine.
In the dbt.log file, I can see it fails on a Snowflake command:
create schema if not exists FT.
... with the SQL compilation error message shown above.
I found the same error in the Snowflake query history, with the same command text. So I tried it by hand in the Snowflake console. Lo and behold, it works fine without the trailing period, but Snowflake produces exactly this error with that trailing period.
So it seems like dbt and Snowflake disagree about whether a SQL command should end with a period. Which one has a bug? Or is there a way to tell one or the other to change?
I forgot that I had created a generate_schema_name macro -- and it was messing up the schema name, turning it into an empty string. The create schema command was trying to create a schema named "FT." but because the schema name was blank, it ended up as "FT." -- and the trailing period confused me.
Mea culpa.
Hope this description ends up helping someone else who makes the same mistake.

Cannot import .sql to PostgreSQL. Syntax error

Probably a very simple error but I cannot work it out for the life of me. Basically, I am loading a .sql dump into a postgres DB using
psql testdb< C:\Users\Callum\Desktop\backup.sql
However, I get the error:
ERROR: syntax error at or near "`"
LINE 1: DROP TABLE IF EXISTS `table1`;
^
ERROR: syntax error at or near "`"
LINE 1: CREATE TABLE `table2` (
^
ERROR: syntax error at or near "`"
LINE 1: LOCK TABLES `table3` WRITE;
I have been trying to work this out for days and could not find any anwsers online.
Thanks
Are you importing from MySQL? You don't need backticks here, you can take them out.

Importing database in PostgreSQL using pg_dump having ERROR: 42601: syntax error at or near "psql"

i am using PostgreSQL database for my application. Now i have to import my all databases in it.
I am using this command for importing,
psql -U postgres Employees < dbimport.pgsql
but it is not importing. I have already created the database with name Employees in my PostgreSQL.
Getting Error like,
42601: syntax error at or near "psql"
Please suggest me if i am going wrong.
if you have postgres client installed, probably you have misconfigured environmental variables ($PATH), to find the psql use instructions here: https://stackoverflow.com/a/44106963/5315974
Basically you need to usemlocate (if you have it installed) or just find...
Unrelated, but also I would avoid using mixed case in database name...
Also 42601: syntax error at or near "psql" error code means you try to run psql as SQL statement, which it is not - look into your dbimport.pgsql if you have not SQL there - maybe it is shell (or some other) script?..
The error 42601: syntax error at or near "psql" is a syntax_error from the database not from the terminal, so the value of $PATH is not wrong.
It looks like the file 'dbimport.pgsql' which you are trying to import does not contain the importable data.
Can you confirm, how this backup was taken? Or the content of file 'dbimport.pgsql'.

Syntax error: Encountered "<EOF>" in derby on DROP SEQUENCE statement

Some sequences were created because of the error described here. To keep everything clean I tried to delete them with the command DROP SEQUENCE seqname;. It produces me the following message:
Error code -1, SQL state 42X01: Syntax error: Encountered "" at line 1, column 20.
Line 1, column 1
Execution finished after 0 s, 1 error(s) occurred.
I guess it is because I work on Windows machine which has different EOF marker. But how to solve the problem in SQL?
After several trials the solution is DROP SEQUENCE sequence_name RESTRICT which was found here. Adding RESTRICT to the SQL statement solves the problem

Sql error with backquotes, says there's a syntax error at or near "`"

I'm trying to load a database into Heroku from a sql file, however I get a syntax error from back quotes / backticks.
heroku pg:psql < backup.sql
Outputs this error:
syntax error at or near "`"
Why is that? Aren't backquotes valid?
I can find/replace them with something else if that would be good to try.
are you restoring from a postgresql system or another db software such mySQL?
can you search your backup.sql file for the back-ticks and post that section of your file?
it would help to know if your back-ticks are in the column field names or in the data portion of the SQL statement.