PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, November 15, 2022

[FIXED] How to pass URIs as variable in BQ stored procedure

 November 15, 2022     bq, error-handling, file-upload, gcs, google-cloud-platform     No comments   

Issue

I am new to BQ and trying to load table via file from GCS bucket and getting error for uris .

Query error: Found unsupported function call 'ARRAY[...]'; failed to set 'uris' in OPTIONS()

Code Snippet :

begin
declare filename STRING;
declare SourceDir STRING  ;
declare infilename STRING ;

set SourceDir='dir/';
set infilename='file.csv';
set filename = CONCAT('gs://mybucket/' , SourceDir,infilename);

LOAD DATA INTO `dataset.tablename`
FROM FILES(
format='CSV',
uris = [filename]
);
end

I am getting the above error.


Solution

Consider below approach using EXECUTE IMMEDIATE to pass filename as a parameter to your LOAD DATA clause:

begin
declare filename STRING;
declare SourceDir STRING;
declare infilename STRING;

set SourceDir='dir/';
set infilename='test.csv';
set filename = CONCAT("'",CONCAT('gs://mybucket/' , SourceDir,infilename),"'");

EXECUTE IMMEDIATE FORMAT("""
LOAD DATA INTO `dataset.tablename`
FROM FILES(
  format='CSV',
  uris = [%s]
  );
""",filename);
end

Output:

enter image description here



Answered By - Ricco D
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing