我正在尝试使用现有数据填充新的JSON字段,并且可以使用一些帮助来正确格式化字段。我有一个子查询返回一个值列表,意图是JSON属性中的数组。子查询返回正确的结果,但我无法正确填充JSON数组。
我的查询基本上是这样的:
UPDATE foos SET json_property =
cast(
'{"bar_ids":' ||
(select json_agg(x) from (select id from bars) x) ||
'}'
as json);
我想要存储的是:
{"bar_ids":[1,2,3,4]}
但我现在得到的是:
{"bar_ids":[{"id":1},{"id":2},{"id":3},{"id":4}]}
思想?
答案 0 :(得分:1)
似乎一个子查询是不必要的:
package com.demo.learn;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class handle {
public static void main (String [] args){
WebDriver driver;
System.setProperty("webdriver.chrome.driver", "D://CAHCO Automation//OpteamixAutomation-master(1)//OpteamixAutomation-master//Automation_framework//OPTEAMIX//Drivers//chromedriver.exe");
driver=new ChromeDriver();
driver.get("https://www.indiapost.gov.in/VAS/Pages/Form.aspx");
driver.manage().window().maximize();
driver.findElement(By.xpath(".//*[@id='ctl00_SPWebPartManager1_g_29491a13_ee77_4e11_a5e4_e031cc13d245']/div[1]/table[1]/tbody/tr[2]/td[1]/a/img")).click();
Set<String> handles=driver.getWindowHandles();
String firsthandle = driver.getWindowHandle();
handles.remove(firsthandle);
String winhandle = handles.iterator().next();
if (winhandle!=firsthandle){
String secondWinHandle = winhandle;
driver.switchTo().window(secondWinHandle);
System.out.println("Switched");
boolean display = driver.findElement(By.xpath(".//*
[@id='download']")).isDisplayed();
if(display==true)
{
System.out.println("Displayed");
}
else
{
System.out.println("Not Displayed");
}
}
}
}