<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Reference file name when using COPY INTO? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/reference-file-name-when-using-copy-into/m-p/5092#M1604</link>
    <description>&lt;P&gt;Found the info I was looking for on the page below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.databricks.com/ingestion/file-metadata-column.html" target="test_blank"&gt;https://docs.databricks.com/ingestion/file-metadata-column.html&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 08 May 2023 19:45:52 GMT</pubDate>
    <dc:creator>cnjrules</dc:creator>
    <dc:date>2023-05-08T19:45:52Z</dc:date>
    <item>
      <title>Reference file name when using COPY INTO?</title>
      <link>https://community.databricks.com/t5/data-engineering/reference-file-name-when-using-copy-into/m-p/5089#M1601</link>
      <description>&lt;P&gt;When using the COPY INTO statement is it possible to reference the current file name in the select staement?  A generic example is shown below, hoping I can log the file name in the target table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;COPY&lt;/B&gt; &lt;B&gt;INTO&lt;/B&gt; my_table&lt;/P&gt;&lt;P&gt;  &lt;B&gt;FROM&lt;/B&gt; (&lt;B&gt;SELECT&lt;/B&gt; &lt;B&gt;key&lt;/B&gt;, &lt;B&gt;index&lt;/B&gt;, textData, 'constant_value', &lt;B&gt;?FILE_NAME?&lt;/B&gt;&lt;/P&gt;&lt;P&gt;          &lt;B&gt;FROM&lt;/B&gt; 'abfss://container@storageAccount.dfs.core.windows.net/base/path')&lt;/P&gt;&lt;P&gt;  FILEFORMAT = CSV&lt;/P&gt;&lt;P&gt;  PATTERN = 'folder1/file_[a-g].csv'&lt;/P&gt;&lt;P&gt;  FORMAT_OPTIONS('header' = 'true')&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Apr 2023 21:25:24 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/reference-file-name-when-using-copy-into/m-p/5089#M1601</guid>
      <dc:creator>cnjrules</dc:creator>
      <dc:date>2023-04-27T21:25:24Z</dc:date>
    </item>
    <item>
      <title>Re: Reference file name when using COPY INTO?</title>
      <link>https://community.databricks.com/t5/data-engineering/reference-file-name-when-using-copy-into/m-p/5090#M1602</link>
      <description>&lt;P&gt;@Michael L​&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes, it is possible to reference the current file name in the SELECT statement when using the COPY INTO statement. The placeholder for the current file name is @1. You can use this placeholder in your SELECT statement to reference the current file name. Here is an example of how to use it:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;COPY INTO my_table
FROM (
  SELECT key, index, textData, 'constant_value', @1 AS file_name
  FROM 'abfss://container@storageAccount.dfs.core.windows.net/base/path'
)
FILEFORMAT = CSV
PATTERN = 'folder1/file_[a-g].csv'
FORMAT_OPTIONS('header' = 'true')&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In this example, the @1 placeholder is used to reference the current file name and it is aliased as file_name in the SELECT statement. This value will be inserted into the my_table target table as a column.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2023 17:36:47 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/reference-file-name-when-using-copy-into/m-p/5090#M1602</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-04-28T17:36:47Z</dc:date>
    </item>
    <item>
      <title>Re: Reference file name when using COPY INTO?</title>
      <link>https://community.databricks.com/t5/data-engineering/reference-file-name-when-using-copy-into/m-p/5091#M1603</link>
      <description>&lt;P&gt;Thanks for the response.  I tried that but received a PARSE_SYNTAX_ERROR on the @1 reference.  Any chance you know of any documentation on that placeholder?  &lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2023 22:35:38 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/reference-file-name-when-using-copy-into/m-p/5091#M1603</guid>
      <dc:creator>cnjrules</dc:creator>
      <dc:date>2023-04-28T22:35:38Z</dc:date>
    </item>
    <item>
      <title>Re: Reference file name when using COPY INTO?</title>
      <link>https://community.databricks.com/t5/data-engineering/reference-file-name-when-using-copy-into/m-p/5092#M1604</link>
      <description>&lt;P&gt;Found the info I was looking for on the page below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.databricks.com/ingestion/file-metadata-column.html" target="test_blank"&gt;https://docs.databricks.com/ingestion/file-metadata-column.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 19:45:52 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/reference-file-name-when-using-copy-into/m-p/5092#M1604</guid>
      <dc:creator>cnjrules</dc:creator>
      <dc:date>2023-05-08T19:45:52Z</dc:date>
    </item>
    <item>
      <title>Re: Reference file name when using COPY INTO?</title>
      <link>https://community.databricks.com/t5/data-engineering/reference-file-name-when-using-copy-into/m-p/129440#M48531</link>
      <description>&lt;P&gt;In sql, with a subselect works just fine&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;%sql &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;COPY&lt;/SPAN&gt; &lt;SPAN&gt;INTO&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;tabele_copy_into_test &lt;/SPAN&gt;&lt;SPAN&gt;from&lt;/SPAN&gt;&lt;SPAN&gt; (&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;SELECT&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; user_id,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; email,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;_metadata&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;file_name&lt;/SPAN&gt; &lt;SPAN&gt;AS&lt;/SPAN&gt;&lt;SPAN&gt; source_file&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;from&lt;/SPAN&gt; &lt;SPAN&gt;"/Volumes/dbacademy_ecommerce/v01/raw/users-historical/"&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;FILEFORMAT&lt;/SPAN&gt; &lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; PARQUET&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;COPY_OPTIONS&lt;/SPAN&gt;&lt;SPAN&gt; (&lt;/SPAN&gt;&lt;SPAN&gt;'mergeSchema'&lt;/SPAN&gt; &lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;'true'&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Aug 2025 16:02:53 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/reference-file-name-when-using-copy-into/m-p/129440#M48531</guid>
      <dc:creator>dalcuovidiu</dc:creator>
      <dc:date>2025-08-23T16:02:53Z</dc:date>
    </item>
  </channel>
</rss>

