Skip to main content
Question

How to use parameterized query in the DB-Extractor?

  • 13 September 2024
  • 2 replies
  • 40 views

dinesh.makked
Seasoned

Hello,

I am trying to set up a database extractor for SQL Server database. I would like to pass parameters to the query so that the extraction logic can be controlled via the env file. 

Here is what I have done.

  1. Created an environment variable called “DEPT_ID”,
  2. In the YAML file, I am using ${DEPT_ID} to use the value of the env variable. 

 

SELECT
  *
FROM
  [Employee] 
WHERE [Dept_id] = ${DEPT_ID}

 

While running the DB-Extractor, I am encountering the following error.

KeyError: DEPT_ID

 

I am wondering if the product even supports the use of parameterized queries in the DB-Extractor.

Any help will be greatly appreciated. 

 

Thanks,

Dinesh

Isha Thapliyal
Seasoned Practitioner
Forum|alt.badge.img+3

Hi @dinesh.makked 

We have forwarded your request to our engineering team and will share an update with you soon.

Thank you
Isha


  • Practitioner
  • September 20, 2024

Using environment variables in this way should work, see here: https://docs.cognite.com/cdf/integration/guides/extraction/configuration/db#using-values-from-environment-variables.

However, the  Key Error: DEPT_ID indicates that the environment variable DEPT_ID is not defined. 

Are you running the DB extractor through Docker? If so, remember that you need to pass over any environment variables to the docker container for them to be available, see here: https://docs.cognite.com/pt/cdf/integration/guides/extraction/db/db_setup/#step-2-run-the-docker-container
 

Hope that this helps. Keep extracting!

 


Reply


Cookie Policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie Settings