代码之家  ›  专栏  ›  技术社区  ›  i1ravenov

如何在PostgreSQL表的列中插入多行文字?

  •  -1
  • i1ravenov  · 技术社区  · 3 年前

    我正在寻找一种将多行文本插入PostgreSQL表(列)的方法。

    Screenshot of the insert query

    假设我在data.sql文件中有一个表“问题”,并且我想在DETAILS列中插入一个多行文本。 我该怎么办?

    1 回复  |  直到 3 年前
        1
  •  1
  •   Zegarek    3 年前

    您可以使用 String Constants With C-Style Escapes 通过添加 E 在文本常量之前,然后是 \n 无论您想在哪里换行: demo

    create table test(id serial primary key, a text);
    insert into test (a) values (E'line1\nline2\nline3') returning *;
    
    id 一
    1. 第1行
    第2行
    第3行