惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
Blog — PlanetScale
Blog — PlanetScale
The GitHub Blog
The GitHub Blog
Microsoft Security Blog
Microsoft Security Blog
I
InfoQ
A
About on SuperTechFans
T
The Blog of Author Tim Ferriss
D
DataBreaches.Net
L
LangChain Blog
F
Fortinet All Blogs
C
Check Point Blog
Google DeepMind News
Google DeepMind News
云风的 BLOG
云风的 BLOG
Engineering at Meta
Engineering at Meta
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
H
Help Net Security
J
Java Code Geeks
月光博客
月光博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More
IT之家
IT之家
aimingoo的专栏
aimingoo的专栏
小众软件
小众软件
宝玉的分享
宝玉的分享
Jina AI
Jina AI

Sanity.io

A Board Game agent built using Sanity Context and Vercel's AI SDK | Sanity Build a prototype with Claude Code that your whole team can edit | Sanity What’s New - May 2026 | Sanity I built a London pub guide with v0 and the Sanity MCP in six hours. Here's what I learned. | Sanity Build a conference concierge with Agent Context and Anthropic | Sanity Build a content-aware Telegram agent with Vercel AI SDK and Chat SDK | Sanity How I used Agent API to generate photos for my family’s recipes | Sanity What’s New April - 2026 | Sanity Better context, better matches: An AI love story (for dogs) | Sanity How to write for an agent | Sanity Content Agent, meet Slack: AI content operations in your workflow | Sanity Structure powers intelligence | Sanity Your agent needs better content. Here's how to give it. | Sanity How to serve content to agents (a field guide) | Sanity Sanity TypeGen GA: Automatic TypeScript types for content and GROQ | Sanity Sanity is now available on the Vercel Marketplace | Sanity The logo soup problem (and how to solve it) | Sanity Content Releases: From scattered updates to coordinated publishing | Sanity What's New - February 2026 | Sanity How we solved the agent memory problem | Sanity v0 Builder Challenge: The winners | Sanity Introducing: Sanity Agent Skills | Sanity Content Agent: Days of work in one conversation | Sanity Our Sanity Values | Sanity Open Source Pledge 2025: Stepping up when it matters | Sanity v0 builder challenge: $3000 in prizes | Sanity Why AI Breaks Without Structured Content Operations | Sanity What’s New January - 2026 | Sanity BFCM 2025: What teams built when infrastructure stopped being the problem | Sanity How AI shaped holiday shopping and what it means for content in 2026 | Sanity
Functions in GROQ defined | Sanity
Kapehe · 2021-07-23 · via Sanity.io

In Kap & Lauren learn GROQ - Part 7, we entered the world of GROQ functions and contemplated traveling to the sun or the moon. Kap and I were split on this question, I would much rather go to the moon so that I could have special moon boots! But Kap would travel to the sun and play soccer (fútbol).

GROQ Functions

In GROQ, there are numerous functions you can choose when writing out your queries. Whether you want to find the length of a string or even round up a number to a whole number, functions in GROQ can help you out. To find the full list, visit this function reference page.

In this stream, we covered a handful of them. Let's check them out.

Defined Function

The defined() function takes any argument and evaluates whether it's true, false, or NULL:

Kap and I used the defined() in the above query to filter all of our content that has a price and return the title and price in our projection. This is a departure from the queries we did in previous streams because we are using the defined() to search across all of our documents instead of filtering by a document _type to narrow the scope of our query.

Round Function

The round() function will take any number and round it to the nearest integer or decimal place specified in the function:

Our second query uses round() to round all of the product prices to a whole integer. For example, the round() would return a price of 10 for a candy priced at 9.99.

In the example above, we took the rounded price and added 3.00 (+ 3) to all prices at once. This would be a great time-saver if you needed to update all of the prices in your store!

Text Function

The text() function is used to return the string or plain text from fields that are portable text blocks or an array of blocks. This function is specific to the pt namespace and only works with portable text.

A quick note on namespaces:

The Sanity Content Lake has built-in namespaces such as global, pt, geo. If a GROQ function is global, the entire Content Lake is its scope. Whereas, pt and geo functions only pertain to portable text and geolocation namespaces respectively.

Back to our scheduled programming, the text ()...

In this query, we filter on the product document type and return all of the body text within the portable text block for all products. This would be super useful if you needed to edit a bunch of product descriptions or any text.

Length vs Count Functions

Kap & I took the text() query a step further and used the length() to get a character count for each product body text and the count() to get the number of images associated with each product :

The difference between length() and count() can be confusing at first. The length() will give you the size of an array or the number of characters in a string. But the count() only gives the number of elements that have been passed in an array and is perfect for counting something like how many images are attached to each product.

If you missed the stream, you can watch Kap & Lauren learn GROQ - Part 7 on YouTube. Follow us on Twitch and tune in for another episode of Kap & Lauren learn GROQ, we hope to see you there!