sql - 需要在 psql 中以特定格式输出
问题描述
认为:-
subh=# select 'test123';
?column?
-------------------------------------
test123
和
subh=# select obj_description('test123'::regclass);
obj_description
--------------------
this is my table
我正在运行此查询:-
subh=# select 'test123' || ' ' || obj_description('test123'::regclass) as test;
test
-------------------------------
test123 this is my table
实际上我希望输出如下: -
test
-------------------------------
test123 'this is my table'
解决方案
利用quote_literal
此函数在给定字符串/数字的前后添加单引号。在这里阅读。
subh=# select 'test123' || ' ' || quote_literal(obj_description('test123'::regclass)) as test;
推荐阅读
- amazon-web-services - 无法从 aws CLI 创建 DynamoDB 表
- javascript - Jquery第一次没有在Rail 6页面上运行
- javascript - 将 mocha 并行选项与动态生成的 Mocha 测试套件一起使用
- c++ - 使用 cmake 构建忍者时遇到问题
- java - 如何使用jackson api将双值序列化为原始类型和空值
- database - 无法启动 Oracle Database XE 18.4 Docker 容器
- php - 当用户再次选择时,如何清理预览图像和文件?以及如何修改这个数组循环?
- scala - Spark 问题:如果我不缓存数据帧,那么它会运行多次吗?
- c# - .NET Core 中的依赖注入
- python - 更快地检查熊猫系列中的元素是否存在于列表列表中