KevinYanesG commented on issue #21457: URL: https://github.com/apache/airflow/issues/21457#issuecomment-1033862251
One last thing: In the ["valid" version of the pipeline example](https://github.com/apache/airflow/blob/main/docs/apache-airflow/tutorial.rst#pipeline-example) it is said: > Create a Employee table in Postgres using this: CREATE TABLE "Employees" ... For me (someone who didn't work with Postgres) it wasn't trivial to get the example to run, because I didn't know how to explicitly create the database. Finally, I did it with the following code: ```python def get_data(): # NOTE: configure this as appropriate for your airflow environment data_path = "/opt/airflow/dags/files/employees.csv" url = "https://raw.githubusercontent.com/apache/airflow/main/docs/apache-airflow/pipeline_example.csv" response = requests.request("GET", url) with open(data_path, "w+") as file: file.write(response.text) postgres_hook = PostgresHook(postgres_conn_id="postgres_default") conn = postgres_hook.get_conn() cur = conn.cursor() cur.execute('''CREATE TABLE "Employees" ( "Serial Number" NUMERIC PRIMARY KEY, "Company Name" TEXT, "Employee Markme" TEXT, "Description" TEXT, "Leave" INTEGER ); CREATE TABLE "Employees_temp" ( "Serial Number" NUMERIC PRIMARY KEY, "Company Name" TEXT, "Employee Markme" TEXT, "Description" TEXT, "Leave" INTEGER ); ''') with open(data_path, "r") as file: cur.copy_expert( "COPY \"Employees_temp\" FROM STDIN WITH CSV HEADER DELIMITER AS ',' QUOTE '\"'", file, ) conn.commit() ``` I don't know if this is the intended/optimal way to create the DB, but it didn't fail. Maybe it would be easier for bloody beginners like me to include the part of creating the DB explicitly in the tutorial's code. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
