ゆるかわの日記

暮らしに役立つかもしれないことを書きます

PowerShellでsqlファイルをinclude

PowerShellsqlファイルをimport

$testCaseFilePath = "./unique.sql"
$testCaseFile = (Get-Content $testCaseFilePath) -as [string[]]

$targetModelFilePath = "./target_model.sql"
$targetModelFile = (Get-Content $targetModelFilePath) -as [string[]]

$targetColumnFilePath = "target_column.sql"
$targetColumnFile = (Get-Content $targetColumnFilePath) -as [string[]]

$outputFile = $testCaseFile.replace('%%target_model%%',$targetModelFile).replace('%%target_column%%',$targetColumnFile)

Write-Output $outputFile > ./output.sql

unique.sql

WITH target_model AS(
  
%%target_model%%

)
SELECT
  CASE
    WHEN COUNT(%%target_column%%) = COUNT(DISTINCT %%target_column%%) 
    THEN True
    ELSE False
  END AS result
FROM
  target_model

target_model.sql

/* メンバーの一覧 */
SELECT
  id
  ,member_name
  ,team_id
FROM
  sample_scores.members

target_column.sql

id