They are technically not the same, but they are similar, as you can see by loading them:
import ruamel.yaml
yaml = ruamel.yaml.YAML(typ='safe', pure=True)
for fn in 'literal.yaml', 'quoted.yaml':
data = yaml.load(Path(fn))
print(repr(data['test']['query']))
which gives:
'create or replace view emp as\n\nselect e.id as emp_id\nfrom employees as e\n'
'create or replace view emp\nas\nselect e.id as emp_id\n FROM employees\n as e\n;'
The double quoted style can represent any string using backslash escapes, but is not always very readable.
If you have a string with just linebreaks, you can often use the first form, called a literal
style scalar.
You can create individual literal style scalars using the following (of course you don't have to start from
loaded data, you can just as well create that in YAML):
import sys
import ruamel.yaml
from ruamel.yaml.scalarstring import LiteralScalarString as LS
yaml = ruamel.yaml.YAML()
data = yaml.load(Path('quoted.yaml'))
data['test']['query'] = LS(data['test']['query'])
yaml.dump(data, sys.stdout)
which gives:
test:
query: |-
create or replace view emp
as
select e.id as emp_id
FROM employees
as e
;