0

we want to run sql insert in BQ but we are using .sh file for this. below is our command and its not working as there is ' in my last insert value("Don't")

bq query --use_legacy_sql=false --label lm:<local_mkt> --label env:<env_var> '
INSERT INTO `<project>.<dataset_source>.reason_table`(cd,cd1,cd2,cd3,desc,dec1) 
VALUES(1,"DCV","AB","AB","SDF","I Don't")'

can anyone help here

glenn jackman
  • 238,783
  • 38
  • 220
  • 352
Yug
  • 105
  • 1
  • 9
  • [How to escape single quotes within single quoted strings](https://stackoverflow.com/questions/1250079/how-to-escape-single-quotes-within-single-quoted-strings) – glenn jackman Dec 07 '21 at 14:19

2 Answers2

0

Make double single quotes

select 'I don''t'
W_O_L_F
  • 1,049
  • 1
  • 9
  • 16
0

Escape character ' with \

bq query --use_legacy_sql=false --label lm:<local_mkt> --label env:<env_var> '
INSERT INTO `<project>.<dataset_source>.reason_table`(cd,cd1,cd2,cd3,desc,dec1) 
VALUES(1,"DCV","AB","AB","SDF","I Don\'t")'
Timogavk
  • 809
  • 1
  • 7
  • 20
  • bash does not allow single quotes in a single quoted string, not even escaped. https://www.gnu.org/software/bash/manual/bash.html#Single-Quotes – glenn jackman Dec 08 '21 at 14:45