I am trying to insert new record into my database through a .sql file
INSERT INTO CisZdravotnickeProstredky(Kod,Nazev) VALUES
(N'0048367', N'SET AUTOTRANSFÚZNÍ BELLOVAC ABT-ZÁKLADNÍ SET')
Problem is with the keyword "SET"
How to insert this nvarchar?
Related
I want to truncate a table in PostgreSQL 13 and then insert rows to the same table within a single transaction, so that when I execute the SQL command it will TRUNCATE the table and if during INSERTS anything fails truncated data should be rollback.
Below is the command which I want in a single transaction.
TRUNCATE TABLE public.truninsdemo;
INSERT INTO public.truninsdemo (id, name)
VALUES (1, 'Scott'), (2, 'John');
UPDATE
I don't want to execute TRUNCATE and INSERT statements as 2 separate commands, separated by a semicolon. I want to achieve results using a single command may be CTE, but not sure how.
I want to be able to load/run a sql file from inside another sql file.
Because my goal is to have one sql file with all the table creations and then after each create statment I let run the <table-name>-data.sql to insert the data for the table.
I just dont know what the rigth sql command is for that because copy is only for csv files.
And load is for shared libarys.
LOAD — load a shared library file
File with the data from a table:
<table-name>-data.sql:
INSERT INTO public.table VALUES ('2022-11-16');
INSERT INTO public.table VALUES ('2022-11-17');
INSERT INTO public.table VALUES ('2022-11-18');
INSERT INTO public.table VALUES ('2022-11-19');
File where I create the table and then load <table-name>-data.sql:
create.sql:
... sql for creating the table ...
run "c:/path/<table-name>-data.sql"
And in the end I can just run the create.sql file.
Solved by #Álvaro González,
Just use: \i path/file.sql
You can use it inside SQL too when trying it to run with psql.
I am using ora2pg to export TABLE and INSERT type from oracle database. https://ora2pg.darold.net/documentation.html#:~:text=Ora2Pg%20consist%20of,QUERY%2C%20KETTLE%2C%20SYNONYM.
I have 2 questions.
The TABLE and INSERT sql statements have double quotes for table and column names but I want to create them without double quotes. Is it possible to configure this in the .conf file?
The INSERT sql file that is generated by ora2pg does not have the sql statements in right order. The parent table data should be inserted first before trying to insert data into child table due to foreign key constraints. But the INSERT sql file generated by ora2pg is not taking this into account so this is causing error because the child table insert statement is present before the parent table. Is this how ora2pg works or am I doing something wrong in the .conf file?
I have a table named basic_data which contains more than 8 millions rows and I want to copy all this data into a CSV file.
So I use the COPY command like this :
copy basic_data to '/tmp/data_fdw.csv' delimiter ';' null '';
COPY 8792481
This work great but when I want to insert my data into another table with exactly the same schema (but it's a foreign table), I had this following error:
ERROR: value out of range: overflow
How to add results of selecting query to a new column in already existing table in PostgreSQL in pgAdmin?
Results of the select query is an alteration of over columns in the same table.
Just create the column and update data afterwards (using the command line bundled in pgadmin):
ALTER TABLE tablename ADD COLUMN colname coltype;
UPDATE tablename SET colname = yourexpression;