Comments (7)
Using fetch
will always return the entire contents of the record link. The cool thing is that it's not necessary for your use-case. fetch
is not required to pull record properties directly from a record link. So the following should give you what you need:
SELECT *, artist.email FROM review limit 1
You may need to OMIT
the artist field to get exactly what you want, but I haven't tested it...
SELECT *, artist.email OMIT artist FROM review limit 1
from surrealdb.
What about this?
SELECT *, NONE as artist, artist.email FROM review limit 1
from surrealdb.
Thanks @ntorrey ! Sadly none of those queries return artist....
> SELECT *, artist.email FROM review limit 1
[
{
artist: artist:73z6oc419v1c5v34j20x,
id: review:00a0ic854u4j7z02s00v,
person: person:67s8cp304i4p6p83q02d,
product: product:41v2qv923h3o7s55e96l,
rating: 3,
review_text: 'repeat languages tr rest hospital consulting infrastructure melissa proposal singing finally hey eggs left market title yards identify movement themselves existing lake questions exchange m
eter strip up archive interview rather mostly transit stuff attitude fundamental palestinian estate cast yours eye lawyer academy sunset holy gang'
}
]
> SELECT *, artist.email OMIT artist FROM review limit 1
[
{
id: review:00a0ic854u4j7z02s00v,
person: person:67s8cp304i4p6p83q02d,
product: product:41v2qv923h3o7s55e96l,
rating: 3,
review_text: 'repeat languages tr rest hospital consulting infrastructure melissa proposal singing finally hey eggs left market title yards identify movement themselves existing lake questions exchange m
eter strip up archive interview rather mostly transit stuff attitude fundamental palestinian estate cast yours eye lawyer academy sunset holy gang'
}
]
Hence the bug report...
from surrealdb.
@ntorrey Nice, that one works! :)
> SELECT *, NONE as artist, artist.email FROM review limit 1
[
{
artist: {
email: '[email protected]'
},
id: review:00a0ic854u4j7z02s00v,
person: person:67s8cp304i4p6p83q02d,
product: product:41v2qv923h3o7s55e96l,
rating: 3,
review_text: 'repeat languages tr rest hospital consulting infrastructure melissa proposal singing finally hey eggs left market title yards identify movement themselves existing lake questions exchange m
eter strip up archive interview rather mostly transit stuff attitude fundamental palestinian estate cast yours eye lawyer academy sunset holy gang'
}
]
Awesome! Still, I consider this a workaround, that is non-obvious. I'll be using it for now, let's hope this gets fixed in future.
Thanks, you have saved me writing lots of gnarly "select"-generating code with explicit field listing!
from surrealdb.
@ntorrey Great trick!
About feature request: I feel SurrealDB team is quite overloaded and I'd rather have them focusing on performance improvements and bug fixes.
Also the SQL statement that I have used is directly from the documentation, so that is why it is a bug report. I'm happy if the documented specs match the actual implementation. But yeah, have a great day, @ntorrey, this is a life-saving trick :)
from surrealdb.
Awesome! I learned that trick a while back! Although I think there might be something to your idea: to be able to write:
SELECT *, artist.email FROM review limit 1 FETCH artist;
Does seem more intuitive.
Or maybe Surreal should just be smart enough to infer what is desired here:
SELECT *, artist.email FROM review limit 1
(Automatically replacing the artist record link with artist.email)
Maybe a good feature request?
from surrealdb.
Agreed, I just stomped on it yesterday and was going to file a bug. I've also noticed that aliasing allows to get the email when not aliasing doesn't ...
test/test> SELECT *, artist.email FROM review limit 1;
-- Query 1 (execution time: 314.25µs)
[
{
artist: artist:73z6oc419v1c5v34j20x,
id: review:00a0ic854u4j7z02s00v,
person: person:67s8cp304i4p6p83q02d,
product: product:41v2qv923h3o7s55e96l,
rating: 3,
review_text: 'repeat languages tr rest hospital consulting infrastructure melissa proposal singing finally hey eggs left market title yards identify movement themselves existing lake questions exchange meter strip up archive interview rather mostly transit stuff attitude fundamental palestinian estate cast yours eye lawyer academy sunset holy gang'
}
]
test/test> SELECT *, artist.email as artist_email FROM review limit 1;
-- Query 1 (execution time: 907.167µs)
[
{
artist: artist:73z6oc419v1c5v34j20x,
artist_email: '[email protected]',
id: review:00a0ic854u4j7z02s00v,
person: person:67s8cp304i4p6p83q02d,
product: product:41v2qv923h3o7s55e96l,
rating: 3,
review_text: 'repeat languages tr rest hospital consulting infrastructure melissa proposal singing finally hey eggs left market title yards identify movement themselves existing lake questions exchange meter strip up archive interview rather mostly transit stuff attitude fundamental palestinian estate cast yours eye lawyer academy sunset holy gang'
}
]
But then the format you get is different, so I totally agree that it's a bug that needs to be fixed
from surrealdb.
Related Issues (20)
- Bug: live queries kill DB connection HOT 1
- Feature: DenoKV as persistent data storage HOT 1
- How to customize an analyzer
- Bug: `update merge` should not check required fields
- Bug: License unfinished HOT 1
- Bug: cant have id field in struct HOT 1
- Bug: INFO / USE... query parsing error (RUST SDK) HOT 2
- Bug: Table Permissions Doesn't Seem To Be Working With Embedded Select Statement HOT 3
- Bug: Flutter app with embedded Rust failing to compile as a result of SurrealDB dependency usage HOT 1
- Bug: Deadlock encountered HOT 2
- Bug: Index not used when comparing with "==" HOT 1
- Bug: Db(Unreachable("This feature won't go live with sql1, so delete this branching"))
- Bug: Vector NN search count does not respect WHERE clause
- Feature: Query builder like syntax
- Bug: Paginating data (START / OFFSET) gets exponential slower with bigger datasets (from 380ms to 468970ms) HOT 1
- Bug: Cannot insert/create a data that contains a large vector size
- Feature: Automatically create/update records of child based on definition in parent or id in child
- Parameters do not work in string functions HOT 5
- Feature: Omit in fetch
- Bug: Live Query using `WHERE` clause with variables does not work. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from surrealdb.