How to get average of something
So as u can see here I am fetching some doctor informations. Now i have reviews table where doctors reviews are stored. Now how can I get the average of that reviews?

Multiple Datasources
Hello! I'm trying to connect two or more datasources to my next js web app.
Does it work? Is there any tutorial or anything what could help me to implement it.
I'm using the postgres databases from vercel....
Is there a way to just return a specific column?
I have a DB that holds voting results and I want to grab all the weeks that have votes. I.e. if there are votes for weeks 0-5, I just want to return 0, 1, 2, 3, 4, 5 and not the entire row for each of those weeks.
db push error
I am using drizzle to connect to a supabase database. I am doing my first push to a fresh DB. The schema has a single table in it, and i am getting this error
PostgresError: must be owner of sequence key_key_id_seq
Anyone have any idea what could be going on here?...
Subquery in select statement?
Hi, I'm trying to grab a value from a subquery in my select statement for a computed column but I'm getting an error telling me the column from the subquery doesn't exist.
```
const issuancesSq = tx
.select({
totalAcreFeetPerShare: sum(issuance.acreFeetPerShare)...
Solution:
👋 you can use a plain query as sub select: https://drizzle.run/yxbxn6x4rloxney2nvc1tphp
migration fail when table exists
I have a table
messages that is created in an earlier migration file:
```sql
DO $$ BEGIN
CREATE TYPE "public"."result" AS ENUM('LEFT', 'RIGHT');
EXCEPTION...Query causes error
```ts
const user = await database.query.users.findFirst({
where: eq(users.id, id),
with: {
links: true,...
MySQL2 and Datetime - UTC is wrong.
Hi!
I'm having trouble with fetching and saving UTC Datetimes to the database. In the database everything works fine. UTC time is right if i for example say DEFAULT NOW(). However when i create a new Date() and try to save it to the database. Drizzle is doing it's own conversion before sending it up or something. My local machine is +2 UTC but the times drizzle sends to database is -2 utc.
Do you know any fix for this? Is this a known error/bug?...
Error Handling for Null Values in Drizzle-Zod + Shadcn Form (React-Hook-Form)
The error message indicates that the value property of the field object can be null, but the Input, Checkbox components value prop do not accept null as a valid type. It only accepts string, number, readonly string[], or undefined.
Foreign key reference in drizzle causes type error
In my drizzle schema, I have two tables, users and payment_history, when I try to reference the id of payment_history, it throws a type error Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.. users table and payment_history table have a one to many relation where one user can have many payments. These are my schema definition: users:
```ts
export const users = pgTable("users",{
...
last_payment_id: varchar("last_payment_id").references(() => payment_history.id, { onDelete: "cascade" }),//error...
Confused about the return type of this function
So i have a function which fetches the user. My goal is to return user if exists else return null. However in order to achieve this i need to manually check the length of the response and if its zero i return null. Overall my code looks so much duplicated and verbose. I tried using this but this doesnt shows null as return type

how to set up postgis?
I lokked into this guide https://orm.drizzle.team/learn/guides/postgis-geometry-point and as per my understanding the guide is related if u are creating table and than doing a migration. But if I am introspecting than the cli should get the gemoetry type right? Becuuse I getting unknown type instead
Querying Views
I'm currently trying to query a view, but im getting an error back.
```ts
export const runTest1 = async () => {
try {...
Schema filter not working
As can been seen in the pic I have provided the filter but when i run the drizzle-kit introspect command it still does not take filter the schema

Insert line break in Postgres
I am trying to insert line breaks ('\n') into a text field in Postgres.
I saw that I am supposed to do the following:
https://stackoverflow.com/questions/36028908/postgresql-newline-character
...
How do we infer the batch query, response??
```tsx
const batchResponse: BatchResponse<
[
BatchItem<typeof schema.users.$inferSelect>,...
Drizzle ORM Query Builder Only Returning One Row
Aren't these two queries the same?
```...
const [data] = await db.execute(sql`SELECT * FROM products`);
const [data] = await db.execute(sql`SELECT * FROM products`);
mapWith doesn't look to work with extras columns
By chance, do anyone have clue why the mapWith is never called in this small code example :
```ts
const users = await ctx.db.query.users.findMany({
orderBy: desc(schema.users.createdAt),...
Need a review / suggestion please
Hello ,
i want to store the positions of items depending on the user preferences ( using a sortable list in which he can even move up or down one of the items )
i thought about this solution using transactions and some how two queries.
is there anybody free to take look please ...