0

I am trying to put data into a table in Postgres DB. Schema and table already exist. All I want is to use file as input source that could be insert into that table.

I used modules like SqlServer if you ask, here is a quick glimpse of that part of the script:

Import-Module SqlServer
$connectionString =  Invoke-Sqlcmd -Username "USERNAME" -Password "PASSWORD" -Server "SERVERNAME" -Database "DATABASE_NAME" 
Write-SqlTableData -DatabaseName "DASHBOARD_NAME" -SchemaName "SCHEMA_NAME" -TableName "TABLE_NAME" -Force -InputData -Path 'PATH WHERE THE FILE IS STORED'
Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228
  • Use the SQL `COPY` command or the psql meta-command `\copy`. See: https://stackoverflow.com/a/32279203/939860 (How is an SQLServer module relevant to this? Different RDBMS ...) – Erwin Brandstetter Jan 02 '23 at 09:11
  • @ErwinBrandstetter thanks for answer. How it is relevant? Well, I tried to use PostgreSQLCmdlets module. I have a feeling that it would work, but this module demands a valid licence key to use. For obvious reason, I want my script to run every time I want to and not bother with licence expiration. –  Jan 02 '23 at 09:23
  • @ErwinBrandstetter you were right - SQLServer module is not relevant for Postgre DB. –  Jan 04 '23 at 10:30

1 Answers1

-1

You can use the LOAD DATA INFILE statement in MySQL. LOAD DATA INFILE

LOAD DATA INFILE '/path/to/file.csv' INTO TABLE table_name FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' IGNORE 1 ROWS;

Kelvin O
  • 1
  • 4