我想使用 postgresql 从我们的 postgresql 数据库中的数据库列中提取查询参数,但没有成功
I want to extract a query parameter from a database column in our postgresql database using postgresql but am having no success
我正在尝试使用 postgresql 获取查询参数,但遇到了问题,因为参数的顺序并不总是相同。我有一个 table,如下所示:
username | context_page
________________________________________________
John |?promo=summer21&campaign=presidentsDay
Sam |?campaign=july4th&promo=summer21
Chris |?promo=spring&campaign=baseball
我尝试了以下方法但没有成功:
SELECT split_part(substring(conversion.context_page from '[?&]promo=[^&]+'), '=', 2),
context_page_search
FROM conversion;
如有任何帮助,我们将不胜感激!
如果您有固定的查询参数列表(促销和活动)试试这个:
SELECT username,
(REGEXP_MATCH(context_page, '[?&]promo=([^&]+)'))[1] AS promo,
(REGEXP_MATCH(context_page, '[?&]campaign=([^&]+)'))[1] AS campaign
FROM conversion;
您将在单独的列中获得参数
username promo campaign
-------------------------------------
John summer21 presidentsDay
Sam summer21 july4th
Chris spring baseball
我正在尝试使用 postgresql 获取查询参数,但遇到了问题,因为参数的顺序并不总是相同。我有一个 table,如下所示:
username | context_page
________________________________________________
John |?promo=summer21&campaign=presidentsDay
Sam |?campaign=july4th&promo=summer21
Chris |?promo=spring&campaign=baseball
我尝试了以下方法但没有成功:
SELECT split_part(substring(conversion.context_page from '[?&]promo=[^&]+'), '=', 2),
context_page_search
FROM conversion;
如有任何帮助,我们将不胜感激!
如果您有固定的查询参数列表(促销和活动)试试这个:
SELECT username,
(REGEXP_MATCH(context_page, '[?&]promo=([^&]+)'))[1] AS promo,
(REGEXP_MATCH(context_page, '[?&]campaign=([^&]+)'))[1] AS campaign
FROM conversion;
您将在单独的列中获得参数
username promo campaign
-------------------------------------
John summer21 presidentsDay
Sam summer21 july4th
Chris spring baseball