I have to use SQL for the very first time. I downloaded data from French Public Service Open Data (https://cerema.app.box.com/v/dvfplus-opendata/folder/160785684885). I also downloaded Postgres App and PgAdmin 4. The file of interest is a dump, with a .sql extension. I created a database called "DVF" directly in PgAdmin.
Following all the tutorials online and the help here I tried to import the file using "Backup" and "Restore" commands, as well as lines directly from the terminal. I have a "success" message when I use Backup or Restore in PgAdmin, but always an error message from the Terminal (by clicking on DVF in Postgres App).
[DVF=# ./psql -U postgres DVF < /Users/Menica/dpts.sql;
>ERROR : syntax error at or near "."
[DVF=# psql -h localhost -p 5432 -U postgres -d DVF -f dpts.sql;
>ERROR: syntax error at or near "psql"
Furthermore, even with "success" messages from Backup/Restore, my tables aren't in PgAdmin after the Refresh.
I don't know if it can help but here are some directories :
The file : /Users/Menica/dpts.sql
PostGres App : /Library/PostgreSQL/9.3
=> There is a lot of folders there, like "bin"
Terminal by default : /bin/zhs
UPDATE
To dump the database I used the following in psql :
DVF-# pg_dump DVF > /Users/Menica/dpts.sql;
ERROR: syntax error at or near "pgdump"
LINE 1: pg_dump DVF > /Users/Menica/dpts.sql
^
The first 25 lines of the dpts.sql file are the following :
--
-- PostgreSQL database dump
--
-- Dumped from database version 9.5.25
-- Dumped by pg_dump version 9.5.25
-- Started on 2022-04-14 15:50:09 CEST
SET statement_timeout = 0;
SET lock_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;
--
-- TOC entry 34 (class 2615 OID 631938251)
-- Name: dvf_d2a; Type: SCHEMA; Schema: -; Owner: -
--
CREATE SCHEMA dvf_d2a;
--
-- TOC entry 35 (class 2615 OID 632173840)
-- Name: dvf_d2b; Type: SCHEMA; Schema: -; Owner: -
--
CREATE SCHEMA dvf_d2b;
SET default_tablespace = '';
SET default_with_oids = false;
Related
I'm trying to run a shell script that has a SQL query in it. Now, I can't use a SQL script in the shell script because of story requirements. I have been trying to get the shell script to return the correct count which is '6' but it is only returning '0'.
#!/bin/ksh
. /apps/path/config/setenv.ksh
DATE=`date "+%m%d%Y`
returnMessage="`sqlplus username/password#$ORACLE_SID << EOF
WHENEVER OSERROR EXIT SQL.OSCODE ;
WHENEVER SQLERROR EXIT SQL.OSCODE ;
spool /apps/path/data/test.txt
SET HEADING OFF
SET FEEDBACK OFF
SET VERIFY OFF
SET ECHO ON
SET PAGES 0
SET LINESIZE 90
select count(*) from table where dt = to_date('06/18/2020','MM/DD/YYYY');
EOF
`
"
exitCode=$?
oracleError=`echo "$returnMessage" | grep ORA-`
if [ -n "$oracleError" -o "$exitCode" -ne 0 ]; then
log "An error occurred while looking up the $COUNT"
log "SQLPlus Exit Code = $exitCode"
log "SQLPlus Message is: $returnMessage"
return 1
fi
export COUNT=`echo $returnMessage"
return 0
The output is also given below
SQL> SET HEADING OFF
SQL> SET FEEDBACK OFF
SQL> SET VERIFY OFF
SQL> SET ECHO ON
SQL> SET PAGES 0
SQL> SET LINESIZE 90
SQL>
SQL> select count(*) from table where dt = to_date('06/18/2020','MM/DD/YYYY');
0
SQL>
THis is the output and the code I'm using. Not sure where it is going wrong since the query should return 6;
UnCOMMITted data is only visible within the session that created it (and will ROLLBACK at the end of the session if it has not been COMMITted). If you can't see the data from another session (i.e. in SQL*Plus invoked from the shell) then make sure you have issued a COMMIT command in the SQL client where you INSERTed the data.
Note: even if you connect as the same user, this will create a separate session and you will not be able to see the uncommitted data in the other session.
If you have issued a COMMIT and still can't see the data then make sure that both the SQL Client and the shell program are connecting to the same server and the same database and are querying the same user's schema of that database.
I have newly setup TYPO3, but when I try to add/save content, it gives me this error:
SQL error: 'Incorrect integer value: '' for column 'sys_language_uid'
at row 1
The behavior is related to database management systems using strict mode, like MySQL since version 5.7. Disabling strict mode (like provided in the accepted answer) is just a work around.
The real solution would be to explicitly cast values to integer by modifying TCA (table configuration array) for the according field definitions.
for fields of type input that would be setting/extending 'eval' => 'int', see example tt_content.starttime
or in general for all field types it would be to define the default value using 'default' => 0, see example tt_content.sys_language_uid
set this in Localconfiguration.php file
[SYS][setDBinit] = SET SESSION sql_mode=''
For me, after trying different approaches, the solution was:
mysql -u root -p -e "SET GLOBAL sql_mode = 'NO_ENGINE_SUBSTITUTION';"
Then, you can verify that the mode is set by running the following:
mysql -u root -p -e "SELECT ##GLOBAL.sql_mode;"
And you should see:
+---------------+------------------------+
| Variable_name | Value |
+---------------+------------------------+
| sql_mode | NO_ENGINE_SUBSTITUTION |
+---------------+------------------------+
In latest TYPO3 Versions you have to add this in LocalConfiguration.php
'setDBinit' => 'SET SESSION sql_mode = \'NO_ENGINE_SUBSTITUTION\';',
In Typo3 9.5/10.4
It you are not able to change the programming of the used extentions - or change the running mode of mysql server - it might be useful to change the mode of the typo3 connection. You can simply add to youre LocalConfiguration.php.
[DB][Connections][Default][initCommands]='SET SESSION sql_mode = \'\';',
i have been trying to import a Postgresql dump with my pgadmin3 interface but im running into problems. These dump was generated with pg_dump dbname > dump_file.sql
ERROR: syntax error at or near "\"
LINE 1903: \.
^
********** Error **********
ERROR: syntax error at or near "\"
SQL state: 42601
Character: 45693
the code:
--
-- Data for Name: auth_group; Type: TABLE DATA; Schema: public; Owner: postgres
--
COPY auth_group (id, name) FROM stdin;
\.
thanks
PgAdmin-III's SQL window unfortunately does not understand psql backslash commands, COPY ... FROM STDIN, etc.
You must restore with psql.
psql -f dump_file.sql
I am trying to automate the creation of schemas and some tables into that newly created schema. I am trying to write a script in powershell to help me achieve the same. I have been able to create the schema, however, I cannot create the tables into that schema.
I am passing the new schema to be created as a variable to powershell.
script so far (based off the solution from the following answer. StackOverFlow Solution):
$MySchema=$args[0]
$CreateSchema = 'CREATE SCHEMA \"'+$MySchema+'\"; set schema '''+$MySchema+''';'
write-host $CreateSchema
C:\PostgreSQL\9.3\bin\psql.exe -h $DBSERVER -U $DBUSER -d $DBName -w -c $CreateSchema
# To create tables
C:\PostgreSQL\9.3\bin\psql.exe -h $DBSERVER -U $DBUSER -d $DBName -w -f 'E:\automation\scripts\create-tables.sql' -v schema=$MySchema
At the execution, I see the following error:
psql:E:/automation/scripts/create-tables.sql:11: ERROR: no schema has been selected to create in
The content of create-tables.sql is:
SET search_path TO :schema;
CREATE TABLE testing (
id SERIAL,
QueryDate varchar(255) NULL
);
You've got this in your first step:
$CreateSchema = 'CREATE SCHEMA \"'+$MySchema+'\"; set schema '''+$MySchema+''';'
Take out that set schema - it's erroneous and causing the schema not to be created. Then on the next step you wind up with an empty search path (because the schema never got created), which is why you get that error.
I use mysqldump to save data from tables and move it to Postgres db.
I make dump with:
mysqldump --complete-insert --no-create-info --no-create-db --compatible=postgresql -uroot -p music files > music_files.sql
But while doing in psql:
=> \i music_files.sql
have this error:
music_files.sql:29: ERROR: syntax error at or near "s"
LINE 1: ...,5,'Impossible',NULL),(33,4103,178,841,198,'Tifa\'s Theme [P...
Postgres doesn't understand this escaping. It wants 2 quotes '' before s
How can I make it with mysqldump?
You can use this in the psql shell:
=> set backslash_quote = on;
=> set standard_conforming_strings = off;
=> select 'foo\'bar';
?column?
----------
foo'bar
=> \i ...whatever...
Do NOT make this persistent by setting it in some configuration file or by ALTER USER etc. since this may be security relevant.