Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for type casting (id::text) #429

Merged

Conversation

ozanmakes
Copy link
Contributor

@ozanmakes ozanmakes commented May 25, 2023

What kind of change does this PR introduce?

This change adds support for type casting in select queries. For example an id column with the type bigint can be casted to text by "id::text".

Equivalent PostgreSQL type for TypeScript type is based on the type generator pgTypeToTsType function.

What is the current behavior?

Fixes #370

What is the new behavior?

  • id::text will cast a bigint column to string in TypeScript.
  • _text will be text[].
  • newname:id::text will also work

Additional context

This is by no means a complete list of all possible type casts nor is it sound, but this is much less error prone than having to do an unsafe cast such as

supabase.from("users").select("id::text").returns<{ id: string }[]>

@ozanmakes ozanmakes force-pushed the add-support-for-type-casting branch 2 times, most recently from 249e707 to c9b9c89 Compare August 18, 2023 15:21
This change adds support for type casting in select queries. For example
an id column with the type bigint can be casted to text by "id::text".

Equivalent PostgreSQL type for TypeScript type is based on the type
generator pgTypeToTsType function https://github.com/supabase/postgres-meta//blob/80809c71d78d875524d7d9865c2458136207aa10/src/server/templates/typescript.ts#L421

Fixes supabase#370
@ozanmakes
Copy link
Contributor Author

Hi @soedirgo. Any chance this can be reviewed?

@steve-chavez steve-chavez merged commit 4525dc4 into supabase:master Feb 7, 2024
Copy link

github-actions bot commented Feb 7, 2024

🎉 This PR is included in version 1.11.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Query parser can't parse id::text
2 participants